r/cpp • • Feb 16 '26

Favorite optimizations ??

I'd love to hear stories about people's best feats of optimization, or something small you are able to use often!

135 Upvotes

185 comments sorted by

View all comments

Show parent comment

1

u/nothingtoseehr Mar 07 '26

If you have debug symbols on your assembly, it's not that hard even though you have A LOT of code. Most of it is just assembly boilerplate of calling conventions, stack management and moving data here and there. If you have a graph view it loots Even better than the source code xD

I'm mostly a C programmer which makes the task significantly easier since the compiler is less magical, so it's a bit of an unfair comparison, but I primarily see if the compiler is SIMD'ing my code properly. Compilers love to lazy around floating point operations and it can be a massive performance killer for really silly stuff

Not related to optimization per se but if you're dealing with UB, it can also be pretty helpful to track along the compiled assembly. Not as common in C++ as in C, but keeping track of an object/variable and how the compiled code accesses it sometimes reveal bugs that are quite obvious in assembly (random LEAs on random values, incorrect pointer arithmetic, wrong vtable etc etc) but hard to spot on the source's abstraction soup