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/ack_error Feb 18 '26

Yeah, I've seen cases where this is due to conflicting optimizations.

One case I saw had two patterns that were both optimized well by the compiler into wide operations, one direct and one with a byte reverse. Put the two into the same function with a branch and the compiler hoisted out common scalar operations from both branches, breaking the pattern matched optimized wide ops and emitting a bunch of byte ops on both branches.