Message ID | 20211116165314.3558115-1-jason@redhat.com |
---|---|
State | New |
Headers | show |
Series | [RFC] c-family: don't cache large vecs | expand |
On Tue, Nov 16, 2021 at 11:53:14AM -0500, Jason Merrill via Gcc-patches wrote: > Patrick observed recently that an element of the vector cache could be > arbitrarily large. Let's only cache relatively small vecs. > > This has no effect on compiling the libstdc++ stdc++.h, presumably because > nothing in the library requires a vec that large. I figure that this makes it > more likely that a subsequent long list will reuse the same memory when the > later vec gets expanded. > > Does this make sense to others? Looks good to me. > gcc/c-family/ChangeLog: > > * c-common.c (release_tree_vector): Only cache vecs smaller than > 16 elements. > --- > gcc/c-family/c-common.c | 12 ++++++++++-- > 1 file changed, 10 insertions(+), 2 deletions(-) > > diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c > index 436df45df68..90e8ec87b6b 100644 > --- a/gcc/c-family/c-common.c > +++ b/gcc/c-family/c-common.c > @@ -8213,8 +8213,16 @@ release_tree_vector (vec<tree, va_gc> *vec) > { > if (vec != NULL) > { > - vec->truncate (0); > - vec_safe_push (tree_vector_cache, vec); > + if (vec->allocated () >= 16) > + /* Don't cache vecs that have expanded more than once. On a p64 > + target, vecs double in alloc size with each power of 2 elements, e.g > + at 16 elements the alloc increases from 128 to 256 bytes. */ > + vec_free (vec); > + else > + { > + vec->truncate (0); > + vec_safe_push (tree_vector_cache, vec); > + } > } > } > > > base-commit: 132f1c27770fa6dafdf14591878d301aedd5ae16 > -- > 2.27.0 > Marek
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 436df45df68..90e8ec87b6b 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -8213,8 +8213,16 @@ release_tree_vector (vec<tree, va_gc> *vec) { if (vec != NULL) { - vec->truncate (0); - vec_safe_push (tree_vector_cache, vec); + if (vec->allocated () >= 16) + /* Don't cache vecs that have expanded more than once. On a p64 + target, vecs double in alloc size with each power of 2 elements, e.g + at 16 elements the alloc increases from 128 to 256 bytes. */ + vec_free (vec); + else + { + vec->truncate (0); + vec_safe_push (tree_vector_cache, vec); + } } }