Skip to content

[RFC] pack-objects: try older bases with chunk hints - #2327

Draft
sluongng wants to merge 3 commits into
gitgitgadget:masterfrom
sluongng:sluongng/git-pack-cdc-series
Draft

sluongng wants to merge 3 commits into
gitgitgadget:masterfrom
sluongng:sluongng/git-pack-cdc-series

Conversation

@sluongng

@sluongng sluongng commented Nov 23, 2026 •

Copy link
Copy Markdown

When Git packs large blobs, a good delta base can fall out of the
search window before Git gets to the next similar blob. This RFC asks
whether path-walk should try one more base from the same path, and
how to pick it. The prototype uses content-defined chunking (CDC).

For context, I helped drive chunking standardization in the Bazel
Remote Execution API [1], and I ran the unconference session on using
CDC for Git LFS at Git Merge in Lisbon [2].

Patrick Steinhardt discussed CDC as a way to store large blobs in Git
at FOSDEM 2026 [3]. At the NVIDIA hackathon on making partial clones a
practical alternative to Git LFS [4], we explored keeping large blobs
in object storage behind a promisor remote [7]. A conversation with
Martin Fick got me thinking about a smaller step: could CDC help the
pack writer without changing how Git stores blobs?

Separately, I have a branch exploring CDC at the pluggable object
database layer. It uses a storage format called filev2 to store large
loose blobs as chunks [8]. This RFC doesn't depend on either storage
experiment.

CDC picks chunk boundaries from the data, not from fixed offsets.
An insertion can shift the bytes without changing many of the chunks
that follow. The prototype draws on FastCDC in Bazel [5] and
BuildBuddy [6].

Original: [foo]     [bar][baz]
Edited:   [new-foo] [bar][baz]

The edit shifts [bar] and [baz], but they still match.

Path-walk groups blobs by path. This patch keeps chunk fingerprints
for some evicted blobs and uses matching chunks to choose at most
one older blob to try. The normal delta matcher still checks the
bytes; it doesn't delta individual chunks. The hint is off by default.
Older Git can read the packs: object IDs, pack format, and wire
protocol are unchanged. A simpler alternative is to try the blob at
the same path in the parent commit.

On a 32-version Chromium ICU file history, with --window=2, hints
reduced the pack from 26.76 MB to 11.23 MB, while peak RSS rose from
54 to 82 MiB. The default window without hints made a smaller pack
(9.17 MB) but used 293 MiB. In three unmodified slices of public Git
LFS asset histories, hints did not change the resulting packs.

In tests where I deliberately put a useful base outside the window,
the parent and a finer fingerprint sketch found different cases.
That shows the choice of hint matters, but not yet how often the
extra search pays off in practice.

The first two patches fix existing bugs. Patch 3 is the focus of this
RFC, which is for discussion rather than merging:

1/3: Honor the delta depth limit across both path-walk passes.
2/3: Honor no-fetch requests when recovering packed objects.
3/3: Use chunk fingerprints to try an older same-path delta base.

All feedback is welcome. I'd especially like to hear what people think
about these two questions:

  1. Is one extra same-path base attempt worth exploring as an
    opt-in part of path-walk?
  2. What real histories should it beat a wider window or a
    parent-only hint on, and at what CPU and memory cost?

If you have a repository with a history of changing large blobs, I'd
also welcome benchmarks from it, even if the packs don't change. On
the same build and object set, run pack-objects with --path-walk and
--no-reuse-delta, setting pack.pathWalkUseChunkHints to false and true.
Keep the window and thread count fixed and report pack size, writer
CPU, and peak RSS. The prototype considers 4-64 MiB blobs and is
disabled when pack.windowMemory is nonzero.

[1] bazelbuild/remote-apis#357
[2] https://git-merge.com/
[3] https://archive.fosdem.org/2026/schedule/event/HTJK33-evolving_git_for_the_next_decade/
[4] https://gus26.gerritforge.com/#hackathon
[5] https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/build/lib/remote/chunking/FastCdcChunker.java
[6] https://github.com/buildbuddy-io/fastcdc2020
[7] https://git-scm.com/docs/large-object-promisors
[8] https://github.com/sluongng/git/tree/sluongng/filev2-odb-review

Path-walk searches for deltas at each path before the ordinary search
looks for more bases. If the path pass creates a delta and leaves
its base undeltified, the ordinary search can turn that base into
another delta without accounting for the child. A pack written with
--depth=1 can then contain a chain of depth two.

Rebuild the delta-child links after the path workers finish so that
the existing depth check includes the children from the path pass.
Share the link builder with write ordering and clear external base
children before relinking.

Exercise two paths that share a name hash and assert that the path
delta still exists without exceeding the requested depth.

Signed-off-by: Son Luong Ngoc <sluongng@gmail.com>
git mktree checks entry types without fetching. When a packed delta's
base header is corrupt, recovery drops the no-fetch flag and can
download a remote-only replacement.

Carry the flag through type lookup and unpacking. Exclude the failed
copy only for the current no-fetch lookup, so a later read can still
recover it when fetching is allowed. Preserve the ordinary recovery
and replacement lookup rules.

Test a remote-only replacement, including a fetch-enabled retry after
a no-fetch failure in the same process.

Signed-off-by: Son Luong Ngoc <sluongng@gmail.com>
A narrow path-walk window can evict a useful base. When the ordinary
search finds no small delta, use chunk fingerprints to try one of up
to 16 evicted blobs from the same path. Do not fetch a hinted base. The
normal matcher still chooses the delta, and the reader is unchanged.

With one thread and reuse disabled, a two-entry window packed a
32-version Chromium ICU history into 11.23 MB rather than 26.76 MB,
at 82 rather than 54 MiB peak RSS. Keep hints opt-in and skip them
when window memory is limited.

Signed-off-by: Son Luong Ngoc <sluongng@gmail.com>
@sluongng
sluongng force-pushed the sluongng/git-pack-cdc-series branch from 9af37d6 to 9906a3e Compare November 23, 2026 13:23
@sluongng

Copy link
Copy Markdown
Author

/preview

@gitgitgadget

gitgitgadget Bot commented Nov 23, 2026

Copy link
Copy Markdown

Preview email sent as pull.2327.git.1795447145.gitgitgadget@gmail.com

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant