Skip to content

perf: reduce memory spikes under load for git and npm handlers#38

Merged
wolfeidau merged 2 commits into
mainfrom
perf_reduce_memory_spikes
Feb 21, 2026
Merged

perf: reduce memory spikes under load for git and npm handlers#38
wolfeidau merged 2 commits into
mainfrom
perf_reduce_memory_spikes

Conversation

@wolfeidau
Copy link
Copy Markdown
Member

  • Stream git upload-pack request bodies to disk instead of io.ReadAll; for gzip-encoded requests decompress into a second temp file with a 500 MB cap, keeping heap use proportional to pack data not request size
  • Add FetchPackageMetadataDecoded to npm upstream; rewrite handleMetadata cache-miss path to decode once into a map, marshal once to []byte, and share that single allocation between the async cache write and the HTTP response (peak ~1.5× metadata size vs ~3× previously)
  • Add io.LimitReader guards to OCI FetchManifest (32 MB) and npm FetchPackageMetadataRaw (100 MB) to bound unbounded io.ReadAll calls

* Stream git upload-pack request bodies to disk instead of io.ReadAll; for gzip-encoded requests decompress into a second temp file with a 500 MB cap, keeping heap use proportional to pack data not request size
* Add FetchPackageMetadataDecoded to npm upstream; rewrite handleMetadata cache-miss path to decode once into a map, marshal once to []byte, and share that single allocation between the async cache write and the HTTP response (peak ~1.5× metadata size vs ~3× previously)
* Add io.LimitReader guards to OCI FetchManifest (32 MB) and npm FetchPackageMetadataRaw (100 MB) to bound unbounded io.ReadAll calls
* Fix file descriptor leak in git upload-pack: singleflight waiters now close their body temp file when the closure is not executed for them
* Fix silent truncation of oversized gzip request bodies: return 413 when the decompressed size hits the limit instead of forwarding a truncated body to upstream; add WithMaxDecompressedBodySize option
* Fix abbreviated metadata being written to cache: always cache the full URL-rewritten form and abbreviate only the HTTP response, so a full request following an abbreviated cache miss gets all fields
@wolfeidau wolfeidau merged commit a36166f into main Feb 21, 2026
1 check passed
@wolfeidau wolfeidau deleted the perf_reduce_memory_spikes branch February 21, 2026 10:12
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