diff options
author | Dan McGee <dpmcgee@gmail.com> | 2011-09-08 21:02:46 -0500 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2011-09-28 18:26:12 -0700 |
commit | 1b74092373898a53885cfb7e89aa54f9329a92d3 (patch) | |
tree | e267d6590c7b3fa131877e00d3eef95b351e573b | |
parent | tree-walk: drop unused parameter from match_dir_prefix (diff) | |
download | tgif-1b74092373898a53885cfb7e89aa54f9329a92d3.tar.xz |
tree-walk: micro-optimization in tree_entry_interesting
In the case of a wide breadth top-level tree (~2400 entries, all trees
in this case), we can see a noticeable cost in the profiler calling
strncmp() here. Most of the time we are at the base level of the
repository, so base is "" and baselen == 0, which means we will always
test true. Break out this one tiny case so we can short circuit the
strncmp() call.
Test cases are as follows. packages.git is the Arch Linux git-svn clone
of the packages repository which has the characteristics above.
Commands:
[1] packages.git, /usr/bin/time git log >/dev/null
[2] packages.git, /usr/bin/time git log -- autogen/trunk pacman/trunk wget/trunk >/dev/null
[3] linux.git, /usr/bin/time git log >/dev/null
[4] linux.git, /usr/bin/time git log -- drivers/ata drivers/uio tools >/dev/null
Results:
before after %faster
[1] 2.56 2.55 0.4%
[2] 51.82 48.66 6.5%
[3] 5.58 5.61 -0.5%
[4] 1.55 1.51 0.2%
The takeaway here is this doesn't matter in many operations, but it does
for a certain style of repository and operation where it nets a 6.5%
measured improvement. The other changes are likely not significant by
reasonable statistics methods.
Note: the measured improvement when originally submitted was ~11% (43 to
38 secs) for operation [2]. At the time, the repository had 117220
commits; it now has 137537 commits.
Signed-off-by: Dan McGee <dpmcgee@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | tree-walk.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/tree-walk.c b/tree-walk.c index 9be800760c..f386151ce3 100644 --- a/tree-walk.c +++ b/tree-walk.c @@ -591,8 +591,8 @@ int tree_entry_interesting(const struct name_entry *entry, ps->max_depth); } - /* Does the base match? */ - if (!strncmp(base_str, match, baselen)) { + /* Either there must be no base, or the base must match. */ + if (baselen == 0 || !strncmp(base_str, match, baselen)) { if (match_entry(entry, pathlen, match + baselen, matchlen - baselen, &never_interesting)) |