git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] read-cache: add simple performance test
@ 2013-06-09 17:39 René Scharfe
  2013-06-09 17:39 ` [PATCH 2/2] read-cache: free cache in discard_index René Scharfe
  0 siblings, 1 reply; 2+ messages in thread
From: René Scharfe @ 2013-06-09 17:39 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Felipe Contreras, Stephen Boyd

Add the helper test-read-cache, which can be used to call read_cache and
discard_cache in a loop as well as a performance check based on it.

Signed-off-by: René Scharfe <rene.scharfe@lsrfire.ath.cx>
---
 .gitignore                 |  1 +
 Makefile                   |  1 +
 t/perf/p0002-read-cache.sh | 14 ++++++++++++++
 test-read-cache.c          | 13 +++++++++++++
 4 files changed, 29 insertions(+)
 create mode 100755 t/perf/p0002-read-cache.sh
 create mode 100644 test-read-cache.c

diff --git a/.gitignore b/.gitignore
index 1640c3a..c0e00eb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -191,6 +191,7 @@
 /test-mktemp
 /test-parse-options
 /test-path-utils
+/test-read-cache
 /test-regex
 /test-revision-walking
 /test-run-command
diff --git a/Makefile b/Makefile
index a748133..2e3b4ee 100644
--- a/Makefile
+++ b/Makefile
@@ -572,6 +572,7 @@ TEST_PROGRAMS_NEED_X += test-mergesort
 TEST_PROGRAMS_NEED_X += test-mktemp
 TEST_PROGRAMS_NEED_X += test-parse-options
 TEST_PROGRAMS_NEED_X += test-path-utils
+TEST_PROGRAMS_NEED_X += test-read-cache
 TEST_PROGRAMS_NEED_X += test-regex
 TEST_PROGRAMS_NEED_X += test-revision-walking
 TEST_PROGRAMS_NEED_X += test-run-command
diff --git a/t/perf/p0002-read-cache.sh b/t/perf/p0002-read-cache.sh
new file mode 100755
index 0000000..9180ae9
--- /dev/null
+++ b/t/perf/p0002-read-cache.sh
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+test_description="Tests performance of reading the index"
+
+. ./perf-lib.sh
+
+test_perf_default_repo
+
+count=1000
+test_perf "read_cache/discard_cache $count times" "
+	test-read-cache $count
+"
+
+test_done
diff --git a/test-read-cache.c b/test-read-cache.c
new file mode 100644
index 0000000..b25bcf1
--- /dev/null
+++ b/test-read-cache.c
@@ -0,0 +1,13 @@
+#include "cache.h"
+
+int main (int argc, char **argv)
+{
+	int i, cnt = 1;
+	if (argc == 2)
+		cnt = strtol(argv[1], NULL, 0);
+	for (i = 0; i < cnt; i++) {
+		read_cache();
+		discard_cache();
+	}
+	return 0;
+}
-- 
1.8.3

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH 2/2] read-cache: free cache in discard_index
  2013-06-09 17:39 [PATCH 1/2] read-cache: add simple performance test René Scharfe
@ 2013-06-09 17:39 ` René Scharfe
  0 siblings, 0 replies; 2+ messages in thread
From: René Scharfe @ 2013-06-09 17:39 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Felipe Contreras, Stephen Boyd

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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-06-09 17:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-09 17:39 [PATCH 1/2] read-cache: add simple performance test René Scharfe
2013-06-09 17:39 ` [PATCH 2/2] read-cache: free cache in discard_index René Scharfe

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).