packfile.Parser (not low-memory, with a storage) keeps every delta's buffer after writing it to storage — intended?
Mantenedores costumam responder em até 3 dias
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 55/100
- Tipo de issue
- Bug
- Clareza
- Claramente especificada
- Status de atividade
- Ativa
- Stack de tecnologia
- go
- Domínio
- backend, performance
Direção de pesquisa
Start with plumbing/format/packfile/parser.go, especially storeOrCache, parentReader, and the storage capability checks; then read parser_options.go for WithHighMemoryMode. Reproduce the reported memory growth with a file-backed storer and a delta chain, and inspect existing packfile parser tests. Done means the chosen buffer behavior is verified for both high- and low-memory modes without breaking delta resolution.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
go-git version: v6.0.0-beta.1. Unchanged on main at 9decb13c (2026-11-06).
This may be expected behaviour. We're asking because what the parser keeps does not seem to serve as a cache.
What happens
When a Parser has a storage and is not in low-memory mode, it still holds about the raw size of every resolved delta and base until Parse returns. This holds even though it has written every delta to the storage. That is the case for packfile.UpdateObjectStorage with a storer that is not a PackfileWriter (e.g. memory.Storage), or for any storer that is not LowMemoryCapable.
Why
storeOrCache (parser.go#L130-L166; main L132-L168) works like this:
- It copies the resolved delta to storage with
ioutil.CopyBufferPool(w, oh.content).oh.contentis abytes.Buffer, soio.CopyBufferuses itsWriteTo, which drains it: length 0, capacity kept. - Outside low-memory mode it does not release the buffer, so
p.cache.Add(oh)keeps that capacity. - When a child of
ohis resolved,parentReaderfindsparent.content.Len() == 0(parser.go#L473). It reads the object back from storage into the same buffer (L481-L496), and the buffer then stays full until the parse ends.
So the parser holds a cache-sized amount of memory, but every child's base is still fetched from storage.
WithHighMemoryMode documents that delta contents are cached (parser_options.go#L50-L59), so keeping them may be intended. The drain seems not to be.
Possibly related: WithHighMemoryMode sets p.lowMemoryMode = false in the options loop, and NewParser then overwrites the field from the storage's LowMemoryMode() (parser.go#L99-L119). The option therefore looks like a no-op. We may be misreading it.
Reproduction (public API only)
- Build a ~2 MiB pack of 32 versions of a 2 MiB blob, as a delta chain (
memory.Storage+packfile.NewEncoder(...).Encode(hashes, 10)). - Parse it with
packfile.WithStorage(s).sis anEncodedObjectStorerthat appendsRawObjectWriteroutput to a temp file and servesEncodedObjectfrom there, so the storer itself holds nothing in memory. - Add an
ObserverwhoseOnInflatedObjectContentrunsruntime.GC()and readsMemStats.HeapAllocat the last object.
s |
Live heap at the last object |
|---|---|
no LowMemoryMode method |
64 MiB (126 MiB if its readers are not io.WriterTo; that part is a separate issue) |
LowMemoryMode() == true |
0 MiB |
What we observed in our application
We index packs through a file-backed storage. When it declines low-memory mode, indexing a chain of 32 × 2 MiB versions grows the process by +64 MiB, against +6 to +9 MiB in low-memory mode.
Question / suggested fix
If the intent is a cache, one option is to copy to storage without draining, e.g. CopyBufferPool(w, bytes.NewReader(oh.content.Bytes())), so the cached bytes actually serve the children.
If the storage is meant to be the source of truth, the other option is to release oh.content after the copy, as low-memory mode does.
With the second option, memory.Storage users would also stop holding each delta twice. We're happy to send a PR for whichever you prefer.
Found while working on peircelabs/commens#1852.
- Linguagem predominante
- Go
- Estrelas
- 7.9k
- Forks
- 1.1k
- Merge médio
- 4d 19h
- PRs com merge (30d)
- 34
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de go-git/go-git
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 92/100
Mantenedores costumam responder em até 3 dias
-
plumbing: ReferenceName.Short() is slow (5× fmt.Sscanf per call, panic/recover on mismatch)Talvez já em andamento @blakepettersson assumiu há 11 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
Mantenedores costumam responder em até 3 dias
-
storage/filesystem: EncodedObjectSize leaks the loose object file handleTalvez livre de novo Um pull request para esta issue foi fechado sem ser mesclado. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100
Mantenedores costumam responder em até 3 dias
-
`GO_GIT_USER_AGENT_EXTRA` puts a space in the `agent` capabilityTalvez já em andamento @BoxBoxJason assumiu há 54 dias. Abertabug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
Mantenedores costumam responder em até 3 dias
-
Worktree checkout rejects Windows reserved device names (e.g. prn.sh) on Linux/macOS — regression since v5.19.1Talvez já em andamento @SomSamantray assumiu há 102 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
go-git/go-git#2322 · 5 comentários ·
Mantenedores costumam responder em até 3 dias
Todas as issues de go-git/go-git
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
alibaba/MongoShake#1077 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
mattermost/mattermost-plugin-jira#1397 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
Mantenedores costumam responder em até 1 dia
-
Add Free CS Systems Workshops, Starter Scaffolds & Zero-Dependency Verification CLI to CS SeriesAberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
-
documentation linkinator-failure
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 66/100