Bug 124925 - -freflection slows down compilation (of e.g. stdc++.h) by about 20%
Summary: -freflection slows down compilation (of e.g. stdc++.h) by about 20%
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 16.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: compile-time-hog
Depends on:
Blocks: c++-reflection
  Show dependency tree / graph
 
Reported: 2026-04-18 14:52 UTC by Patrick Palka
Modified: 2026-09-14 15:54 UTC (History)
6 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Patrick Palka 2026-04-18 14:52:56 UTC
The culprits seem to be consteval_only_p and check_out_of_consteval_use, each accounting for about 10% of compile time (this is with an --enable-checking=release build).

$ perf stat -r5 g++-16 -std=c++26 -fsyntax-only libstdc++-v3/include/precompiled/stdc++.h
...
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:01.42
...
$ perf stat -r5 g++-16 -std=c++26 -fsyntax-only -freflection libstdc++-v3/include/precompiled/stdc++.h
...
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:01.69
...
Comment 1 Jakub Jelinek 2026-04-18 15:04:58 UTC
The main problem is that we don't cache consteval_only flag on types.
We could cache a 3 state (known to be consteval-only, known not to be consteval-only, unknown), either just on class types or on array/pointer/reference types as well.
The main reason for not implementing that was that we don't know what will happen with consteval-only types vs. consteval-only values, i.e. whether it won't be a wasted effort.
Comment 2 Jakub Jelinek 2026-09-14 15:42:12 UTC
Guess we want to meassure this again now.
Comment 3 Marek Polacek 2026-09-14 15:51:31 UTC
$ perf stat -r5 xg++ -std=c++26 -fsyntax-only stdc++.h

 Performance counter stats for 'xg++ -std=c++26 -fsyntax-only stdc++.h' (5 runs):

                 0      context-switches:u               #      0.0 cs/sec  cs_per_second     
                 0      cpu-migrations:u                 #      0.0 migrations/sec  migrations_per_second
            80,458      page-faults:u                    #  16307.1 faults/sec  page_faults_per_second  ( +-  0.02% )
          4,933.92 msec task-clock:u                     #      nan CPUs  CPUs_utilized         ( +-  0.16% )
       101,038,872      branch-misses:u                  #      1.0 %  branch_miss_rate         ( +-  0.42% )  (50.01%)
    10,492,969,039      branches:u                       #   2126.7 M/sec  branch_frequency     ( +-  0.06% )  (50.03%)
    26,909,357,524      cpu-cycles:u                     #      5.5 GHz  cycles_frequency       ( +-  0.09% )  (66.69%)
    58,033,354,072      instructions:u                   #      2.2 instructions  insn_per_cycle  ( +-  0.18% )  (50.02%)
     8,773,812,719      stalled-cycles-frontend:u        #     0.33 frontend_cycles_idle        ( +-  0.44% )  (50.00%)

       4.943746813 +- 0.007941643 seconds time elapsed  ( +-  0.16% )

$ perf stat -r5 xg++ -std=c++26 -fsyntax-only -freflection stdc++.h

 Performance counter stats for 'xg++ -std=c++26 -fsyntax-only -freflection stdc++.h' (5 runs):

                 0      context-switches:u               #      0.0 cs/sec  cs_per_second     
                 0      cpu-migrations:u                 #      0.0 migrations/sec  migrations_per_second
            81,099      page-faults:u                    #  16254.4 faults/sec  page_faults_per_second  ( +-  0.00% )
          4,989.36 msec task-clock:u                     #      nan CPUs  CPUs_utilized         ( +-  0.66% )
       102,726,834      branch-misses:u                  #      1.0 %  branch_miss_rate         ( +-  0.58% )  (49.98%)
    10,681,074,259      branches:u                       #   2140.8 M/sec  branch_frequency     ( +-  0.06% )  (50.01%)
    27,347,396,329      cpu-cycles:u                     #      5.5 GHz  cycles_frequency       ( +-  0.45% )  (66.67%)
    59,028,719,550      instructions:u                   #      2.2 instructions  insn_per_cycle  ( +-  0.05% )  (50.04%)
     8,835,672,943      stalled-cycles-frontend:u        #     0.32 frontend_cycles_idle        ( +-  0.61% )  (50.01%)

       4.999518199 +- 0.033349767 seconds time elapsed  ( +-  0.67% )
Comment 4 Marek Polacek 2026-09-14 15:54:53 UTC
...which is about 1.12812% increase.  So I think it's fixed.