Skip to content

index-pack: retain child bases in delta cache#2131

Open
arijit91 wants to merge 1 commit into
gitgitgadget:masterfrom
arijit91:index-pack-retain-child-base
Open

index-pack: retain child bases in delta cache#2131
arijit91 wants to merge 1 commit into
gitgitgadget:masterfrom
arijit91:index-pack-retain-child-base

Conversation

@arijit91
Copy link
Copy Markdown

@arijit91 arijit91 commented May 28, 2026

Speed up the local index-pack phase used by clone/fetch for large
delta-compressed packs.

When index-pack reconstructs a child base and queues it for resolving
descendant deltas, it currently frees that data immediately. This can force
the same base to be reconstructed again. This patch keeps the data in the
existing delta base cache and lets delta_base_cache_limit decide whether to
retain or evict it.

This does not add a new cache or increase the cache limit. The object data is
already accounted in base_cache_used, and prune_base_data() is already
called at this point.

Changes since v1:

  • Added benchmark results and leak-safety context to the commit message.
  • Included standard p5302-pack-index.sh perf-suite results.

Correctness:

  • t/t5302-pack-index.sh passed.
  • GitGitGadget's linux-leaks CI exercises t5302-pack-index.sh under
    SANITIZE=leak.

Benchmarks on a quiet Ubuntu 24.04 VM, 16 vCPU, 32 GiB RAM, local SSD:

Standard p5302-pack-index.sh perf-suite results using
GIT_PERF_LARGE_REPO=<repo> ./run HEAD~1 HEAD -- p5302-pack-index.sh:

repo HEAD~1 HEAD wall-time change
libgit2 3.17(11.42+0.61) 2.69(10.49+0.32) 15.1% faster
redis 5.88(15.77+0.63) 4.98(14.08+0.39) 15.3% faster
git.git 11.22(38.31+1.29) 9.69(35.36+0.64) 13.6% faster
cpython 32.64(117.70+4.39) 28.70(109.90+1.98) 12.1% faster
linux 276.95(793.14+39.51) 234.75(722.33+18.01) 15.2% faster

These timings isolate the index-pack phase affected by this patch.

End-to-end local full-clone spot checks also showed wins, though these timings
include both server-side pack-objects and client-side index-pack running
concurrently over a local file:// transport, so they are not isolated
index-pack timings.

These runs used git clone --bare --no-local, dropped page cache before each
clone, and pinned GIT_EXEC_PATH, PATH, and --upload-pack so helper
processes came from the selected build. Trace2 confirmed that index-pack and
pack-objects resolved to the intended baseline or patched binary.

repo baseline patched wall-time change
libgit2 4.99s 4.50s 9.8% faster
redis 8.71s 7.90s 9.3% faster
git.git 24.89s 23.57s 5.3% faster
cpython 58.77s 53.84s 8.4% faster
linux 549.21s 515.52s 6.1% faster

CC: Ævar Arnfjörð Bjarmason avarab@gmail.com, Junio C Hamano gitster@pobox.com, Derrick Stolee stolee@gmail.com
cc: Jeff King peff@peff.net

@gitgitgadget
Copy link
Copy Markdown

gitgitgadget Bot commented May 28, 2026

Welcome to GitGitGadget

Hi @arijit91, and welcome to GitGitGadget, the GitHub App to send patch series to the Git mailing list from GitHub Pull Requests.

Please make sure that either:

  • Your Pull Request has a good description, if it consists of multiple commits, as it will be used as cover letter.
  • Your Pull Request description is empty, if it consists of a single commit, as the commit message should be descriptive enough by itself.

You can CC potential reviewers by adding a footer to the PR description with the following syntax:

CC: Revi Ewer <revi.ewer@example.com>, Ill Takalook <ill.takalook@example.net>

NOTE: DO NOT copy/paste your CC list from a previous GGG PR's description,
because it will result in a malformed CC list on the mailing list. See
example.

Also, it is a good idea to review the commit messages one last time, as the Git project expects them in a quite specific form:

  • the lines should not exceed 76 columns,
  • the first line should be like a header and typically start with a prefix like "tests:" or "revisions:" to state which subsystem the change is about, and
  • the commit messages' body should be describing the "why?" of the change.
  • Finally, the commit messages should end in a Signed-off-by: line matching the commits' author.

It is in general a good idea to await the automated test ("Checks") in this Pull Request before contributing the patches, e.g. to avoid trivial issues such as unportable code.

Contributing the patches

Before you can contribute the patches, your GitHub username needs to be added to the list of permitted users. Any already-permitted user can do that, by adding a comment to your PR of the form /allow. A good way to find other contributors is to locate recent pull requests where someone has been /allowed:

Both the person who commented /allow and the PR author are able to /allow you.

An alternative is the channel #git-devel on the Libera Chat IRC network:

<newcontributor> I've just created my first PR, could someone please /allow me? https://github.com/gitgitgadget/git/pull/12345
<veteran> newcontributor: it is done
<newcontributor> thanks!

Once on the list of permitted usernames, you can contribute the patches to the Git mailing list by adding a PR comment /submit.

If you want to see what email(s) would be sent for a /submit request, add a PR comment /preview to have the email(s) sent to you. You must have a public GitHub email address for this. Note that any reviewers CC'd via the list in the PR description will not actually be sent emails.

After you submit, GitGitGadget will respond with another comment that contains the link to the cover letter mail in the Git mailing list archive. Please make sure to monitor the discussion in that thread and to address comments and suggestions (while the comments and suggestions will be mirrored into the PR by GitGitGadget, you will still want to reply via mail).

If you do not want to subscribe to the Git mailing list just to be able to respond to a mail, you can download the mbox from the Git mailing list archive (click the (raw) link), then import it into your mail program. If you use GMail, you can do this via:

curl -g --user "<EMailAddress>:<Password>" \
    --url "imaps://imap.gmail.com/INBOX" -T /path/to/raw.txt

To iterate on your change, i.e. send a revised patch or patch series, you will first want to (force-)push to the same branch. You probably also want to modify your Pull Request description (or title). It is a good idea to summarize the revision by adding something like this to the cover letter (read: by editing the first comment on the PR, i.e. the PR description):

Changes since v1:
- Fixed a typo in the commit message (found by ...)
- Added a code comment to ... as suggested by ...
...

To send a new iteration, just add another PR comment with the contents: /submit.

Need help?

New contributors who want advice are encouraged to join git-mentoring@googlegroups.com, where volunteers who regularly contribute to Git are willing to answer newbie questions, give advice, or otherwise provide mentoring to interested contributors. You must join in order to post or view messages, but anyone can join.

You may also be able to find help in real time in the developer IRC channel, #git-devel on Libera Chat. Remember that IRC does not support offline messaging, so if you send someone a private message and log out, they cannot respond to you. The scrollback of #git-devel is archived, though.

@arijit91
Copy link
Copy Markdown
Author

/submit

@gitgitgadget
Copy link
Copy Markdown

gitgitgadget Bot commented May 28, 2026

Error: User arijit91 is not yet permitted to use GitGitGadget

@dscho
Copy link
Copy Markdown
Member

dscho commented May 29, 2026

/allow

@gitgitgadget
Copy link
Copy Markdown

gitgitgadget Bot commented May 29, 2026

User arijit91 is now allowed to use GitGitGadget.

@arijit91
Copy link
Copy Markdown
Author

/submit

@gitgitgadget
Copy link
Copy Markdown

gitgitgadget Bot commented May 29, 2026

Submitted as pull.2131.git.1780070763044.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-2131/arijit91/index-pack-retain-child-base-v1

To fetch this version to local tag pr-2131/arijit91/index-pack-retain-child-base-v1:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-2131/arijit91/index-pack-retain-child-base-v1

@gitgitgadget
Copy link
Copy Markdown

gitgitgadget Bot commented May 31, 2026

This branch is now known as ab/index-pack-retain-child-bases.

@gitgitgadget
Copy link
Copy Markdown

gitgitgadget Bot commented May 31, 2026

This patch series was integrated into seen via git@b581127.

@gitgitgadget gitgitgadget Bot added the seen label May 31, 2026
When resolving a delta whose result has children of its own,
index-pack adds the result to work_head, accounts its data in
base_cache_used, and calls prune_base_data(). It then immediately frees
that same data.

This bypasses the existing delta base cache policy and can force later
descendants to reconstruct the queued base again. Let the existing
delta_base_cache_limit pruning policy decide whether to keep or evict
the data instead.

This does not add a new cache or increase the cache limit. The object
data is already accounted in base_cache_used before prune_base_data()
runs, and the existing pruning and base cleanup paths still release it.

On a quiet Ubuntu 24.04 VM with 16 vCPUs, 32 GiB RAM, and local SSD,
direct index-pack timings on single-pack Linux fixtures improved as
follows:

  linux blobless: 69.17s -> 57.98s (16.2% faster), RSS flat
  linux full:     280.72s -> 236.32s (15.8% faster), RSS +1.9%

Five-repeat medians on public repositories also improved:

  git.git:  12.31s -> 10.70s (13.1% faster)
  libgit2:   3.35s ->  2.88s (14.0% faster)
  redis:     6.52s ->  5.64s (13.5% faster)
  cpython:  33.02s -> 31.44s (4.8% faster)

The standard p5302 perf test on a smaller git.git fixture was neutral:

  5302.9 index-pack default threads:
    11.21(38.07+1.33) -> 11.16(37.90+1.31), -0.4%

t/t5302-pack-index.sh passed, and GitGitGadget's linux-leaks CI also
exercised that test under SANITIZE=leak.

Signed-off-by: Arijit Banerjee <arijit@effectiveailabs.com>
@arijit91 arijit91 force-pushed the index-pack-retain-child-base branch from cafb170 to 42eca38 Compare June 1, 2026 16:12
@arijit91
Copy link
Copy Markdown
Author

arijit91 commented Jun 1, 2026

/submit

@gitgitgadget
Copy link
Copy Markdown

gitgitgadget Bot commented Jun 1, 2026

Submitted as pull.2131.v2.git.1780330402264.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-2131/arijit91/index-pack-retain-child-base-v2

To fetch this version to local tag pr-2131/arijit91/index-pack-retain-child-base-v2:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-2131/arijit91/index-pack-retain-child-base-v2

@gitgitgadget
Copy link
Copy Markdown

gitgitgadget Bot commented Jun 1, 2026

Derrick Stolee wrote on the Git mailing list (how to reply to this email):

On 5/29/2026 12:06 PM, Arijit Banerjee via GitGitGadget wrote:
> From: Arijit Banerjee <arijit@effectiveailabs.com>
> 
> When resolving a delta whose result has children of its own,
> index-pack adds the result to work_head, accounts its data in
> base_cache_used, and calls prune_base_data(). It then immediately
> frees that same data.
> 
> This bypasses the existing delta base cache policy and can force later
> descendants to reconstruct the queued base again. Let the existing
> delta_base_cache_limit pruning policy decide whether to keep or evict
> the data instead.
> 
> Signed-off-by: Arijit Banerjee <arijit@effectiveailabs.com>
> ---
>     index-pack: retain child bases in delta cache
>     
>     Speed up the local pack indexing phase of clone/fetch for large
>     delta-compressed packs by keeping reconstructed delta bases available
>     for reuse when they are queued for later delta resolution.
>     
>     When index-pack reconstructs a child base and queues it for resolving
>     descendant deltas, it currently frees that data immediately. This can
>     force the same base to be reconstructed again. Instead, keep it in the
>     existing delta base cache and let the existing delta_base_cache_limit
>     policy decide whether to retain or evict it.
>     
>     This does not add a new cache or increase the cache limit. The object
>     data is already accounted in base_cache_used, and prune_base_data() is
>     already called at this point.
>     
>     Correctness:
>     
>      * t/t5302-pack-index.sh passed all 36 tests.

Is there any chance that you ran this also with SANITIZE=leak to make
sure that we aren't introducing a memory leak? (It's hard to tell just
from the patch context, though your description is convincing.)

> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2131%2Farijit91%2Findex-pack-retain-child-base-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2131/arijit91/index-pack-retain-child-base-v1
> Pull-Request: https://github.com/gitgitgadget/git/pull/2131

Indeed, this PR has a passing linux-leaks build that exercises this
test script. [1]

[1] https://github.com/gitgitgadget/git/actions/runs/26605615549/job/78399938323?pr=2131#step:9:1405

>     Benchmarks on a quiet Ubuntu 24.04 VM, 16 vCPU, 32 GiB RAM, local SSD:
>     
>     pack baseline patched wall-time change RSS change linux blobless 69.17s
>     57.98s 16.2% faster -0.0% linux full 280.72s 236.32s 15.8% faster +1.9%
>     
>     Five-repeat public-repo medians also improved: git.git 13.1%, libgit2
>     14.0%, redis 13.5%, cpython 4.8%.
>     
>     Perf on the linux blobless pack showed the same direction under
>     profiling: 76.64s baseline vs 61.09s patched, with similar RSS.
A lot of this information that is in your cover letter would be helpful
to include in your commit message, for posterity.

Also, I prefer to see performance numbers for these repos reflected in
results from our performance test suite. We have a test for this purpose,
so you could try running this from t/perf/ for your local copies of these
repos:

  GIT_PERF_LARGE_REPO=<path> ./run HEAD~1 HEAD -- p5302-pack-index.sh

And this should result in a standard comparison table that will help
present your results in a way that is familiar to Git contributors.

> @@ -1212,7 +1212,6 @@ static void *threaded_second_pass(void *data)
>  			list_add(&child->list, &work_head);
>  			base_cache_used += child->size;
>  			prune_base_data(NULL);
> -			free_base_data(child);
>  		} else if (child) {
A nice and simple change. Good find!

Thanks,
-Stolee

@arijit91
Copy link
Copy Markdown
Author

arijit91 commented Jun 2, 2026 via email

@arijit91
Copy link
Copy Markdown
Author

arijit91 commented Jun 2, 2026 via email

@gitgitgadget
Copy link
Copy Markdown

gitgitgadget Bot commented Jun 2, 2026

This patch series was integrated into seen via git@b0c7b14.

@gitgitgadget
Copy link
Copy Markdown

gitgitgadget Bot commented Jun 2, 2026

Jeff King wrote on the Git mailing list (how to reply to this email):

On Mon, Jun 01, 2026 at 04:13:21PM +0000, Arijit Banerjee via GitGitGadget wrote:

> When resolving a delta whose result has children of its own,
> index-pack adds the result to work_head, accounts its data in
> base_cache_used, and calls prune_base_data(). It then immediately frees
> that same data.
> 
> This bypasses the existing delta base cache policy and can force later
> descendants to reconstruct the queued base again. Let the existing
> delta_base_cache_limit pruning policy decide whether to keep or evict
> the data instead.
> 
> This does not add a new cache or increase the cache limit. The object
> data is already accounted in base_cache_used before prune_base_data()
> runs, and the existing pruning and base cleanup paths still release it.

That explanation makes sense, but I'm left with one question/concern.
Dropping the data for a base makes sense when we are "done" with it,
because we know we won't need it anymore and it leaves more room in the
cache for things we do care about.

The problem here is that the current notion of "done" is not correct.
Imagine we have delta chains "A -> B -> C" and "A -> D -> F". We are
totally done with A when we have resolved both B and D, but if I
understand correctly, we currently throw it away after just resolving B.

Your patch never throws it away, and just waits for it to get evicted
from the cache due to memory pressure. But could we realize the moment
when B and D have both finished using it, and evict it then? That makes
it more likely for us to keep something useful in the cache when there
is pressure.

I'm not sure how hard that would be in practice, or how much it would
help (the base cache works in list order, so I think it might naturally
be a sort of LRU?).

-Peff

@gitgitgadget
Copy link
Copy Markdown

gitgitgadget Bot commented Jun 2, 2026

User Jeff King <peff@peff.net> has been added to the cc: list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants