]> git.ipfire.org Git - thirdparty/git.git/commit
ref-filter: memoize --contains with generations
authorTamir Duberstein <tamird@gmail.com>
Fri, 12 Jun 2026 21:49:13 +0000 (17:49 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 12 Jun 2026 22:56:44 +0000 (15:56 -0700)
commitca96eeee79bc231f8096d9e9d0b501e0495e2db7
tree81fd102d1566bbd657df4aa2a407a05e3014cb9b
parent5bd39784cda151203aa6d97e24c21bf7fddc11de
ref-filter: memoize --contains with generations

git branch and git for-each-ref run a separate reachability walk for
each ref considered by --contains and --no-contains. Refs with shared
history therefore traverse the same commits repeatedly.

git tag instead uses a depth-first walk that caches results across
refs. That walk can perform poorly without generation numbers: a
negative check may walk to the root instead of stopping at a nearby
divergence. Generation numbers let it stop below the oldest target.

Use the memoized walk for all ref-filter callers when generation
numbers are available. Keep git tag on its existing path without
generations. Caching still helps when many tags share deep history:
ffc4b8012d (tag: speed up --contains calculation, 2011-06-11) reduced
git tag --contains HEAD~200 in linux-2.6 from 15.417 to 5.329 seconds.

The new shared-history perf test improves from 0.72 to 0.03 seconds. In
a repository with 62,174 remote-tracking refs, running:

    git branch -r --contains c78ae85f3ce7e

improves from 104.365 seconds to 468 milliseconds.

Suggested-by: Jeff King <peff@peff.net>
Signed-off-by: Tamir Duberstein <tamird@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
commit-reach.c
t/perf/p1500-graph-walks.sh