Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 <dturner@twopensource.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
David Turner authored and Junio C Hamano committed Jan 22, 2016
1 parent d9c2bd5 commit a672095
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion unpack-trees.c
Expand Up @@ -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)
Expand Down

0 comments on commit a672095

Please sign in to comment.