Comment Re:Why stop there? (Score 1) 752
Correct, but it does not change the premise. Actually, all major C++ compilers are well aware about the situation and are very good at optimizing inlines (and not optimizing when it does not make sense).
They can only really do a good job if they're taking into account the size of the caches, and that's not portable at all. A lot of people don't have the luxury of only ever coding for one processor variant.
First, in real modern CPUs _practical_ differences are not that big. E.g., put the inlining limit to 32 bytes (for fast code) and you will hardly see performance degradation anywhere.
But the main issue: inlining often leads to code that is actually shorter than the call.
(Curiously, I work somewhere where that level of optimization is sometimes used for real.
So do I. I have spent years optimizing stuff in C++. Benchmarking and examining produced assembly is my second nature. That is why I am pretty sure I could not achieve C++ levels in any other language, assembler included.
In fact, what really counts is not inlining itself, but optimization across multiple functions call - in C++, multiple calls can get collapsed into a couple of assembly instructions. Often, such collapsing leads into less code bytes than required to perform function call.
If you're only inlining trivial accessors then you're correct, but that's not the only case that people inline. For something longer, it's a much trickier tradeoff.
Specifically, in my C++ code, String comparison inlined fast path collapses to 5 assembler opcodes. That is about as long as function call.
And I would not call String comparison trivial accessor.
But even so, the problem of even trivial accessors is that they often tend to go deep. In container intense code, without inlines, you might end spending 50% of time just managing stack frames for element retrieval calls.
(And inlines have that ABI-bake-in problem which you ignored, which really bites in production libraries. Mainline developers don't see the issue, but maintenance programmers and deployment engineers do.)
No dispute there, there is a big problem with C++ and maintaining shared library compatibility.
For most applications it can be easily solved by not using shared libraries... Facebook would be a nice example. After all, PHP does not produce