Skip to content

Conversation

@bigsaltyfishes
Copy link

@bigsaltyfishes bigsaltyfishes commented Jun 7, 2025

This is an attempt to add compression support for wasm binary.

  • Add data-compression-algorithm and data-compression-level attributes.
  • Enable gzip compression by default on release build, can be disabled by set data-compression-level="0".
  • Use DecompressionStream API to decompress at runtime.

* Add data-gzip-compression attribute.
* Enable compression by default on release build.
* Use DecompressionStream API to decompress at runtime.

Signed-off-by: bigsaltyfishes <bigsaltyfishes@gmail.com>
* Remove `data-gzip-compression` attribute.
* Add `data-compression-algorithm` and `data-compression-level` attributes.
* Add support for zlib(deflate) and deflate(deflate-raw) algorithm.

Signed-off-by: bigsaltyfishes <bigsaltyfishes@gmail.com>
@bigsaltyfishes bigsaltyfishes changed the title feat: Add Gzip compress support for wasm binary feat: Add compression support for wasm binary Jun 7, 2025
Signed-off-by: bigsaltyfishes <bigsaltyfishes@gmail.com>
@ctron
Copy link
Collaborator

ctron commented Jun 10, 2025

Thanks for the PR. I guess this could be a valuable addition. There are two things:

  • I think it would make sense doing a quick check/proof on how much this would safe. Showing one or two examples.
  • It looks like this is missing out on the else when using the more complex initializer. It also seems to repeat code from the initializer, which does something similar. Maybe it's time to collapse both, and have the "non initializer" version be a special (simpler) form of the initializer version?

Signed-off-by: bigsaltyfishes <bigsaltyfishes@gmail.com>
Signed-off-by: bigsaltyfishes <bigsaltyfishes@gmail.com>
Signed-off-by: bigsaltyfishes <bigsaltyfishes@gmail.com>
@bigsaltyfishes bigsaltyfishes force-pushed the feat/gzip branch 2 times, most recently from a42dc04 to 80bc851 Compare June 10, 2025 09:45
…ure `init_with_object`

Signed-off-by: bigsaltyfishes <bigsaltyfishes@gmail.com>
@bigsaltyfishes
Copy link
Author

bigsaltyfishes commented Jun 10, 2025

Thanks for the PR. I guess this could be a valuable addition. There are two things:

  • I think it would make sense doing a quick check/proof on how much this would safe. Showing one or two examples.
  • It looks like this is missing out on the else when using the more complex initializer. It also seems to repeat code from the initializer, which does something similar. Maybe it's time to collapse both, and have the "non initializer" version be a special (simpler) form of the initializer version?

I've merged repeat code and add missing compression support for custom initializer. Here are the file size savings with compression enabled. All examples were built with the release profile. By default, gzip compression is enabled with the default compression level:

Example Raw wasm-opt processed (opt-level='z') Compressed
initializer 35 KB 23 KB 11 KB
leptos 137 KB 93 KB 36 KB
yew 450 KB 307 KB 104 KB
My Blog (Leptos 0.8) 1349 KB 819 KB 330 KB

All examples save about 50% to 70% in size.

Signed-off-by: bigsaltyfishes <bigsaltyfishes@gmail.com>
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