Hacker News new | past | comments | ask | show | jobs | submit login

Attributes like inline or likely rarely do that much, so that doesn't explain it. They are merely suggestions, frequently ignored, and the compiler is good at optimizing these things anyway. Languages that allow explicit, deterministic, fine-grained resource management like C, C++, and Rust (systems languages) have significant advantages over ones that do not like Java and Go; certain types of optimizations cannot be effectively implemented without this property. In principle, systems languages can all produce similarly performant code but the amount of work required to get that performance varies greatly.

Modern C++ in particular encourages the extensive use of expressive compile-time metaprogramming to automate optimization that the compiler cannot. In theory, the heavily optimized data structure and algorithm code that is often generated in C++ could be manually written in C or similar. However, in practice, few software engineers have the patience or time to systematically apply those optimizations manually to everything in their code base. I know for a fact that I didn't when I was writing C.

That modern C++ tends to produce the most highly optimized code is more a matter of economy than theoretical capability.




> Attributes like inline or likely rarely do that much, so that doesn't explain it. They are merely suggestions, frequently ignored

In Rust you can annotate a function with `#[inline(always)]` which makes is not a suggestion; it'll always inline it AFAIK (unless it calls itself recursively where, by definition, inlining is not possible).


All major c++ compilers have similar attributes but they are heavily discouraged by the compiler authors.

Clang also has a flatten attribute which can be interesting: it does the conjugate of marking functions inline: the function to which it is applied to will have all its own content inlined, e.g. [[clang::flatten]] void f() { a(); b(); }

will inline a and b


Got it, I'll have to dig through the language benchmark game to see if it reflects the best C++ tricks. From what I've seen previously, the biggest perf difference is in native memory management along with easy access to machine specific instructions.

Having recently worked on a large C/C++ code base which had a heavy focus on performance observation, I found myself wondering if tricks like dynamic Code Generation to avoid method overhead and unnecessary branch checks actually had a significant benefit on performance relative to the developer economy impact.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: