Per-function template chains make 2000 generated wrappers compile three times slower
Symptom#
A generated table of about 2000 C wrapper functions took about 36 s and 1.7 GB to compile at -O2.
Cause#
Each wrapper used a std::tuple, a generic lambda, an index_sequence and a std::get<I> for each argument. Every function built its own deep chain of template instantiations.
Fix#
Move the per-argument work into a small struct template that depends only on the argument role and type. The functions then share those instantiations. Keep the per-function instantiation shallow. A parameter-pack fold can run the per-argument steps in order. The restructured version took about 10 s and 131 MB, close to hand-written wrappers at 10.8 s.
Evidence#
Measured in a prior prototype and stated by the user in the design brief for the brahma binding generator, 2026-10. The numbers are as given in that brief.
Also found by searching
- template instantiation takes 36 seconds for 2000 functions
- compile time and memory of generated wrappers with std::tuple and index_sequence
- per-function template instantiation makes the build slow