https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119705
Bug ID: 119705
Summary: Massive memory use when building Flang (10GB+)
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Keywords: compile-time-hog, memory-hog
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: sjames at gcc dot gnu.org
CC: amonakov at gcc dot gnu.org, mgorny at gentoo dot org,
ppalka at gcc dot gnu.org
Target Milestone: ---
Originally reported by Michał Górny downstream at
https://bugs.gentoo.org/953484: "As discussed on IRC, when compiling
llvm-core/flang, GCC may end up using ~10G for some files (effectively capping
the package at -j3 on systems with 32G RAM)" with GCC 14. Trunk doesn't fare
much better.
At r15-9352-g6284f555e877c7 with --enable-checking=release:
```
$ g++ -c DataSharingProcessor.cpp.ii -fsyntax-only
real 0m46.318s
user 0m42.178s
sys 0m3.983s
```
With that, perf report says:
```
6.11% cc1plus cc1plus [.] gt_ggc_mx_lang_tree_node
5.51% cc1plus cc1plus [.] ggc_set_mark
3.07% cc1plus cc1plus [.] find_substitution
3.02% cc1plus cc1plus [.] variably_modified_type_p
2.16% cc1plus cc1plus [.] ggc_internal_alloc_no_dtor
2.06% cc1plus cc1plus [.] hash_tree_cons
1.98% cc1plus cc1plus [.] walk_tree_1
1.45% cc1plus cc1plus [.] cp_fold
1.33% cc1plus cc1plus [.] tsubst
0.86% cc1plus cc1plus [.] add_candidates
0.82% cc1plus cc1plus [.] spec_hasher::equal
0.76% cc1plus cc1plus [.] cp_type_quals
0.76% cc1plus cc1plus [.] member_vec_binary_search
[...]
```
That find_substitution was mentioned by richi at
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119387#c19.
With `-ftime-report -ftime-report-details -fsyntax-only`:
```
Time variable wall GGC
phase setup : 0.00 ( 0%) 1948k ( 0%)
phase parsing : 15.20 ( 31%) 2436M ( 42%)
phase lang. deferred : 33.60 ( 69%) 3430M ( 58%)
|name lookup : 2.42 ( 5%) 129M ( 2%)
|overload resolution : 19.78 ( 41%) 2216M ( 38%)
garbage collection : 6.51 ( 13%) 0 ( 0%)
preprocessing : 0.20 ( 0%) 3799k ( 0%)
parser (global) : 0.97 ( 2%) 164M ( 3%)
`- garbage collection : 4.43 ( 9%) 0 ( 0%)
`- parser struct body : 0.01 ( 0%) 1832k ( 0%)
`- template instantiation : 7.29 ( 15%) 958M ( 16%)
`- preprocessing : 0.20 ( 0%) 3799k ( 0%)
`- constant expression evaluation : 0.01 ( 0%) 1565k ( 0%)
`- parser function body : 0.05 ( 0%) 4351k ( 0%)
`- parser inl. func. body : 0.07 ( 0%) 14M ( 0%)
parser struct body : 1.76 ( 4%) 342M ( 6%)
`- template instantiation : 0.06 ( 0%) 7177k ( 0%)
`- varconst : 0.01 ( 0%) 0 ( 0%)
`- parser struct body : 0.01 ( 0%) 2315k ( 0%)
`- parser inl. meth. body : 0.92 ( 2%) 119M ( 2%)
`- constant expression evaluation : 0.01 ( 0%) 1434k ( 0%)
parser function body : 0.10 ( 0%) 8264k ( 0%)
parser inl. func. body : 0.15 ( 0%) 22M ( 0%)
`- template instantiation : 0.01 ( 0%) 587k ( 0%)
`- constant expression evaluation : 0.02 ( 0%) 2697k ( 0%)
parser inl. meth. body : 2.09 ( 4%) 235M ( 4%)
`- template instantiation : 0.08 ( 0%) 10M ( 0%)
`- garbage collection : 2.08 ( 4%) 0 ( 0%)
`- constant expression evaluation : 0.05 ( 0%) 4740k ( 0%)
template instantiation : 35.92 ( 74%) 5051M ( 86%)
`- template instantiation : 5.34 ( 11%) 715M ( 12%)
`- constant expression evaluation : 0.86 ( 2%) 21M ( 0%)
`- symout : 0.02 ( 0%) 0 ( 0%)
`- varconst : 0.02 ( 0%) 0 ( 0%)
constant expression evaluation : 1.04 ( 2%) 36M ( 1%)
`- template instantiation : 0.50 ( 1%) 58M ( 1%)
varconst : 0.04 ( 0%) 82k ( 0%)
symout : 0.02 ( 0%) 0 ( 0%)
TOTAL : 48.81 5868M
```