https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119387

--- Comment #14 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Created attachment 60941
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=60941&action=edit
reduced memory-hog testcase

I managed to distill a large chunk of the front end memory-hog into the
attached testcase (compile with -std=c++20 -O -fsyntax-only) which initializes
a 512-tuple.  The initialization is clearly non-constant, but after P2280
during speculative constexpr folding we no longer immediately give up
evaluating the hefty recursive initialization, and in the meantime create a lot
of garbage evaluating all the recursive constexpr calls in vain (and seemingly
quadratically).  The constexpr call cache doesn't help here because the
constructor arguments are non-constant.

r14-5978 (unoptimized checking):

Time variable                                   usr           sys          wall
          GGC
 phase setup                        :   0.04 (  0%)   0.01 (  8%)   0.09 (  1%)
 1773k (  3%)
 phase parsing                      :   9.39 ( 99%)   0.12 ( 92%)   9.53 ( 98%)
   66M ( 97%)
 phase lang. deferred               :   0.08 (  1%)   0.00 (  0%)   0.09 (  1%)
  128  (  0%)
 |name lookup                       :   7.75 ( 81%)   0.05 ( 38%)   7.85 ( 81%)
  305k (  0%)
 |overload resolution               :   0.07 (  1%)   0.01 (  8%)   0.18 (  2%)
 3802k (  5%)
 garbage collection                 :   0.08 (  1%)   0.00 (  0%)   0.09 (  1%)
    0  (  0%)
 parser (global)                    :   0.00 (  0%)   0.01 (  8%)   0.01 (  0%)
  585k (  1%)
 parser struct body                 :   0.01 (  0%)   0.00 (  0%)   0.00 (  0%)
   31k (  0%)
 parser function body               :   0.03 (  0%)   0.00 (  0%)   0.04 (  0%)
 2623k (  4%)
 template instantiation             :   9.08 ( 95%)   0.10 ( 77%)   9.22 ( 95%)
   57M ( 84%)
 constant expression evaluation     :   0.27 (  3%)   0.01 (  8%)   0.25 (  3%)
 6087k (  9%)
 varconst                           :   0.00 (  0%)   0.00 (  0%)   0.01 (  0%)
    0  (  0%)
 TOTAL                              :   9.51          0.13          9.71       
   67M

r14-5979 (unoptimized checking):

Time variable                                   usr           sys          wall
          GGC
 phase setup                        :   0.01 (  0%)   0.00 (  0%)   0.02 (  0%)
 1773k (  0%)
 phase parsing                      :  35.94 (100%)   0.52 (100%)  36.53 (100%)
  457M (100%)
 phase lang. deferred               :   0.15 (  0%)   0.00 (  0%)   0.15 (  0%)
  128  (  0%)
 |name lookup                       :   7.59 ( 21%)   0.04 (  8%)   7.86 ( 21%)
  324k (  0%)
 |overload resolution               :   0.11 (  0%)   0.00 (  0%)   0.10 (  0%)
 3809k (  1%)
 garbage collection                 :   0.15 (  0%)   0.00 (  0%)   0.15 (  0%)
    0  (  0%)
 parser function body               :   0.03 (  0%)   0.01 (  2%)   0.03 (  0%)
 2623k (  1%)
 template instantiation             :   9.10 ( 25%)   0.10 ( 19%)   9.18 ( 25%)
   57M ( 12%)
 constant expression evaluation     :  26.81 ( 74%)   0.41 ( 79%)  27.32 ( 74%)
  397M ( 86%)
 TOTAL                              :  36.10          0.52         36.70       
  459M

trunk (optimized release):

Time variable                                  wall           GGC
 phase setup                        :   0.01 (  1%)  1813k (  1%)
 phase parsing                      :   1.42 ( 99%)   328M ( 99%)
 |name lookup                       :   0.01 (  0%)   328k (  0%)
 |overload resolution               :   0.01 (  1%)  3810k (  1%)
 parser function body               :   0.00 (  0%)  2345k (  1%)
 template instantiation             :   0.13 (  9%)    58M ( 18%)
 constant expression evaluation     :   1.28 ( 90%)   267M ( 81%)
 TOTAL                              :   1.43          330M

Reply via email to