https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70452
--- Comment #7 from Patrick Palka <ppalka at gcc dot gnu.org> --- Created attachment 38155 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=38155&action=edit patch that reuses the function copies I attached a small patch (not commented yet) that reduces the runtime (of a checking compiler) from 3.5s to 2s and reduces GGC memory usage from 550MB to 200MB when compiling the test case in comment #1. What it does is it maintains a per-FUNCTION_DECL freelist of body/parm/res copies that were created by copy_fn(). When a constexpr call is finished it pushes the copied body/parm/res trees to the freelist and before a call is evaluated it tries to reuse the trees from the freelist, falling back to copy_fn() if the freelist is empty. AFAICT the reason we use copy_fn() in the first place is to make recursive constexpr calls work. If we didn't copy the function trees then recursive calls would refer the same VAR/PARM_DECL trees. In that respect I think this patch is safe because recursive calls to the same function will still use distinct trees since all the entries on the freelist are distinct copies. Does this seem approach sensible?