Shortening C++ Compilation Times

What can be done to make compilation times shorter?

Updated over 2 years ago Edit Page Revisions

A few of many things a programmer should care about.

  • Forward Declarations

    Use forward declarations wherever applicable.

  • Clean Unused Includes

    Clean up unused includes. Tools like Resharper C++ or Rider IDE highlights unused includes in the opened source file.

  • Use Lowest Possible Class in Hierarchy

    Use "the lowest possible class in the hierarchy", i.e. include engine's PlayerController.h instead of your extended version if you don't need anything from your overridden class.

  • Put Common Types into Separate Headers

    Put common types (enums, structs) into separate headers like "MyProjectTypes.h" or "InventoryTypes.h". This way you wouldn't have to include the entire InventoryComponent class when another class just needs a struct holding InventoryItem definition. So you don't add classes used by InventoryComponent to the dependency chain

  • Minimize Dependency

    Don't forget about proper code architecture. Think all the time how to minimize dependencies between classes and systems.