5 ms·
I’m pretty happy I don’t have to worry about such details in C and can rely on the compiler to do the easy optimizations for me.
by pantalaimon 6y ago
I’m pretty happy I don’t have to worry about such details in C and can rely on the compiler to do the easy optimizations for me.
- ascar 6y agoWait, isn't that trick basically about avoiding optimization (inlining the function to avoid the context switch) to reduce code size? The C compiler would do something similar here and also increase code size for performance unless you explicitly use `-Os`
- monocasa 6y agoThe better C compilers use better heuristics in these cases, knowing that binary size can mean I$ pressure and therefore be a detriment to performance.
- a_e_k 6y agoThey also tend to have ways to override those heuristics (e.g., `__attribute__((noinline))` in GCC).
- singron 6y agogo has //go:noinline for the same effect. I don't think you need these weird trampoline calls and they are probably somewhat fragile since a future compiler might figure out how to inline through them.
- jeffbee 6y agoNobody needs to bounce through trampoline calls like this, but for people willing to chase a modest code size decrease like the 6% in the article, it's worth knowing that how your code is arranged may have a larger effect on program size than you're used to from other compiled languages.
- millstone 6y agoCache effects mean this is not a pure tradeoff. Any inlining routine needs a cost model. From the article it seems like Go compiler's cost model is not yet well tuned.
- jeffbee 6y agoIt's not really a language problem, it's a compiler problem, so at least in the future we might get a compiler that recognizes error-handling idioms. Or we just get llvm? The language problems, like the performance-hostile calling convention, are harder to fix.
- AmericanChopper 6y ago> It's not really a language problem, it's a compiler problem This has never seemed like such a clear distinction to me. A language is essentially just an instruction set for a compiler.
- NullPrefix 6y agoWell, there is a disctinction. It being a compiler problem, you can just accept the performance/size penalty and leave your code as is, but hope that in the future it will eventually change and the eventually really smart compiler will accept your current code as is and produce output without the penalty. Language problem would means you have to rewrite it differently.
- AmericanChopper 6y agoA language is both the abstractions that it implements, and the way it implements them. Any problem in the code you write could be solved by changing the compiler as much as it could be solved by changing the code. The two parts of the system are inseparable. I’d say a language can only be as good as its best compiler.
- somethingwitty1 6y agoBut they are quite different. There are languages that are tightly coupled, but not true of all (like Go). You could write all your applications in the Go Language, but use a transpiler. And as other comments call out, it is important to not conflate the two. A language issue is one that can't be easily fixed without breaking backwards compatibility. Compiler optimizations can be made (and is done all the time) without breaking the language.
- gameswithgo 6y agoohhh you think weird stuff doesn’t happen in C compilers? heh