From: David Turner <dturner@twopensource.com>
To: git@vger.kernel.org
Cc: David Turner <dturner@twopensource.com>
Subject: [PATCH] unpack-trees: fix accidentally quadratic behavior
Date: Wed, 20 Jan 2016 23:05:56 -0500 [thread overview]
Message-ID: <1453349156-12553-1-git-send-email-dturner@twopensource.com> (raw)
While unpacking trees (e.g. during git checkout), when we hit a cache
entry that's past and outside our path, we cut off iteration.
This provides about a 45% speedup on git checkout between master and
master^20000 on Twitter's monorepo. Speedup in general will depend on
repostitory structure, number of changes, and packfile packing
decisions.
Signed-off-by: David Turner <dturner@twopensource.com>
---
unpack-trees.c | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/unpack-trees.c b/unpack-trees.c
index 5f541c2..b18a611 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -695,8 +695,25 @@ static int find_cache_pos(struct traverse_info *info,
++o->cache_bottom;
continue;
}
- if (!ce_in_traverse_path(ce, info))
+ if (!ce_in_traverse_path(ce, info)) {
+ /*
+ * Check if we can skip future cache checks
+ * (because we're already past all possible
+ * entries in the traverse path).
+ */
+ if (info->prev && info->traverse_path) {
+ int prefix_cmp = strncmp(ce->name, info->traverse_path, info->pathlen);
+ if (prefix_cmp > 0)
+ break;
+ else if (prefix_cmp == 0 &&
+ ce_namelen(ce) >= info->pathlen &&
+ strcmp(ce->name + info->pathlen,
+ info->name.path) > 0) {
+ break;
+ }
+ }
continue;
+ }
ce_name = ce->name + pfxlen;
ce_slash = strchr(ce_name, '/');
if (ce_slash)
--
2.4.2.749.g730654d-twtrsrc
next reply other threads:[~2016-01-21 4:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-21 4:05 David Turner [this message]
2016-01-21 4:58 ` [PATCH] unpack-trees: fix accidentally quadratic behavior Junio C Hamano
2016-01-21 19:09 ` David Turner
2016-01-21 19:51 ` Junio C Hamano
2016-01-21 20:59 ` David Turner
2016-01-21 21:06 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1453349156-12553-1-git-send-email-dturner@twopensource.com \
--to=dturner@twopensource.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).