{"thread":{"id":"45694","subject":"[PATCH v5] string-list: use ALLOC_GROW macro when reallocing","startedAt":"2017-04-14T19:52:12Z","lastAt":"2017-04-14T19:52:14Z","messageCount":2,"participants":["git@jeffhostetler.com"],"isPatch":true,"patchVersion":5,"patchTotal":null},"messages":[{"id":"316846","messageId":"20170414195152.33919-1-git@jeffhostetler.com","threadId":"45694","inReplyTo":null,"subject":"[PATCH v5] string-list: use ALLOC_GROW macro when reallocing","fromName":"","fromEmail":"git@jeffhostetler.com","sentAt":"2017-04-14T19:51:51Z","receivedAt":"2017-04-14T19:52:12Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nVersion 5 addresses coding style comments from the mailing list\nin the perf test and squashes the changes into 1 commit.\n\nJeff Hostetler (1):\n  string-list: use ALLOC_GROW macro when reallocing string_list\n\n string-list.c          |  5 +----\n t/perf/p0005-status.sh | 49 +++++++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 50 insertions(+), 4 deletions(-)\n create mode 100755 t/perf/p0005-status.sh\n\n-- \n2.9.3\n\n"},{"id":"316847","messageId":"20170414195152.33919-2-git@jeffhostetler.com","threadId":"45694","inReplyTo":"20170414195152.33919-1-git@jeffhostetler.com","subject":"[PATCH v5] string-list: use ALLOC_GROW macro when reallocing string_list","fromName":"","fromEmail":"git@jeffhostetler.com","sentAt":"2017-04-14T19:51:52Z","receivedAt":"2017-04-14T19:52:14Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"From: Jeff Hostetler <jeffhost@microsoft.com>\n\nUse ALLOC_GROW() macro when reallocing a string_list array\nrather than simply increasing it by 32.  This is a performance\noptimization.\n\nDuring status on a very large repo and there are many changes,\na significant percentage of the total run time is spent\nreallocing the wt_status.changes array.\n\nThis change decreases the time in wt_status_collect_changes_worktree()\nfrom 125 seconds to 45 seconds on my very large repository.\n\nThis produced a modest gain on my 1M file artificial repo, but\nbroke even on linux.git.\n\nTest                                            HEAD^^            HEAD\n---------------------------------------------------------------------------------------\n0005.2: read-tree status br_ballast (1000001)   8.29(5.62+2.62)   8.22(5.57+2.63) -0.8%\n\nSigned-off-by: Jeff Hostetler <jeffhost@microsoft.com>\n---\n string-list.c          |  5 +----\n t/perf/p0005-status.sh | 49 +++++++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 50 insertions(+), 4 deletions(-)\n create mode 100755 t/perf/p0005-status.sh\n\ndiff --git a/string-list.c b/string-list.c\nindex 45016ad..003ca18 100644\n--- a/string-list.c\n+++ b/string-list.c\n@@ -41,10 +41,7 @@ static int add_entry(int insert_at, struct string_list *list, const char *string\n \tif (exact_match)\n \t\treturn -1 - index;\n \n-\tif (list->nr + 1 >= list->alloc) {\n-\t\tlist->alloc += 32;\n-\t\tREALLOC_ARRAY(list->items, list->alloc);\n-\t}\n+\tALLOC_GROW(list->items, list->nr+1, list->alloc);\n \tif (index < list->nr)\n \t\tmemmove(list->items + index + 1, list->items + index,\n \t\t\t\t(list->nr - index)\ndiff --git a/t/perf/p0005-status.sh b/t/perf/p0005-status.sh\nnew file mode 100755\nindex 0000000..0b0aa98\n--- /dev/null\n+++ b/t/perf/p0005-status.sh\n@@ -0,0 +1,49 @@\n+#!/bin/sh\n+#\n+# This test measures the performance of various read-tree\n+# and status operations.  It is primarily interested in\n+# the algorithmic costs of index operations and recursive\n+# tree traversal -- and NOT disk I/O on thousands of files.\n+\n+test_description=\"Tests performance of read-tree\"\n+\n+. ./perf-lib.sh\n+\n+test_perf_default_repo\n+\n+# If the test repo was generated by ./repos/many-files.sh\n+# then we know something about the data shape and branches,\n+# so we can isolate testing to the ballast-related commits\n+# and setup sparse-checkout so we don't have to populate\n+# the ballast files and directories.\n+#\n+# Otherwise, we make some general assumptions about the\n+# repo and consider the entire history of the current\n+# branch to be the ballast.\n+\n+test_expect_success \"setup repo\" '\n+\tif git rev-parse --verify refs/heads/p0006-ballast^{commit}\n+\tthen\n+\t\techo Assuming synthetic repo from many-files.sh\n+\t\tgit branch br_base            master\n+\t\tgit branch br_ballast         p0006-ballast\n+\t\tgit config --local core.sparsecheckout 1\n+\t\tcat >.git/info/sparse-checkout <<-EOF\n+\t\t/*\n+\t\t!ballast/*\n+\t\tEOF\n+\telse\n+\t\techo Assuming non-synthetic repo...\n+\t\tgit branch br_base            $(git rev-list HEAD | tail -n 1)\n+\t\tgit branch br_ballast         HEAD\n+\tfi &&\n+\tgit checkout -q br_ballast &&\n+\tnr_files=$(git ls-files | wc -l)\n+'\n+\n+test_perf \"read-tree status br_ballast ($nr_files)\" '\n+\tgit read-tree HEAD &&\n+\tgit status\n+'\n+\n+test_done\n-- \n2.9.3\n\n"}]}