TL;DR: Only generate template parameters in skeleton units for template functions/types whose names have been simplified. Please consider if there are any issues with this approach.
Background
In an internal project using -fsplit-dwarf-inlining and -fdebug-info-for-profiling, we observed that skeleton units contained a lot of template parameters. These details are intended for symbolizers to reconstruct names simplified by -gsimple-template-names, which was not enabled in this project. Consequently, these template parameters became entirely redundant.
The issue stems from LLVM’s current approach: when generating debug info for skeleton units, it unconditionally emits all template parameters. To optimize debug info size, the emission should be conditional — providing parameters only for template types/functions whose names have actually been simplified.
Proposal
Introduce a metadata flag for -gsimple-template-names to mark DISubprograms/DICompositeTypes whose names have been simplified. This enables selective generation of template parameters in skeleton CUs during the backend, thereby optimizing debug information.
I implemented the proposal in this draft PR: [DebugInfo] Introduce metadata flag for -gsimple-template-names and optimize template params in skeleton CU. by Sockke · Pull Request #174904 · llvm/llvm-project · GitHub
Effect
I conducted tests in an internal project based on LLVM 16. The build was configured with options like -fsplit-dwarf-inlining, -fdebug-info-for-profiling and -O3, but without -gsimple-template-names.
In LTO builds:
| Binary File | Size Reduction | % Reduction |
|---|---|---|
| .debug_info | -441Mi | -29.1% |
| .debug_str | -204Mi | -26.9% |
| total | -651Mi | -10.4% |
In non-LTO builds:
| Binary File | Size Reduction | % Reduction |
|---|---|---|
| .debug_info | -123Mi | -3.8% |
| .debug_str | -40.8Mi | -6.1% |
| total | -172Mi | -1.7% |
Meanwhile, I also verified the effect when -gsimple-template-names is enabled.
In LTO builds:
| Binary File | Size Reduction | % Reduction |
|---|---|---|
| .debug_info | -59.5Mi | -3.9% |
| .debug_str | -15.2Mi | -2.4% |
| total | -75Mi | -1.3% |
In non-LTO builds:
| Binary File | Size Reduction | % Reduction |
|---|---|---|
| .debug_info | -14.8Mi | -0.4% |
| .debug_str | -2.46Mi | -0.4% |
| total | -18.5Mi | -0.2% |