Honor backpressure during ZIP finalization - #227
Draft
jeff-an wants to merge 1 commit into
Draft
Conversation
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.
[written by Codex]
Problem
ZIP finalization writes every central-directory field synchronously without honoring
write()backpressure. Large archives can therefore enqueue hundreds of thousands of tiny buffers at once and exhaust memory, as reported in #121.Solution
write()returnsfalseand resume from the next entry ondrain._finish()return an unobserved promise, and release retained entries as their headers are emitted.PR #92 identified the right backpressure signal, but its async
_finish()completion is not observed by callers and it still retains every entry and writes every header field separately. This implementation keeps the existing public API and storage contract.Result
The benchmark below uses 50,000 empty stored entries, switches a
highWaterMark: 1sink to asynchronous writes immediately beforefinish(), samples RSS every millisecond, and runs each revision in three fresh Node.js processes. Values are medians on macOS with Node.js v22.13.1.28f1a73)8635e95)Reproduce the benchmark
Save this as
benchmark.mjs, then run it against clean checkouts of the base and this branch:Tests
npm test(43 passing,20 pending)unzip -t.Compatibility
The patch does not add filesystem I/O or change the public API. Entry metadata remains retained until finalization begins to preserve existing behavior, then is released incrementally as central headers are written.
Fixes #121