Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Documentation/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ TECH_DOCS += technical/hash-function-transition
TECH_DOCS += technical/large-object-promisors
TECH_DOCS += technical/long-running-process-protocol
TECH_DOCS += technical/multi-pack-index
TECH_DOCS += technical/pack-chunk-hints
TECH_DOCS += technical/packfile-uri
TECH_DOCS += technical/pack-heuristics
TECH_DOCS += technical/paint-down-to-common
Expand Down
16 changes: 16 additions & 0 deletions Documentation/config/pack.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ pack.windowMemory::
suffixed with "k", "m", or "g". When left unconfigured (or
set explicitly to 0), there will be no limit.

pack.pathWalkUseChunkHints::
When packing with path-walk, use content-defined chunk fingerprints
to look for one additional delta base when the normal same-path
window finds no small delta. Git considers recently evicted
candidates from the same path and validates a hint with the normal
delta matcher.
This can reduce pack size when the window misses a similar version
of a large blob, at the cost of fingerprinting and possibly
rereading a base. It has no effect without path-walk or when
`pack.windowMemory` is nonzero. Like the ordinary search, hints
skip bases in the same pack as an undeltified target unless
delta reuse is disabled (for example, with `git repack -f`).
Defaults to false and does not change the pack format. See
link:technical/pack-chunk-hints.html[Chunk hints for path-walk packing]
for how Git chooses and checks a hinted base.

pack.compression::
An integer -1..9, indicating the compression level for objects
in a pack file. -1 is the zlib default. 0 means no
Expand Down
1 change: 1 addition & 0 deletions Documentation/technical/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ articles = [
'large-object-promisors.adoc',
'long-running-process-protocol.adoc',
'multi-pack-index.adoc',
'pack-chunk-hints.adoc',
'packfile-uri.adoc',
'pack-heuristics.adoc',
'paint-down-to-common.adoc',
Expand Down
70 changes: 70 additions & 0 deletions Documentation/technical/pack-chunk-hints.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
= Chunk hints for path-walk packing

The delta search in linkgit:git-pack-objects[1] considers bases in a
sliding window. A similar version of a large blob can leave that window
before Git reaches the target. Widening the window keeps more unpacked
objects and delta indexes in memory and compares more pairs. Chunk hints
let Git try one base outside the window without keeping its data or
delta index.

== Collecting fingerprints

Path-walk groups objects by path. Hints are local to one such group and
are not used by the later global search. The order within a group is
the delta search order, not the order of commits in the history.

When an eligible blob leaves the window, Git fingerprints it only if
the ordinary search already read its bytes. Hints cover blobs from
4 MiB to 64 MiB and do not save preferred bases. Git retains one
fingerprint set per evicted blob, up to 16 blobs for the current path.
That limits how many eligible bases Git remembers, not how many chunks
each set can hold. Git evicts the least recent set as it adds another and
releases them all when it finishes that path.

Git uses a rolling Gear hash to choose content-defined chunk boundaries.
A shift in the file need not shift every later boundary, as it would
with fixed-size chunks. The chunker looks for cuts between 16 KiB and
256 KiB, with a looser cut criterion starting at 64 KiB. The last
chunk may be shorter.

Each entry contains a 64-bit FNV-1a fingerprint of the entire chunk
and the chunk's length. The Gear table and cut masks are constants.
Git updates both hashes in the same scan where it looks for a cut.
It sorts the entries and removes duplicates, so repeated chunks do not
inflate the score. The set does not preserve offsets, order, or
repetition counts. It cannot reconstruct a blob and is not written to
disk or sent to a peer.

== Trying a hinted base

The normal search runs first. If it finds a delta no larger than one
eighth of the target before compression, Git skips the hint. Otherwise,
if the target bytes are already loaded, Git can compare the target's
fingerprint set against the retained bases. It screens out bases based
on delta depth, islands, and the ordinary reuse rules before scoring.

The score is the sum of the lengths of distinct matching chunks. Git
tries at most one candidate, and only if its score exceeds one quarter
of the target size. Equal scores favor the more recently evicted base.

Git reloads that base from the local object database without fetching
missing objects. If that read fails, or the normal byte-level delta
matcher rejects the candidate, Git keeps the result of the normal
search. Fingerprint collisions can change which base Git tries, but
cannot cause it to copy mismatched bytes.

== Cost and compatibility

Hints cost a fingerprint pass over eligible evicted blobs, plus a
possible base reread. The retained fingerprints and one temporary
fingerprint set use at most about 1.1 MiB per worker on a typical 64-bit
build. This does not include rereading a base or building its delta
index. Rereading a packed base may require reconstructing an on-disk
delta chain larger than the base itself.
For that reason Git skips hints when a nonzero window-memory limit
is set. Hints are off by default; see `pack.pathWalkUseChunkHints`
in linkgit:git-config[1].

Hints only help choose a base. Git still writes an ordinary delta
against one base in the existing linkgit:gitformat-pack[5] format.
The reader does not need to know about the chunker or fingerprints.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1237,6 +1237,7 @@ LIB_OBJS += oidset.o
LIB_OBJS += oidtree.o
LIB_OBJS += pack-bitmap-write.o
LIB_OBJS += pack-bitmap.o
LIB_OBJS += pack-cdc.o
LIB_OBJS += pack-check.o
LIB_OBJS += pack-mtimes.o
LIB_OBJS += pack-objects.o
Expand Down
3 changes: 2 additions & 1 deletion builtin/fast-import.c
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,8 @@ static void *gfi_unpack_entry(
*/
p->pack_size = pack_size + the_hash_algo->rawsz;
}
data = unpack_entry(the_repository, p, oe->idx.offset, &type, &size_st);
data = unpack_entry(the_repository, p, oe->idx.offset, &type, &size_st,
0, NULL);
if (sizep)
*sizep = cast_size_t_to_ulong(size_st);
return data;
Expand Down
Loading
Loading