Merge branch 'js/packfile-fast-append'

The performance of adding numerous new packfiles has been improved
by introducing a fast path for known-new packfiles to skip an
unnecessary traversal in packfile_list_append(), avoiding a
quadratic complexity regression on load.

* js/packfile-fast-append:
  packfile: fix perf regression with many packs
main
Junio C Hamano 2026-08-25 10:53:33 -07:00
commit b7677512b3
4 changed files with 10 additions and 4 deletions

View File

@ -57,11 +57,12 @@ void packfile_list_prepend(struct packfile_list *list, struct packed_git *pack)
list->tail = entry;
}

void packfile_list_append(struct packfile_list *list, struct packed_git *pack)
void packfile_list_append(struct packfile_list *list, struct packed_git *pack,
int skip_dup_check)
{
struct packfile_list_entry *entry;

entry = packfile_list_remove_internal(list, pack);
entry = skip_dup_check ? NULL : packfile_list_remove_internal(list, pack);
if (!entry) {
entry = xmalloc(sizeof(*entry));
entry->pack = pack;

View File

@ -15,7 +15,8 @@ struct packfile_list_entry {
void packfile_list_clear(struct packfile_list *list);
void packfile_list_remove(struct packfile_list *list, struct packed_git *pack);
void packfile_list_prepend(struct packfile_list *list, struct packed_git *pack);
void packfile_list_append(struct packfile_list *list, struct packed_git *pack);
void packfile_list_append(struct packfile_list *list, struct packed_git *pack,
int skip_dup_check);

/*
* Find the pack within the "packs" list whose index contains the object

View File

@ -781,7 +781,7 @@ void packfile_store_add_pack(struct odb_source_packed *store,
if (pack->pack_fd != -1)
pack_open_fds++;

packfile_list_append(&store->packs, pack);
packfile_list_append(&store->packs, pack, 1);
strmap_put(&store->packs_by_path, pack->pack_name, pack);
}


View File

@ -141,4 +141,8 @@ test_perf "load 10,000 packs" '
git rev-parse --verify "HEAD^{commit}"
'

test_perf "abbreviate with 10,000 packs" '
git rev-parse --short HEAD
'

test_done