public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jason Merrill <jason@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-5325] c-family: don't cache large vecs
Date: Tue, 16 Nov 2021 22:36:01 +0000 (GMT)	[thread overview]
Message-ID: <20211116223601.ADCDD3858037@sourceware.org> (raw)

https://gcc.gnu.org/g:395848255cfa88f6f0f33a9b14c79e584a05d6fc

commit r12-5325-g395848255cfa88f6f0f33a9b14c79e584a05d6fc
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Nov 10 16:23:12 2021 -0500

    c-family: don't cache large vecs
    
    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.

Diff:
---
 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);
+	}
     }
 }


                 reply	other threads:[~2021-11-16 22:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211116223601.ADCDD3858037@sourceware.org \
    --to=jason@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).