Repository navigation
perf(websocket): decompress each permessage-deflate frame with one zlib write - #6192
Closed
deadstrobe5 wants to merge 1 commit into
Closed
deadstrobe5 wants to merge 1 commit into
deadstrobe5 wants to merge 1 commit into
Conversation
…ib write Signed-off-by: deadstrobe5 <afonso.diamantino2@gmail.com>
Member
|
I don't want to copy the entire data just to append a 4-byte TRAILER. |
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.
Rationale
PerMessageDeflate.decompress()made three calls into the inflate stream per frame:write(payload),write(tail)andflush(). Each one is a separate trip to the libuv thread pool, and the receiver waits for the last one before it parses the next frame, so a small compressed message cost about 55 us of CPU and 150 us of wall time on the client.The inflate stream is now created with
flush: Z_SYNC_FLUSH, and each frame is a singlewrite(fin ? Buffer.concat([payload, tail]) : payload, cb). Because every write is a sync flush, all the output for the frame has been emitted by the time the write callback runs, the same guarantee the empty flush write gave. The data listener, themaxPayloadSizepath and the error handler are unchanged, and the callback returns early on an error or once the inflater has been dropped.Sequential
decompress()calls on one context, Node v24.22.2, median of 7 alternating rounds:A new test sends messages that share the deflate context, including a fragmented one whose first fragment holds no complete symbol, and checks that they arrive intact and in order. The WebSocket and permessage-deflate tests pass.
Status