#11916·dolt

GitBlobstore: every ranged read re-inflates the git object from byte 0 — pulls from git remotes are O(reads × part size) (40 min → 2 min with an OID cache)

Author: albusshinCreated Sep 22, 2026Updated Sep 29, 2026
Labelsbugperformancegood reprocustomer issue

Summary

When a clone pulls from a git+ssh:// remote and has to fetch chunks that live in a large table file, the pull takes time proportional to (number of ranged reads) × (part size), not the size of the data. The cause is GitBlobstore's read path: every ranged Get re-streams and re-inflates the git object from byte 0.

We hit this through beads (bd v1.2.2, which embeds dolt/go v0.40.5-0.20260605230755-1bf533220ab0). The same code is still on main (checked against v2.3.5's tree).

Measurements

A clone that was one push behind had to fetch one table file: 56 MB, 37,453 chunks, stored on the remote as two part blobs (50 MiB and 3.9 MiB).

stock patched (below)
dolt pull wall time 40m12s (2,300 s user) 1m56s
git subprocesses spawned 127,753 518
git cat-file blob calls 36,092 on the same 50 MiB part (~1.8 TB inflated to fetch 56 MB) 249
git cat-file -s calls ~90k 256

Both runs reached the same head with identical content. Under a loaded host the stock pull took 1h43m. Any caller that bounds the pull with a timeout never finishes, because a killed pull keeps nothing. That livelocked three replicas for us.

Root cause (go/store/blobstore/git_blobstore.go)

  • Inline blobs: getFromCache → BlobSize (spawns git cat-file -s) + BlobReader (spawns git cat-file blob) → sliceInlineBlob, which discards bytes up to offset.
  • Chunked trees (objects > defaultGitBlobstoreMaxPartSize, 50 MiB): openChunkedTreeRange → validateAndSizeChunkedParts spawns git cat-file -s for every part on every read. Then multiPartReadCloser.openSliceReader spawns git cat-file blob and calls skipN(rc, s.offset), inflating up to 50 MiB to reach one chunk.

The puller issues many small ranged reads per table file, so this is effectively quadratic.

Suggested fix

Git objects are content-addressed and immutable, so caching by OID is always correct:

  1. Memoize blob sizes by OID.
  2. On the first ranged read of an OID, stream git cat-file blob once into a local file (e.g. <gitDir>/dolt-blob-cache/<oid>, written to a temp name and renamed), and serve later ranges with ReadAt/SectionReader. Full-object reads can keep streaming, and any cache error falls back to the current path.

We have this implemented and tested: -race, byte-identical output over 16 range shapes and 500 random reads, 64 concurrent readers sharing one materialization, a fallback when the cache dir is unusable, io.ErrUnexpectedEOF preserved on short parts, and stale-file pruning hooked into the existing periodic git gc. It's ~770 lines including tests, mostly a new git_blobstore_blobcache.go. We're happy to open a PR against main if this approach fits.

Side note: on the stock path, reading a ranged result past its declared length (e.g. io.ReadAll on the returned reader) can fail, because the git cat-file process is torn down mid-stream. Dolt's own callers read exact lengths, so pulls are unaffected, but it's a sharp edge for other callers.