Using unity builds reduces compile times significantly. In my tests it's usually 2-4x faster.
When using unity builds, cmake generates new .cpp like the one below and compiles those instead of our .cc files.
Our source code is already prepared to support this without introducing name collisions (rB1df8abff257030ba79bc23dc321f35494f4d91c5).
Unity builds improve build times in multiple ways (in order of importance):
- Headers are parsed less often, because they only have to be parsed once for each set of files.
- Fewer duplicated template instantiations. Many nodes perform the same template instantiations (e.g. Vector<int>::append). By compiling multiple files at once, each symbol is only instantiated once per set of files.
- Faster link time, due to fewer duplicated symbols that the linker has to deal with.
If this goes well, we could consider using unity builds in other parts of Blender as well.
Example file generated by cmake (just removed empty lines):
/* generated by CMake */ #include "/home/jacques/blender-git/blender/source/blender/nodes/geometry/nodes/node_geo_curve_fillet.cc" #include "/home/jacques/blender-git/blender/source/blender/nodes/geometry/nodes/node_geo_curve_handle_type_selection.cc" #include "/home/jacques/blender-git/blender/source/blender/nodes/geometry/nodes/node_geo_curve_length.cc" #include "/home/jacques/blender-git/blender/source/blender/nodes/geometry/nodes/node_geo_curve_parameter.cc" #include "/home/jacques/blender-git/blender/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_bezier_segment.cc" #include "/home/jacques/blender-git/blender/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_circle.cc" #include "/home/jacques/blender-git/blender/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_line.cc" #include "/home/jacques/blender-git/blender/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadratic_bezier.cc" #include "/home/jacques/blender-git/blender/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadrilateral.cc" #include "/home/jacques/blender-git/blender/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_spiral.cc"

