Writing Efficient C++ Code

(asawicki.info)

35 points | by ibobev 1 day ago

3 comments

  • hn_submit 20 minutes ago
    I write in C++ almost every day but never have the need to optimize for speed. Even when you write straightforward code it's already blazingly fast.
  • 112233 1 hour ago
    "This article was originally published in Polish in issue 4/2013" — a lot of excellent advice. Sad to see C++ have moved in last decade in a direction that makes writing efficient, simple low level code harder and harder :(
    • jll29 6 minutes ago
      I think it has become EASIER: for instance, since C++23 Rust-like move semantics can be used, which provides the compiler with extra information that can be leveraged for the generation of better code.

      Or take constexpr - it permits to move computations to compile time that are complex and in older versions either had to be done at runtime, or an ugly workaround had to be used (e.g. assigning a mysterious literal pre-computed in another run or by hand).

    • fooblaster 40 minutes ago
      How? you can write exactly the same low level code today.
      • AlotOfReading 3 minutes ago
        Shot in the dark, but maybe the OP is referring to the fact that these code conventions are explicitly discouraged by the C++ core guidelines. The SoA example falls afoul of the rule requiring T* to be used only for singular object pointers, for example.
      • beached_whale 30 minutes ago
        My thought too.

        There are so many things that are expressible in C++ now that could not be without writing much more code or using per-compilation tools back then. The ability to run code at compile time that is not run at runtime is huge, #embed lets us make other tools output available without linker scripts or compiler specific tools that.

        Also, most of the code from the past still works(from 10 years ago definitely works)

  • tug2024 19 minutes ago
    [dead]