On Thu, Mar 3, 2016 at 9:22 AM, Markus Trippelsdorf <mar...@trippelsdorf.de> wrote: > On 2016.03.03 at 09:16 -0500, Patrick Palka wrote: >> push_to_top_level gets called fairly frequently in template-heavy code >> that performs a lot of instantiations, and we currently "leak" a lot of >> GC memory when compiling such code since [push|pop]_to_top_level() do >> not bother reusing or even freeing each saved_scope structure it >> allocates. >> >> This patch makes push_to_top_level() reuse the saved_scope structures it >> allocates. This is similar to how begin_scope() reuses the >> cp_binding_level structures it allocates. >> >> This patch reduces the maximum memory usage of the compiler by 4.5%, >> from 525MB to 500MB, when compiling the Boost::Fusion test file >> libs/fusion/test/compile_time/transform.cpp from the Boost 1.60 testsuite. >> >> Bootstrapped and tested on x86_64-pc-linux-gnu, OK for >> trunk or for GCC 7? > > Great. push_to_top_level also shows up very high in profiles when > building Chromium for example. > > There is an old bug for this issue: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64500 > > -- > Markus
I forgot what exactly I was benchmarking but I also saw push_to_top_level high on the list which is what made me interested in this function in the first place. I think the slowness of this function is mostly due to the pointer chasing performed in the function store_bindings, where we iterate over all the names in each non-global scope to figure out whether to preserve them. It would probably improve performance if cp_binding_level::names were a vector of trees instead of a linked list of trees.