Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gateway): support zstd-stream #2400

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

feat(gateway): support zstd-stream #2400

wants to merge 2 commits into from

Conversation

vilgotf
Copy link
Member

@vilgotf vilgotf commented Dec 27, 2024

Adds support for zstd-stream1 transport compression using Facebook's reference implementation (written in C) and deprecates our zlib-stream support.

I did not run into any build dependency issues on macOS, Linux, or Windows as Zstd-safe seems to statically link against Zstd. Otherwise there is a pure Rust implementation of Zstandard called ruzstd which we may eventually switch to.

This PR deprecates the zlib-stock and zlib-simd features since they are replaced by the zstd feature. While doing this, I opted to not expose the previous Inflater type and its processed and produced properties as those are not tracked by Zstd itself.

Edit: more radically, should we unconditionally use Zstd transport compression? It's like an implementation detail (or a foot gun).
Update: no, transport compression is bad for shards behind a Gateway proxy.

Footnotes

  1. https://discord.com/blog/how-discord-reduced-websocket-traffic-by-40-percent

@vilgotf vilgotf added t-feature Addition of a new feature c-gateway Affects the gateway crate labels Dec 27, 2024
@github-actions github-actions bot added c-book Affects the book m-breaking change Breaks the public API. labels Dec 27, 2024
@Erk-
Copy link
Member

Erk- commented Jan 2, 2025

more radically, should we unconditionally use Zstd transport compression? It's like an implementation detail (or a foot gun).

It was how we used to do it, but we had multiple people ask for ways to disable it thus we made it optional in #700.

Copy link
Member

@Erk- Erk- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple small comments

twilight-gateway/src/inflater.rs Outdated Show resolved Hide resolved
twilight-gateway/src/inflater.rs Outdated Show resolved Hide resolved
@vilgotf vilgotf force-pushed the vilgotf/zstd branch 2 times, most recently from 2d33124 to 444a108 Compare January 31, 2025 17:29
@vilgotf vilgotf requested a review from Erk- January 31, 2025 17:29
@vilgotf vilgotf changed the title feat(gateway)!: support Zstd transport compression feat(gateway): support zstd-stream Jan 31, 2025
@vilgotf vilgotf force-pushed the vilgotf/zstd branch 3 times, most recently from 57edeaa to 6bd7057 Compare January 31, 2025 17:51
Copy link
Member

@Erk- Erk- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just a couple small documentation changes

twilight-gateway/src/compression.rs Outdated Show resolved Hide resolved
Comment on lines +136 to +138
self.ctx
.reset(zstd_safe::ResetDirective::SessionOnly)
.expect("resetting session is infallible");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is good for now, but if we see memory grows over time or something we should switch it to just recreating the ctx.

book/src/chapter_1_crates/section_3_gateway.md Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c-book Affects the book c-gateway Affects the gateway crate m-breaking change Breaks the public API. t-feature Addition of a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants