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

Simplify and optimize wasmi codegen #527

Merged
merged 2 commits into from
Oct 20, 2022
Merged

Simplify and optimize wasmi codegen #527

merged 2 commits into from
Oct 20, 2022

Conversation

Robbepop
Copy link
Member

@Robbepop Robbepop commented Oct 20, 2022

Due to historical reasons the wasmi codegen that converts from Wasm bytecode to its internal wasmi bytecode still performed many checks that have already been covered by the wasmparser based Wasm validation.
This PR eliminates all or most of those unnecessary duplicate checks for some reasonable speedups in translation time.

Locally I was able to see roughly 15% speedup in the translation benchmark.

In detail this PR

  • Removes the emulated ValueStack during translation time and replaces it with a glorified ValueStackHeight counter.
  • Simplifies the LocalsRegistry to no longer deal with local variable types so that it also became a glorified counter.
  • Removes tons of type checks during translation time. These are unnecessary since the Wasm validation already performs them.

@Robbepop Robbepop changed the title Simplify and optimize wasmi codegen Simplify and optimize wasmi codegen Oct 20, 2022
@paritytech-cicd-pr
Copy link

BENCHMARKS

NATIVEWASMTIME
BENCHMARKMASTERPRDIFFMASTERPRDIFFWASMTIME OVERHEAD
execute/
bare_call_0
1.29ms 1.26ms 🟢 -2.13% 1.14ms 1.05ms 🟢 -8.13% 🟢 -17%
execute/
bare_call_0/typed
705.24µs 704.49µs ⚪ -0.11% 532.10µs 530.15µs ⚪ -0.42% 🟢 -25%
execute/
bare_call_1
1.40ms 1.40ms 🟢 -0.45% 1.37ms 1.33ms 🟢 -3.09% 🟢 -6%
execute/
bare_call_16
3.05ms 2.90ms 🟢 -4.91% 5.03ms 4.87ms 🟢 -3.16% 🟡 68%
execute/
bare_call_16/typed
1.29ms 1.29ms ⚪ -0.27% 2.54ms 2.50ms 🟢 -1.27% 🟡 94%
execute/
bare_call_1/typed
802.24µs 811.85µs ⚪ 1.11% 826.24µs 819.05µs ⚪ -0.90% 🟢 1%
execute/
bare_call_4
1.84ms 1.75ms 🟢 -4.02% 2.13ms 2.07ms 🟢 -2.72% 🟢 18%
execute/
bare_call_4/typed
888.86µs 888.44µs ⚪ -0.07% 996.38µs 984.87µs ⚪ -1.14% 🟢 11%
execute/
br_table
918.88µs 918.97µs ⚪ -0.01% 1.07ms 1.06ms ⚪ -1.38% 🟢 16%
execute/
count_until
887.63µs 886.63µs ⚪ -0.10% 2.27ms 2.29ms ⚪ 0.88% 🔴 159%
execute/
factorial_iterative
363.61µs 363.55µs ⚪ -0.05% 928.15µs 920.72µs ⚪ -0.91% 🔴 153%
execute/
factorial_recursive
743.94µs 773.48µs 🔴 4.07% 1.57ms 1.57ms ⚪ -0.10% 🔴 102%
execute/
fib_iterative
1.82ms 1.79ms 🟢 -1.73% 4.94ms 4.94ms ⚪ 0.00% 🔴 176%
execute/
fib_recursive
6.96ms 7.01ms ⚪ 0.59% 14.44ms 14.58ms ⚪ 1.01% 🔴 108%
execute/
global_bump
1.44ms 1.42ms ⚪ -0.77% 3.57ms 3.61ms 🔴 1.12% 🔴 154%
execute/
host_calls
32.37µs 33.43µs ⚪ 2.13% 45.06µs 44.99µs ⚪ -0.10% 🟢 35%
execute/
memory_fill
1.54ms 1.53ms ⚪ -0.07% 4.13ms 4.13ms ⚪ 0.00% 🔴 169%
execute/
memory_sum
1.52ms 1.54ms ⚪ 1.17% 4.15ms 4.16ms ⚪ -0.03% 🔴 171%
execute/
memory_vec_add
3.07ms 3.04ms ⚪ -1.12% 8.71ms 8.72ms ⚪ 0.19% 🔴 187%
execute/
recursive_is_even
1.55ms 1.33ms 🟢 -14.16% 2.60ms 2.61ms ⚪ 0.13% 🟡 96%
execute/
recursive_ok
184.16µs 175.53µs 🟢 -4.44% 358.47µs 359.00µs ⚪ 0.12% 🔴 105%
execute/
recursive_scan
237.35µs 219.92µs 🟢 -7.31% 479.66µs 465.02µs 🟢 -2.96% 🔴 111%
execute/
recursive_trap
18.71µs 17.37µs 🟢 -8.56% 35.53µs 35.90µs ⚪ 0.85% 🔴 107%
execute/
regex_redux
658.42µs 655.63µs ⚪ -0.32% 1.64ms 1.61ms 🟢 -1.26% 🔴 146%
execute/
rev_complement
598.93µs 591.38µs ⚪ -0.94% 1.61ms 1.53ms 🟢 -4.75% 🔴 159%
execute/
tiny_keccak
452.38µs 478.39µs 🔴 5.83% 1.47ms 1.39ms 🟢 -5.71% 🔴 190%
execute/
trunc_f2i
1.07ms 1.07ms ⚪ 0.19% 2.61ms 2.61ms ⚪ -0.34% 🔴 143%
instantiate/
wasm_kernel
69.99µs 71.27µs ⚪ -0.20% 94.65µs 125.47µs 🔴 32.59% 🟡 76%
translate/
wasm_kernel
4.95ms 4.14ms 🟢 -16.51% 10.28ms 8.70ms 🟢 -15.27% 🔴 110%

Link to pipeline

@Robbepop Robbepop merged commit 4ab955a into master Oct 20, 2022
@Robbepop Robbepop deleted the rf-simplify-codegen branch October 20, 2022 14:15
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