Skip to content

wasm: reduce wasm output size by 30% - #3

Draft
vicb wants to merge 1 commit into
jbrun3t:devfrom
vicb:vicb/size
Draft

vicb wants to merge 1 commit into
jbrun3t:devfrom
vicb:vicb/size

Conversation

@vicb

@vicb vicb commented Aug 28, 2026

Copy link
Copy Markdown

from 330 to 240kB

Note:

opt-level = "z" might have a negative impact on the perf for the rust lib.

Things we can do:

  • generate 2 different WASM outputs, one optimized for speed and the other optimized for size when it matters
  • always optimize rust for speed and wasm for size

I can amend the PR with one or the other, let me know!

@jbrun3t
jbrun3t force-pushed the dev branch 2 times, most recently from 8b28793 to c8f6b19 Compare August 28, 2026 15:43
Comment thread Cargo.toml
codegen-units = 1
codegen-units = 1 # Allows LLVM to perform cross-module inlining and optimizations
opt-level = "z" # Optimize aggressively for binary size
lto = true # Link-Time Optimization for cross-crate dead code elimination

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

+1

Comment thread Cargo.toml
opt-level = "z" # Optimize aggressively for binary size
lto = true # Link-Time Optimization for cross-crate dead code elimination
panic = "abort" # Strips unwinding/landing pads (saves ~10-20% size; does not affect Result/JsError)
strip = true # Strip debug symbols from the binary

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

this is fine too

Comment thread Cargo.toml
codegen-units = 1 # Allows LLVM to perform cross-module inlining and optimizations
opt-level = "z" # Optimize aggressively for binary size
lto = true # Link-Time Optimization for cross-crate dead code elimination
panic = "abort" # Strips unwinding/landing pads (saves ~10-20% size; does not affect Result/JsError)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This I need to check the overall impact on the rust / non wasm binding module

Comment thread Cargo.toml
[profile.release]
codegen-units = 1
codegen-units = 1 # Allows LLVM to perform cross-module inlining and optimizations
opt-level = "z" # Optimize aggressively for binary size

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Um no, not at the root configuration at least.
I understand size is important for wasm but this impact the rest too
In general, It would be nice to run the bench before and after to see the impact.
I've spend quite a long time optimizing for speed and it is more fragile that it looks.

@jbrun3t

jbrun3t commented Aug 28, 2026

Copy link
Copy Markdown
Owner

Note that compressing the wasm with brotli -q11 yields an even bigger gain (340kB -> 110kB) without touching the optimization flags. That should probably come in first since this making no compromise on speed either (beside the added decompression of 110kB - that probably deserve a bench)

If you don't mind resubmitting the release profile change that are making not making any compromise between speed and size, I'd be happy to take this for a start.

When it comes, to wasm, I think having different release mode is probably the way to go, though I have no idea how web guys would handle that on things like npm ?

@jbrun3t

jbrun3t commented Aug 28, 2026

Copy link
Copy Markdown
Owner

I wonder if python test failing comes from one of the options, like the panic one maybe 🤔 ?

@vicb
vicb marked this pull request as draft August 31, 2026 07:10
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