Skip to content

Commit a672095

Browse files
dturner-twgitster
authored andcommitted
unpack-trees: fix accidentally quadratic behavior
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d9c2bd5 commit a672095

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

unpack-trees.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,8 +695,19 @@ static int find_cache_pos(struct traverse_info *info,
695695
++o->cache_bottom;
696696
continue;
697697
}
698-
if (!ce_in_traverse_path(ce, info))
698+
if (!ce_in_traverse_path(ce, info)) {
699+
/*
700+
* Check if we can skip future cache checks
701+
* (because we're already past all possible
702+
* entries in the traverse path).
703+
*/
704+
if (info->traverse_path) {
705+
if (strncmp(ce->name, info->traverse_path,
706+
info->pathlen) > 0)
707+
break;
708+
}
699709
continue;
710+
}
700711
ce_name = ce->name + pfxlen;
701712
ce_slash = strchr(ce_name, '/');
702713
if (ce_slash)

0 commit comments

Comments
 (0)