SpacetimeDB icon indicating copy to clipboard operation
SpacetimeDB copied to clipboard

Provide option for gzip

Open cloutiertyler opened this issue 1 year ago • 9 comments

Puru:

Provide an option in WS API to send the response encoded in gzip via ?gzip or ?encoding=gzip

OR

Totally switch to gzip, which should be a non-breaking change(AFAIK).

From discord:

"Just outlining the general outline: If we wait for brotli in web, and it comes after 1 year, it'll take over 1 more to > spread across all the browsers(* cough * Safari firefox * cough *) and have > enuf usage as well(Like safari being tied to mac updates so it'll be the slowest to get). After that, it would take time for Node to get it as well, after which we gotta wait for us bumping our TS SDK's minimum node version to the one which supports DecompressionStream(brotli) So we're looking at 2-3 years from now at a minimum. Which means 100KB for our SDK for the said period of time

If we switch to gzip or provide it as an option, we can have a non-breaking > change in the JS SDK(which internally starts using DecompressionStream('gzip') widely supported). We can also do this as a breaking change while bumping up a minimum node version, pre-1.0. And the bundle size can go down very easily to 5-10KBs, which is really good to have. Sizes don't matter in the long run, but it does if people start complaining and this causes others to try to use HTTP API instead, which is a failure of the SDK.

Something to think about pre-1.0"

cloutiertyler avatar Jun 26 '24 19:06 cloutiertyler

Why wouldn't a total change to gzip be a breaking change?

cloutiertyler avatar Jun 26 '24 19:06 cloutiertyler

Isn’t gzip an implementation detail for the sdks? If so, it shouldn’t break anything

Unless people are manually using the binary version of ws api, in which case it would be breaking.

Further confirmation required from Phoebe/Mazdak

PuruVJ avatar Jun 26 '24 21:06 PuruVJ

Breaking in the sense that:

  • We will need to update the SDKs.
  • SDK users will need to update to a new SDK version.
  • Non-SDK users of the binary WebSocket API (afaik none exist) will have to change their code.

Not breaking in the sense that SDK users would need to change their code.

gefjon avatar Jun 26 '24 21:06 gefjon

Since Joshua has confirmed that GZip performs similarly to Brotli for our needs, assuming we can locate reliable Rust and C# (.NET and Unity) libraries for it, this seems like a totally reasonable and low-effort thing to do so long as we do it pre-1.0 so we don't break a stable API. I make no comment as to how high priority this should be.

gefjon avatar Jun 26 '24 21:06 gefjon

FWIW we considered this a while ago, and ended up deciding that we should first do https://github.com/clockworklabs/SpacetimeDB/issues/1080 before switching the compression algorithm, since we believe that that might address most of the performance issue.

(Edit: ah I didn't read the motivation that apparently web doesn't support brotli?)

bfops avatar Jul 09 '24 17:07 bfops

apparently web doesn't support brotli?

Manual brotli decompression isn't supported yet 😄

PuruVJ avatar Jul 09 '24 17:07 PuruVJ

Oops Cmd+Enter closed the issue

PuruVJ avatar Jul 09 '24 17:07 PuruVJ

We've decided to support both brotli and gzip, rather than replace.

joshua-spacetime avatar Jul 09 '24 18:07 joshua-spacetime

How are we planning to support this? Would this be a non-breaking change (e.g. just allow you to provide an option and use Brotli by default) or change the default or require that you specify which compression scheme you want.

cloutiertyler avatar Aug 19 '24 19:08 cloutiertyler

PR: https://github.com/clockworklabs/SpacetimeDB/pull/1802

cloutiertyler avatar Oct 07 '24 20:10 cloutiertyler