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

Replace GZIP compression with Brotli #22

Merged
merged 1 commit into from
Aug 6, 2022

Conversation

daxpedda
Copy link
Contributor

@daxpedda daxpedda commented Aug 6, 2022

Follow-up on #15. This replaces the GZIP compression with Brotli. This shouldn't be a problem as all browsers support Brotli nowadays, see https://caniuse.com/brotli.

My WASM files are now consistently about a third smaller.

@@ -44,7 +44,7 @@ pub async fn run_server(options: Options, output: WasmBindgenOutput) -> Result<(
let serve_dir = get_service(ServeDir::new(".")).handle_error(internal_server_error);

let serve_wasm = || async move {
(TypedHeader(ContentEncoding::gzip()), WithContentType("application/wasm", compressed_wasm))
([("content-encoding", "br")], WithContentType("application/wasm", compressed_wasm))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a bit unfortunate, see hyperium/headers#116.

@jakobhellermann jakobhellermann merged commit 2f0bbec into jakobhellermann:main Aug 6, 2022
@jakobhellermann
Copy link
Owner

I noticed that with a large wasm file compression was taking a lot of time (~50s) so I looked at the brotli docs and it seems like the default compression level is 11.
I compiled a list of algorithm/level/size/speed combinations:

brotli [ 0] 21.76mb -> 8.53mb in 0.50
brotli [ 1] 21.76mb -> 8.17mb in 0.51
brotli [ 2] 21.76mb -> 5.23mb in 0.42
brotli [ 3] 21.76mb -> 4.88mb in 0.44
brotli [ 4] 21.76mb -> 4.53mb in 0.64
brotli [ 5] 21.76mb -> 4.60mb in 0.84
brotli [ 6] 21.76mb -> 4.53mb in 1.10
brotli [ 7] 21.76mb -> 4.36mb in 1.16
brotli [ 8] 21.76mb -> 4.35mb in 1.68
brotli [ 9] 21.76mb -> 3.56mb in 2.35
brotli [10] 21.76mb -> 3.20mb in 24.88
brotli [11] 21.76mb -> 3.08mb in 51.56
gzip  [ 0] 21.76mb -> 21.76mb in 0.32
gzip  [ 1] 21.76mb -> 6.87mb in 0.17
gzip  [ 2] 21.76mb -> 5.88mb in 0.25
gzip  [ 3] 21.76mb -> 5.51mb in 0.37
gzip  [ 4] 21.76mb -> 5.40mb in 0.40
gzip  [ 5] 21.76mb -> 5.34mb in 0.49
gzip  [ 6] 21.76mb -> 5.27mb in 0.83
gzip  [ 7] 21.76mb -> 5.25mb in 1.07
gzip  [ 8] 21.76mb -> 5.24mb in 1.29
gzip  [ 9] 21.76mb -> 5.24mb in 1.36

Looks like brotli definitely is the better option, but a compression level of 5 may be the best trade off.

@daxpedda
Copy link
Contributor Author

daxpedda commented Sep 3, 2022

50 sec is incredibly long ... LGTM.

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.

2 participants