Wednesday, August 19, 2026

Watch out for the range library compilation times

Ranges

 The ranges library are a great addition to the C++ standard. However they can increase compilation times; especially when used in template headers which are included by other translation units. It also caused the following error: 'error C1128: number of sections exceeded object file format limit: compile with /bigobj'. 

 The specific use case was a template class which used the range library in two ways:

  • use of ranges functions; e.g. std::ranges::adjacent_find(...)
  • use of a view; e.g.  std::ranges::binary_search(std::views::keys(deq), h);

It turned out that especially the view was heavy for the compiler. Leaving out the range in the code improved compile times with 30% for a piece of code and 10% overall in a large application. The numbers can o.f.c. vary per use case.

Conclusion 

 If compile times are paramount and you have a header which is included a lot and uses the range library you could measure its impact on compilation times. if it contributes too much replace it with pre range constructs.

Watch out for the range library compilation times

Ranges  The ranges library are a great addition to the C++ standard. However they can increase compilation times; especially when used in te...