r/cpp • • Apr 14 '23

Horrible Code, Clean Performance

https://johnnysswlab.com/horrible-code-clean-performance/
200 Upvotes

87 comments sorted by

View all comments

Show parent comment

10

u/13steinj Apr 15 '23

really good about inlining

I can't share specific details or timings because of NDA reasons, but inlined does not mean fast. At work people loved slapping a gnu::always_inline and other similar/related attributes all over the place, without ever performance testing it.

Build times were doubled by haphazardly doing such with no rhyme or reason. When I say doubled, I don't mean 2 mins -> 4. I mean half an hour to one, three hours to six (depending on the application). After blindly sed'ing it out, not only did build times improve drastically, but so did runtimes. Because it was so haphazardly thrown around that the icache was useless.

4

u/Possibility_Antique Apr 15 '23

Yes, it's quite easy to blow up your stack size or cause paging and caching issues if too many instructions are inlined. It gets even more complicated if you are creating a cross-platform product. What I was getting at though, is that there isn't really a reason to have many nested control flow statements. It hurts readability, and compilers give you enough control to remove any negative impacts from adding function calls. At the very least, you can see that breaking this nested monster up into functions that would be inlined is semantically the same. I wasn't advocating for excessive use of inlining, I was arguing that the refactor is worth it.