perf(collect): stop buffering every response body just to count bytes - #174
Open
JonasJesus42 wants to merge 1 commit into
Open
perf(collect): stop buffering every response body just to count bytes#174JonasJesus42 wants to merge 1 commit into
JonasJesus42 wants to merge 1 commit into
Conversation
responseToEntry() called safeBodySize() → resp.body() for EVERY response of every page, purely to measure byteLength — even though content-length was already parsed as the fallback. resp.body() forces Chromium to materialize the entire body (images, fonts, video) and copy it into the Node heap. Across up to 4 concurrent contexts on image-heavy commerce pages this was a major RSS driver contributing to OOM (exit 137). Prefer the content-length header; only fall back to resp.body() for small text resources (document/script/xhr/fetch) when the header is absent. Never buffer binary assets to count bytes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Problem
responseToEntry()insrc/engine/collect.tscalledsafeBodySize()→resp.body()for every response of every page, just to recordbyteLengthfor the network waterfall — even thoughcontent-lengthwas already parsed as the fallback.resp.body()forces Chromium to materialize the entire response body (images, fonts, video, …) and copy it into the Node heap. Done for every request, on every page, across up to 4 concurrentBrowserContexts on image-heavy commerce pages, this was one of the largest drivers of resident memory — contributing to the OOM pressure that SIGKILLs sibling processes (exit 137).Fix
content-lengthheader (which is what a byte waterfall wants anyway — transfer size).resp.body()for small text resources (document/script/xhr/fetch) and only when the header is absent.image/media/font/stylesheet) just to count bytes.Also a speed win: far less body I/O per page.
Verification
bun run check(tsc) passes.Part of the memory-pressure / OOM series (see #173).
🤖 Generated with Claude Code
Summary by cubic
Stop buffering response bodies in
collectto compute transfer size. We now usecontent-lengthwhen present and only read bodies for small text responses, cutting memory use and speeding up runs.content-lengthinresponseToEntry()for waterfall transfer size.document/script/xhr/fetch); skip binary assets.isSmallTextResource()to gate the fallback.Written for commit a27cd91. Summary will update on new commits.