Skip to content

Instantly share code, notes, and snippets.

@Teebor-Choka
Last active June 21, 2024 13:29
Show Gist options
  • Save Teebor-Choka/743c287841ea4bf5fbfa9f6f68572039 to your computer and use it in GitHub Desktop.
Save Teebor-Choka/743c287841ea4bf5fbfa9f6f68572039 to your computer and use it in GitHub Desktop.
C++ related

Improving C++ builds 1

Tricks:

  • compilers do a lot less in Debug, use it in development
    • minimze optimizations
  • remove unreachable or dead code
    • cppcheck, Coverity, Understand, CppDepend, OCLint, gcov...
  • unused sources, libraries
  • commonly used sources => static libraries
  • use granular includes
    • applications (bad includes): Resharper C++ Analyzer, Doxygen + Graphviz, IWYU...
  • move definitions from header files
    • use link time optimization (or unity build) for inlining
    • use forward declarations where feasible
  • 3rd party code
    • create wrapper types/headers for 3rd party libraries
    • create forward declaration headers
  • PIMPL
    • preserves ABI
  • tricks
    1. pre-compiled headers
    2. ubity builds

Watch the rule of chiel (from fastest to slowest)

  1. look up memoized type
  2. add a parameter to an alias call
  3. add a parameter to a type
  4. call an alias
  5. instantiate a type
  6. instantiate a function template
  7. SFINAE

Templates

  • diagnostics: -ftime-report and templight

Dynamic linking

  • in Unix compile with -fvisibility=hidden

Linkers

  • lld

  • CMake - LINK_WHAT_YOU_USE

  • cmake --graphviz=[file]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment