project-mahiwa / mahiwa-frontend-go

mahiwaのGo言語向けフロントエンド
https://pkg.go.dev/github.com/project-mahiwa/mahiwa-frontend-go
MIT License
0 stars 0 forks source link

[✨Feature]:wabtの最適化の挙動を見る #12

Closed usuyuki closed 1 year ago

usuyuki commented 1 year ago

✨ 概要

wabtで最適化してサイズやメモリ使用量削減できないかを見てみる

なぜ必要

備考

https://github.com/wasm3/wasm3-arduino/blob/main/examples_pio/Wasm_Advanced/wasm_apps/tinygo/build.sh

usuyuki commented 1 year ago

no-text-wasi.wasm 81779byte

wasm-opt -Oz使用後 no-text-wasi-oz.wasm 72552byte

Ozはsuper-focusing on code sizeなので一番サイズ小さくなる.

wasm-strip 使用後 no-text-wasi-oz-strip.wasm 12660byte←!?

当たり前だがメモリの使用量は変わらない.(O4のように変更しても)

usuyuki commented 1 year ago
wasm-opt --help
Optimization options:
---------------------

   -O                                           execute default optimization 
                                                passes (equivalent to -Os) 

   -O0                                          execute no optimization passes 

   -O1                                          execute -O1 optimization passes
                                                (quick&useful opts, useful for 
                                                iteration builds) 

   -O2                                          execute -O2 optimization passes
                                                (most opts, generally gets most
                                                perf) 

   -O3                                          execute -O3 optimization passes
                                                (spends potentially a lot of 
                                                time optimizing) 

   -O4                                          execute -O4 optimization passes
                                                (also flatten the IR, which can
                                                take a lot more time and memory,
                                                but is useful on more nested / 
                                                complex / less-optimized input)

   -Os                                          execute default optimization 
                                                passes, focusing on code size 

   -Oz                                          execute default optimization 
                                                passes, super-focusing on code 
                                                size 
usuyuki commented 1 year ago

wasm-stripはcustom sectionを消すことで削減しているらしい.

❯ wasm-strip --help
usage: wasm-strip [options] filename

  Remove sections of a WebAssembly binary file.

examples:
  # Remove all custom sections from test.wasm
  $ wasm-strip test.wasm

options:
      --help                               Print this help message
      --version                            Print version information
  -o, --output=FILE                        output wasm binary file
  -k, --keep-section=SECTION NAME          Section name to keep in the final output
  -R, --remove-section=SECTION NAME        Section to specifically remove, including all the rest