Skip to content

[perf] Share zlib streams when context takeover is disabled - #2342

Closed
Ryan6578 wants to merge 1 commit into
websockets:masterfrom
Ryan6578:perf/share-zlib-streams
Closed

Ryan6578 wants to merge 1 commit into
websockets:masterfrom
Ryan6578:perf/share-zlib-streams

Conversation

@Ryan6578

@Ryan6578 Ryan6578 commented Oct 9, 2026

Copy link
Copy Markdown

When context takeover is disabled, a zlib stream is reset after each message and carries nothing over to the next one. Instead of keeping its deflate and inflate streams for its whole lifetime, a connection now takes a stream from a pool when a message starts and returns it after the last fragment. Pools are keyed by the zlib{Deflate,Inflate}Options objects and the window size, and hold at most concurrencyLimit streams.

With 1,000 connections that each sent and received one compressed message, the memory used per connection on the server dropped from about 267 KiB to about 31 KiB. The compressed output does not change.

When context takeover is disabled, a zlib stream is reset after each message
and carries nothing over to the next one. Instead of keeping its deflate and
inflate streams for its whole lifetime, a connection now takes a stream from a
pool when a message starts and returns it after the last fragment. Pools are
keyed by the `zlib{Deflate,Inflate}Options` objects and the window size, and
hold at most `concurrencyLimit` streams.

With 1,000 connections that each sent and received one compressed message, the
memory used per connection on the server dropped from about 267 KiB to about
31 KiB. The compressed output does not change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Ryan6578 Ryan6578 closed this Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant