Repository navigation
Decompress each chunk once in the response leak scan - #1306
Merged
Merged
Conversation
The patched ServerResponse re-decompressed every compressed chunk seen so far on each write, so scan cost grew with the square of the response size. Keep one decompressor per response and feed it one chunk at a time by driving the stream's native handle (node and bun both expose it). Falls back to the old path when those internals are missing. Approach proposed by @andreastande in #1305. Fixes #1305 Co-authored-by: andreastande <114910149+andreastande@users.noreply.github.com>
Contributor
|
The changes in this PR will be included in the next version bump.
|
Contributor
📦 Bundle size
dist/ only; native binaries are versioned separately and not counted here. |
commit: |
Contributor
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes: Reviewed the incremental compressed-response leak scanner and its release entry.
- Incremental decompression: Reuses a native decompressor per response instead of replaying all prior compressed chunks.
- Scanning and compatibility: Preserves streaming UTF-8 decoding and cross-chunk detection, with the previous decompression path available when internals are missing.
- Release entry: Marks the performance improvement for a
varlockpatch release.
All 70 focused tests passed on Node and Bun. The concatenated-gzip limitation mentioned in the description did not reproduce on Node 24.22.1 or Bun 1.4.2, including member-aligned and byte-at-a-time chunks.
gpt-6.1-sol | 𝕏
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.



Fixes #1305. Approach and diagnosis by @andreastande, thanks!
The patched
ServerResponsepushed each compressed chunk ontozlibChunksand re-decompressed the whole buffer on every write, so the scan was quadratic in response size. Streaming SSR (e.g. Next.js with compression, which flushes after every rendered chunk) hit this hard.Now each response gets one decompressor that is fed a chunk at a time. Node's public sync zlib API closes the stream after each call, so this drives the stream's native handle directly (
_handle.writeSync/_writeState/_chunkSize, the same loop as node'sprocessChunkSyncminus the close). If those internals are missing, it falls back to the previous whole-buffer path. A stream that fails to decode stops being scanned (fails open, as before).Verified:
patch-server-responsetests pass on both the incremental and the forced-fallback pathKnown gap: concatenated gzip members in one response only get the first member scanned (raw handle doesn't reset between members).