threads / patch / 41243

v3unpack-trees: fix accidentally quadratic behavior

Subject: [PATCH v3] unpack-trees: fix accidentally quadratic behavior

## tl;dr

One message between Jan 22, 2016 and Jan 22, 2016. Diffs are folded; open one to read it.

replies: 0people: 1as markdown or json

David Turner· Jan 22, 2016, 19:58 UTC · lore

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>
---
A colleague pointed out that the info->prev test was unnecessary as
ce_in_traverse_path already does that.
---
 unpack-trees.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
Show changes to unpack-trees.c +12 −1
diff --git a/unpack-trees.c b/unpack-trees.c
index 5f541c2..9f55cc2 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -695,8 +695,19 @@ 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->traverse_path) {
+				if (strncmp(ce->name, info->traverse_path,
+					    info->pathlen) > 0)
+					break;
+			}
 			continue;
+		}
 		ce_name = ce->name + pfxlen;
 		ce_slash = strchr(ce_name, '/');
 		if (ce_slash)
-- 
2.4.2.749.g730654d-twtrsrc

← back to recent threads