Skip to content

Add Zstd compression to the websocket messages - #2846

Closed
ResuBaka wants to merge 2 commits into
clockworklabs:masterfrom
ResuBaka:zstd-websocket-compression
Closed

Add Zstd compression to the websocket messages#2846
ResuBaka wants to merge 2 commits into
clockworklabs:masterfrom
ResuBaka:zstd-websocket-compression

Conversation

@ResuBaka

@ResuBaka ResuBaka commented Jun 7, 2025

Copy link
Copy Markdown
Contributor

Description of Changes

This add the option to the websocket/subscribe endpoint so you can use Zstd as the compression in addition to None/Brotli/Gzip.

API and ABI breaking changes

None

Expected complexity level and risk

1

Testing

  • I have tested it with the simple chat example where I have enabled the zstd compression and added some logging to see if it was used
  • Testing for the compression speed to find the best level

Additional

What we could look into is to use zstd dictionary features to improve the performance even more as it could possible help with the base structure of each message. The only thing that would then needed to be done is have an extra option in the enum as an ZstdDict as the client and server would need to know about the dictionary.

@ResuBaka
ResuBaka requested review from Centril and gefjon as code owners June 7, 2025 10:03
@CLAassistant

CLAassistant commented Jun 7, 2025

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Comment thread crates/client-api-messages/src/websocket.rs Outdated
@gefjon

gefjon commented Jun 10, 2025

Copy link
Copy Markdown
Contributor

What's the motivation for this change? Is there some environment you want to connect to SpacetimeDB from where Zstd compression is available, but GZip and Brotli are not?

@ResuBaka

Copy link
Copy Markdown
Contributor Author

The motivation is that in Zstd should be in general be faster when it comes to decompression. So it should at the least be better for clients.

For server it could cause a small amount of more cpu usages.

So I wanted to add it to have one more options for compression, which could depending on how big responses are be better then the other options. But to check it there would be an benchmark be needed, to see how general the speed differs from each compression option.

Do you guys currently have an easy way to benchmark mixed message compression/decompression speed?

@bfops

bfops commented Oct 20, 2025

Copy link
Copy Markdown
Collaborator

Hey @ResuBaka, sorry for the delay here. We've had a lot going on.

I don't believe we have any benchmarks you could easily run to compare compression/decompression speeds. We did internally run manual benchmarks on several algos, including Zstd, brotli, and gzip, and came to the conclusion that Brotli and Gzip were best to balance server and client load. Part of the reason is that a small amount of increased server load becomes a big amount when the server is managing lots of clients.

Were you seeing issues with compression performance for your use case, or just trying to be prepared?

@cloutiertyler

Copy link
Copy Markdown
Contributor

Closing as stale since we haven't had any reply here.

@cloutiertyler cloutiertyler added the close-stale-pr-create-issue Indicates that the PR is substantially out of date, and should become an issue to reimplement. label Apr 13, 2026
@clockwork-labs-bot

Copy link
Copy Markdown
Contributor

Closing per the close-stale-pr-create-issue label. This work is now tracked in #4797 for reimplementation on a fresh branch.

Replacement issue: #4797

@paddor

paddor commented Aug 13, 2026

Copy link
Copy Markdown

Commenting here since there are actual humans here. Might be of interest: zrip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

close-stale-pr-create-issue Indicates that the PR is substantially out of date, and should become an issue to reimplement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants