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

Reduce Rust Wasm Module Size By 85% (wasm-snip) #898

Merged
merged 1 commit into from
Jun 3, 2022

Conversation

dOrgJelli
Copy link
Contributor

@dOrgJelli dOrgJelli commented Jun 3, 2022

closes: #896

After going through the rust documentation here:
https://rustwasm.github.io/book/reference/code-size.html

I instrumented the wasm modules, and found out that ~85% of the code was "dead" and unreachable (thank you twiggy). I then used another tool the guide recommended, wasm-snip, and boom our module size shrank tremendously!

name old wasm-rs wasm-rs wasm-as
simple-storage m=1.7mb; q=1.5mb; m=282kb; q=136kb; m=86kb; q=49kb;
object-types 1.5mb 135kb 53kb

The "dead code" in question was:

> ~/.../wasm-rs/simple-storage$ twiggy garbage ./build/mutation.wasm 
 Bytes   │ Size % │ Garbage Item
─────────┼────────┼──────────────────────────────────────────────────────────
  617852 ┊ 36.18% ┊ custom section '.debug_str'
  392794 ┊ 23.00% ┊ custom section '.debug_info'
  224924 ┊ 13.17% ┊ custom section '.debug_pubnames'
  161184 ┊  9.44% ┊ custom section '.debug_ranges'
   12627 ┊  0.74% ┊ custom section '.debug_line'
    5406 ┊  0.32% ┊ custom section '.debug_abbrev'
     540 ┊  0.03% ┊ custom section '.debug_pubtypes'
      75 ┊  0.00% ┊ custom section 'producers'
      14 ┊  0.00% ┊ import env::memory
      12 ┊  0.00% ┊ type[21]: (i32, i32, i32, i32, i32, i32, i32, i32) -> i32
 1415428 ┊ 82.88% ┊ Σ [10 Total Rows]
   33556 ┊  1.96% ┊ 1 potential false-positive data segments

@nerfZael
Copy link
Contributor

nerfZael commented Jun 3, 2022

Insane!

@dOrgJelli dOrgJelli merged commit 67b119b into prealpha-dev Jun 3, 2022
@dOrgJelli dOrgJelli deleted the wasm-snip-reduce-size-rust branch February 2, 2023 15:42
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