]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c-family: don't cache large vecs
authorJason Merrill <jason@redhat.com>
Wed, 10 Nov 2021 21:23:12 +0000 (16:23 -0500)
committerJason Merrill <jason@redhat.com>
Tue, 16 Nov 2021 22:35:15 +0000 (17:35 -0500)
Patrick observed recently that an element of the vector cache could be
arbitrarily large.  Let's only cache relatively small vecs.

gcc/c-family/ChangeLog:

* c-common.c (release_tree_vector): Only cache vecs smaller than
16 elements.

gcc/c-family/c-common.c

index 436df45df686207f88e14af0aa40212603b29e74..90e8ec87b6b9b21276df755d6dee69338ff980b0 100644 (file)
@@ -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);
+       }
     }
 }