From: "René Scharfe" <rene.scharfe@lsrfire.ath.cx>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
Felipe Contreras <felipe.contreras@gmail.com>,
Stephen Boyd <sboyd@codeaurora.org>
Subject: [PATCH 2/2] read-cache: free cache in discard_index
Date: Sun, 9 Jun 2013 19:39:18 +0200 [thread overview]
Message-ID: <1370799558-18188-2-git-send-email-rene.scharfe@lsrfire.ath.cx> (raw)
In-Reply-To: <1370799558-18188-1-git-send-email-rene.scharfe@lsrfire.ath.cx>
discard_cache doesn't have to free the array of cache entries, because
the next call of read_cache can simply reuse it, as they all operate on
the global variable the_index.
discard_index on the other hand does have to free it, because it can be
used e.g. with index_state variables on the stack, in which case a
missing free would cause an unrecoverable leak. This patch releases the
memory and removes a comment that was relevant for discard_cache but has
become outdated.
Since discard_cache is just a wrapper around discard_index nowadays, we
lose the optimization that avoids reallocation of that array within
loops of read_cache and discard_cache. That doesn't cause a performance
regression for me, however (HEAD = this patch, HEAD^ = master + p0002):
Test // HEAD^ HEAD
---------------\\-----------------------------------------------------
0002.1: read_ca// 1000 times 0.62(0.58+0.04) 0.61(0.58+0.02) -1.6%
Suggested-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: René Scharfe <rene.scharfe@lsrfire.ath.cx>
---
read-cache.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/read-cache.c b/read-cache.c
index 04ed561..4245f8e 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1518,8 +1518,9 @@ int discard_index(struct index_state *istate)
free_name_hash(istate);
cache_tree_free(&(istate->cache_tree));
istate->initialized = 0;
-
- /* no need to throw away allocated active_cache */
+ free(istate->cache);
+ istate->cache = NULL;
+ istate->cache_alloc = 0;
return 0;
}
--
1.8.3
prev parent reply other threads:[~2013-06-09 17:39 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-09 17:39 [PATCH 1/2] read-cache: add simple performance test René Scharfe
2013-06-09 17:39 ` René Scharfe [this message]
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=1370799558-18188-2-git-send-email-rene.scharfe@lsrfire.ath.cx \
--to=rene.scharfe@lsrfire.ath.cx \
--cc=felipe.contreras@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=sboyd@codeaurora.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 NNTP newsgroup(s).