Key Points

  • Literal arguments and inlining, when combined, provide significant opportunities for a compiler to provide significant performance improvements.

  • Inlining may backfire, and overly aggressive inlining will almost certainly do so. Inlining can increase code size. Large code size suffers a higher rate of cache misses and page faults than smaller code.

  • Nontrivial inlining decisions should be based on sample execution profiles, not gut feelings.

  • Consider rewriting high frequency methods with large static size and small dynamic size to extract their significant dynamic characteristic, and then inline the dynamic component.

  • Trivial and singleton methods can always be inlined.

Get Efficient C++ Performance Programming Techniques now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.