perf: reduce memory spikes under load for git and npm handlers#38
Merged
Conversation
Member
wolfeidau
commented
Feb 21, 2026
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.