Repository navigation
Conversation
The client bundle served by the Node.js HTTP server was compressed on every request. With brotli at its default quality (11), that costs about 60 ms of CPU for socket.io.min.js and 200 ms for socket.io.js per request, in the libuv threadpool. The compressed content is now computed on the first request and kept in memory, keyed by file and encoding. The response bytes are unchanged.
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.
The kind of change this PR does introduce
Current behavior
With
serveClient: true(the default), the Node.js HTTP server compresses the client bundle again for every request (<script src="/socket.io/socket.io.js">). Brotli runs at its default quality (11), which takes about 60 ms of CPU forsocket.io.min.jsand about 200 ms forsocket.io.js, per request, in the libuv threadpool.New behavior
The compressed content is computed on the first request for a given file and encoding, then kept in memory (a few hundred KB at most for all the files). The bytes sent are the same as before (same size, same sha256 for the br response). Uncompressed responses still stream from disk, and the uWebSockets.js path is untouched.
A failed read or compression is not cached, so the next request tries again.
Numbers: 100 (or 40, 200) requests, 4 in flight, client and server in the same Node.js process, base and patched alternated 5 times each, median shown. Windows 11, i7-9700, Node.js 24.15.0.
socket.io.min.js, brsocket.io.js, brsocket.io.js, gzipsocket.io.js, no compressionThe new test checks that two consecutive br responses both decode to the file in
client-dist/.Other information (e.g. related issues)
The benchmark script is just an HTTP client loop against
new Server(httpServer); I can add it somewhere if useful.