packfile.DeltaSelector has no memory bound for large objects (no pack.windowMemory / core.bigFileThreshold equivalent)
Los mantenedores suelen responder en 3 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 39/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- git, go
- Área
- backend, performance
Línea de trabajo
Start with plumbing/format/packfile/delta_selector.go and diff_delta.go, then trace how Encoder.Encode uses DeltaSelector and how objects are read and compared. The issue proposes byte limits for delta search and lazy undeltifying; review those approaches against the current selector and encoder options. Done means large-object encoding respects bounded memory while existing delta selection still works.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
go-git version: v6.0.0-beta.1. delta_selector.go and diff_delta.go are identical on main at 9decb13c (2026-11-06).
What happens
When Encoder.Encode(hashes, 10) runs over large blobs (for example, the versions of a big file), memory grows with the total size of the objects, not with any bound. Git bounds the same work with pack.windowMemory, and skips delta search entirely above core.bigFileThreshold. go-git has neither.
Why
- Every object is read up front and kept.
objectsToPackreads every input up front (delta_selector.go#L95-L129). Fromstorage/filesystem, a loose object belowLargeObjectThresholdcomes back as a wholeMemoryObject, and it stays asObject/Originalfor the rest of the encode. - Undeltifying keeps a whole copy.
undeltify→restoreOriginal(L215-L244) handles a reused delta whose base is not in the set, or one that is on a cycle. It replaces the delta withEncodedObject(h), which is a wholeMemoryObjectfor a packed delta, and keeps that copy until the encode ends. - The window is a count, not bytes.
walk(L250-L299) keeps adeltaIndexinindexMapfor each of up topackWindowbases. Each index is proportional to its base: oneintper 16-byte block, plus the table (delta_index.go#L10-L22).- Only delta targets drop
Originalwhen they leave the window (L263-L266).
- Each comparison reads both objects whole.
getDelta(diff_delta.go#L33-L75) reads base and target whole into pooledbytes.Buffers throughReadFrom. That grows each buffer to about twice its object, and the buffer goes back to the pool at that size.
Reproduction (public API only)
st := filesystem.NewStorage(osfs.New(t.TempDir()), cache.NewObjectLRUDefault())
rnd := rand.New(rand.NewSource(1))
// 32 append-only versions, 64 KiB .. 2 MiB (about 33 MiB raw), stored loose.
var v []byte
var hs []plumbing.Hash
for i := 0; i < 32; i++ {
chunk := make([]byte, 64<<10); rnd.Read(chunk)
v = append(v, chunk...)
o := st.NewEncodedObject(); o.SetType(plumbing.BlobObject)
w, _ := o.Writer(); w.Write(v); w.Close()
h, _ := st.SetEncodedObject(o); hs = append(hs, h)
}
otp, _ := packfile.NewDeltaSelector(st).ObjectsToPack(hs, 10)
// Live heap after GC, with otp still referenced: about 37 MiB (every version, whole).
// Peak during the call (sampling MemStats every ms): about 100 MiB, 3x the raw size.
What we observed in our application
Consolidating 32 packs, each holding one version of a document (0.5 to 16 MiB, 264 MiB raw):
ObjectsToPack(hashes, 10)alone grew the process by +476 MiB;- the whole encode grew it by +472 to +483 MiB.
Suggested fix
Bound the selector by bytes, as git does:
- A window-memory limit. Stop comparing a target once the bases compared sum to W bytes, but always try at least one base.
- A size above which an object is never a delta base or target. Like
bigFileThreshold, this sets the worst pair. - Undeltify lazily. Keep a handle that rebuilds the object on each
Reader()call, instead of holding aMemoryObjectfor the whole encode. - Compare in exact-size buffers. Size the pair's buffers from the objects, instead of
ReadFrom-grown pooled buffers.
These could be exposed as DeltaSelector / EncoderOption settings.
Our workaround is a custom ObjectSelector through WithObjectSelector:
- objects up to 256 KiB go to
DeltaSelectorunchanged; - larger ones are read as stored, never held whole;
- their stored deltas are reused, with a
visitingguard; - new deltas are searched one pair at a time with the exported
DiffDelta, in reused exact-size buffers, withDmax=W= 16 MiB.
The same consolidation then grew by +115 MiB. The pack was 15.15 MiB instead of 8.45 MiB, because the versions above Dmax stay whole.
Happy to send a PR if the approach is welcome.
Found while working on peircelabs/commens#1852.
- Lenguaje dominante
- Go
- Estrellas
- 7.9k
- Forks
- 1.1k
- Merge medio
- 4 d 19 h
- PR fusionados (30 d)
- 34
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de go-git/go-git
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 92/100
Los mantenedores suelen responder en 3 días
-
plumbing: ReferenceName.Short() is slow (5× fmt.Sscanf per call, panic/recover on mismatch)Posiblemente ocupada @blakepettersson la tomó hace 11 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Los mantenedores suelen responder en 3 días
-
storage/filesystem: EncodedObjectSize leaks the loose object file handleQuizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
Los mantenedores suelen responder en 3 días
-
`GO_GIT_USER_AGENT_EXTRA` puts a space in the `agent` capabilityPosiblemente ocupada @BoxBoxJason la tomó hace 54 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 3 días
-
Worktree checkout rejects Windows reserved device names (e.g. prn.sh) on Linux/macOS — regression since v5.19.1Posiblemente ocupada @SomSamantray la tomó hace 102 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
go-git/go-git#2322 · 5 comentarios ·
Los mantenedores suelen responder en 3 días
Todos los issues de go-git/go-git
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
alibaba/MongoShake#1077 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
mattermost/mattermost-plugin-jira#1397 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
Add Free CS Systems Workshops, Starter Scaffolds & Zero-Dependency Verification CLI to CS SeriesAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
-
documentation linkinator-failure
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100