Skip to content

Commit 1b74092

Browse files
toofishesgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6de9691 commit 1b74092

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

tree-walk.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,8 +591,8 @@ int tree_entry_interesting(const struct name_entry *entry,
591591
ps->max_depth);
592592
}
593593

594-
/* Does the base match? */
595-
if (!strncmp(base_str, match, baselen)) {
594+
/* Either there must be no base, or the base must match. */
595+
if (baselen == 0 || !strncmp(base_str, match, baselen)) {
596596
if (match_entry(entry, pathlen,
597597
match + baselen, matchlen - baselen,
598598
&never_interesting))

0 commit comments

Comments
 (0)