{"thread":{"id":"34077","subject":"[PATCH 1/2] read-cache: add simple performance test","startedAt":"2013-06-09T17:39:17Z","lastAt":"2013-06-09T17:39:18Z","messageCount":2,"participants":["René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"220045","messageId":"1370799558-18188-1-git-send-email-rene.scharfe@lsrfire.ath.cx","threadId":"34077","inReplyTo":null,"subject":"[PATCH 1/2] read-cache: add simple performance test","fromName":"René Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2013-06-09T17:39:17Z","receivedAt":"2013-06-09T17:39:17Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Add the helper test-read-cache, which can be used to call read_cache and\ndiscard_cache in a loop as well as a performance check based on it.\n\nSigned-off-by: René Scharfe <rene.scharfe@lsrfire.ath.cx>\n---\n .gitignore                 |  1 +\n Makefile                   |  1 +\n t/perf/p0002-read-cache.sh | 14 ++++++++++++++\n test-read-cache.c          | 13 +++++++++++++\n 4 files changed, 29 insertions(+)\n create mode 100755 t/perf/p0002-read-cache.sh\n create mode 100644 test-read-cache.c\n\ndiff --git a/.gitignore b/.gitignore\nindex 1640c3a..c0e00eb 100644\n--- a/.gitignore\n+++ b/.gitignore\n@@ -191,6 +191,7 @@\n /test-mktemp\n /test-parse-options\n /test-path-utils\n+/test-read-cache\n /test-regex\n /test-revision-walking\n /test-run-command\ndiff --git a/Makefile b/Makefile\nindex a748133..2e3b4ee 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -572,6 +572,7 @@ TEST_PROGRAMS_NEED_X += test-mergesort\n TEST_PROGRAMS_NEED_X += test-mktemp\n TEST_PROGRAMS_NEED_X += test-parse-options\n TEST_PROGRAMS_NEED_X += test-path-utils\n+TEST_PROGRAMS_NEED_X += test-read-cache\n TEST_PROGRAMS_NEED_X += test-regex\n TEST_PROGRAMS_NEED_X += test-revision-walking\n TEST_PROGRAMS_NEED_X += test-run-command\ndiff --git a/t/perf/p0002-read-cache.sh b/t/perf/p0002-read-cache.sh\nnew file mode 100755\nindex 0000000..9180ae9\n--- /dev/null\n+++ b/t/perf/p0002-read-cache.sh\n@@ -0,0 +1,14 @@\n+#!/bin/sh\n+\n+test_description=\"Tests performance of reading the index\"\n+\n+. ./perf-lib.sh\n+\n+test_perf_default_repo\n+\n+count=1000\n+test_perf \"read_cache/discard_cache $count times\" \"\n+\ttest-read-cache $count\n+\"\n+\n+test_done\ndiff --git a/test-read-cache.c b/test-read-cache.c\nnew file mode 100644\nindex 0000000..b25bcf1\n--- /dev/null\n+++ b/test-read-cache.c\n@@ -0,0 +1,13 @@\n+#include \"cache.h\"\n+\n+int main (int argc, char **argv)\n+{\n+\tint i, cnt = 1;\n+\tif (argc == 2)\n+\t\tcnt = strtol(argv[1], NULL, 0);\n+\tfor (i = 0; i < cnt; i++) {\n+\t\tread_cache();\n+\t\tdiscard_cache();\n+\t}\n+\treturn 0;\n+}\n-- \n1.8.3\n"},{"id":"220046","messageId":"1370799558-18188-2-git-send-email-rene.scharfe@lsrfire.ath.cx","threadId":"34077","inReplyTo":"1370799558-18188-1-git-send-email-rene.scharfe@lsrfire.ath.cx","subject":"[PATCH 2/2] read-cache: free cache in discard_index","fromName":"René Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2013-06-09T17:39:18Z","receivedAt":"2013-06-09T17:39:18Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"discard_cache doesn't have to free the array of cache entries, because\nthe next call of read_cache can simply reuse it, as they all operate on\nthe global variable the_index.\n\ndiscard_index on the other hand does have to free it, because it can be\nused e.g. with index_state variables on the stack, in which case a\nmissing free would cause an unrecoverable leak.  This patch releases the\nmemory and removes a comment that was relevant for discard_cache but has\nbecome outdated.\n\nSince discard_cache is just a wrapper around discard_index nowadays, we\nlose the optimization that avoids reallocation of that array within\nloops of read_cache and discard_cache.  That doesn't cause a performance\nregression for me, however (HEAD = this patch, HEAD^ = master + p0002):\n\n  Test           //              HEAD^             HEAD\n  ---------------\\\\-----------------------------------------------------\n  0002.1: read_ca// 1000 times   0.62(0.58+0.04)   0.61(0.58+0.02) -1.6%\n\nSuggested-by: Felipe Contreras <felipe.contreras@gmail.com>\nSigned-off-by: René Scharfe <rene.scharfe@lsrfire.ath.cx>\n---\n read-cache.c | 5 +++--\n 1 file changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/read-cache.c b/read-cache.c\nindex 04ed561..4245f8e 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -1518,8 +1518,9 @@ int discard_index(struct index_state *istate)\n \tfree_name_hash(istate);\n \tcache_tree_free(&(istate->cache_tree));\n \tistate->initialized = 0;\n-\n-\t/* no need to throw away allocated active_cache */\n+\tfree(istate->cache);\n+\tistate->cache = NULL;\n+\tistate->cache_alloc = 0;\n \treturn 0;\n }\n \n-- \n1.8.3\n"}]}