wasmi icon indicating copy to clipboard operation
wasmi copied to clipboard

refactor: improve call wasm

Open yjhmelody opened this issue 3 years ago • 6 comments

  • Make the logic more clean and clear. - check recursion_limit by >=

yjhmelody avatar Oct 12 '22 07:10 yjhmelody

BENCHMARKS

NATIVEWASMTIME
BENCHMARKMASTERPRDIFFMASTERPRDIFFWASMTIME OVERHEAD
execute/
bare_call_0
1.27ms 1.27ms :white_circle: 0.43% 1.12ms 1.09ms :green_circle: -2.98% :green_circle: -14%
execute/
bare_call_0/typed
698.58µs 705.30µs :white_circle: 0.90% 547.87µs 551.10µs :white_circle: 0.60% :green_circle: -22%
execute/
bare_call_1
1.40ms 1.40ms :green_circle: -0.82% 1.37ms 1.35ms :green_circle: -1.58% :green_circle: -4%
execute/
bare_call_16
3.13ms 2.90ms :green_circle: -7.07% 4.99ms 5.00ms :green_circle: 0.32% :yellow_circle: 72%
execute/
bare_call_16/typed
1.32ms 1.29ms :green_circle: -2.45% 2.34ms 2.28ms :green_circle: -2.44% :yellow_circle: 77%
execute/
bare_call_1/typed
800.90µs 799.92µs :white_circle: -0.08% 874.15µs 865.19µs :white_circle: -0.96% :green_circle: 8%
execute/
bare_call_4
1.76ms 1.78ms :red_circle: 1.39% 2.14ms 2.16ms :green_circle: 1.12% :green_circle: 21%
execute/
bare_call_4/typed
891.43µs 886.81µs :white_circle: -0.47% 1.00ms 984.30µs :green_circle: -1.56% :green_circle: 11%
execute/
br_table
983.74µs 908.23µs :green_circle: -7.64% 1.14ms 1.10ms :green_circle: -4.01% :green_circle: 21%
execute/
count_until
903.65µs 903.43µs :white_circle: 0.05% 2.40ms 2.21ms :green_circle: -7.87% :red_circle: 144%
execute/
factorial_iterative
365.06µs 376.29µs :red_circle: 2.97% 946.61µs 901.84µs :green_circle: -4.67% :red_circle: 140%
execute/
factorial_recursive
730.68µs 711.02µs :green_circle: -2.72% 1.58ms 1.45ms :green_circle: -8.78% :red_circle: 103%
execute/
fib_iterative
1.79ms 1.79ms :white_circle: 0.03% 5.00ms 4.90ms :green_circle: -1.89% :red_circle: 174%
execute/
fib_recursive
7.05ms 6.75ms :green_circle: -4.33% 14.29ms 13.68ms :green_circle: -4.27% :red_circle: 103%
execute/
global_bump
1.36ms 1.38ms :white_circle: 1.05% 3.65ms 3.35ms :green_circle: -8.26% :red_circle: 143%
execute/
global_const
999.89µs 999.49µs :white_circle: -0.02% 2.83ms 2.52ms :green_circle: -11.15% :red_circle: 152%
execute/
host_calls
32.63µs 32.39µs :white_circle: -0.77% 44.69µs 44.82µs :white_circle: 0.48% :green_circle: 38%
execute/
memory_fill
1.55ms 1.55ms :white_circle: 0.09% 4.20ms 4.07ms :green_circle: -3.00% :red_circle: 162%
execute/
memory_sum
1.55ms 1.55ms :white_circle: 0.10% 4.18ms 4.05ms :green_circle: -3.10% :red_circle: 161%
execute/
memory_vec_add
3.11ms 3.05ms :green_circle: -1.86% 8.75ms 8.02ms :green_circle: -8.39% :red_circle: 163%
execute/
recursive_is_even
1.29ms 1.29ms :white_circle: 0.15% 2.63ms 2.50ms :green_circle: -5.15% :yellow_circle: 93%
execute/
recursive_ok
170.56µs 167.63µs :green_circle: -1.72% 377.40µs 359.20µs :green_circle: -4.95% :red_circle: 114%
execute/
recursive_scan
213.76µs 209.21µs :green_circle: -2.13% 466.29µs 451.00µs :green_circle: -3.26% :red_circle: 116%
execute/
recursive_trap
16.93µs 16.26µs :green_circle: -3.98% 36.09µs 34.52µs :green_circle: -4.36% :red_circle: 112%
execute/
regex_redux
669.97µs 662.32µs :green_circle: -1.24% 1.60ms 1.45ms :green_circle: -9.38% :red_circle: 118%
execute/
rev_complement
590.19µs 595.15µs :white_circle: 0.94% 1.56ms 1.43ms :green_circle: -8.18% :red_circle: 141%
execute/
tiny_keccak
450.54µs 482.95µs :red_circle: 7.28% 1.39ms 1.29ms :green_circle: -7.12% :red_circle: 167%
execute/
trunc_f2i
1.08ms 1.01ms :green_circle: -6.67% 2.66ms 2.44ms :green_circle: -8.11% :red_circle: 142%
instantiate/
wasm_kernel
67.57µs 70.66µs :white_circle: 4.00% 91.92µs 94.48µs :red_circle: 2.72% :green_circle: 34%
translate/
wasm_kernel
4.19ms 4.22ms :white_circle: 0.74% 7.74ms 7.88ms :red_circle: 1.80% :yellow_circle: 87%

Link to pipeline

paritytech-cicd-pr avatar Oct 12 '22 07:10 paritytech-cicd-pr

I checked out your PR locally after seeing some regressions according to our benchmarking CI and unfortunately I can confirm locally that some benchmarks are slightly regressed with those changes. I see that they are some kind of a clean up but I am hesistant merging a change if it introduces regressions that I do not understand.

Robbepop avatar Oct 13 '22 07:10 Robbepop

@Robbepop I do not see regressions in my local

yjhmelody avatar Oct 13 '22 07:10 yjhmelody

Codecov Report

Merging #508 (ec90097) into master (0d087e2) will decrease coverage by 0.00%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #508      +/-   ##
==========================================
- Coverage   79.73%   79.73%   -0.01%     
==========================================
  Files          75       75              
  Lines        6292     6291       -1     
==========================================
- Hits         5017     5016       -1     
  Misses       1275     1275              
Impacted Files Coverage Δ
crates/wasmi/src/engine/mod.rs 83.52% <100.00%> (ø)
crates/wasmi/src/engine/stack/frames.rs 92.00% <100.00%> (-0.60%) :arrow_down:
crates/wasmi/src/engine/stack/mod.rs 79.71% <100.00%> (+0.29%) :arrow_up:

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

codecov-commenter avatar Oct 13 '22 09:10 codecov-commenter

:( execute/memory_vec_add meet a lot regressions. Why?

yjhmelody avatar Oct 17 '22 13:10 yjhmelody

:( execute/memory_vec_add meet a lot regressions. Why?

I don't know. Could be an artifact. Unfortunately wasmi these days is extremely sensible to performance regressions.

Robbepop avatar Oct 17 '22 13:10 Robbepop

Hi, seems now it at least not make regressions. @Robbepop

yjhmelody avatar Oct 18 '22 13:10 yjhmelody

Why is red when improved? Such as 🔴 -3.70% 🔴 -0.35%

yjhmelody avatar Oct 19 '22 03:10 yjhmelody

Strange, wasm_kernel is not stable, I see a big improvement last time.

yjhmelody avatar Oct 20 '22 08:10 yjhmelody

@Robbepop It now seems is a good improvement that could be merged now.

yjhmelody avatar Oct 26 '22 10:10 yjhmelody

@Robbepop It now seems is a good improvement that could be merged now.

The problem with those benchmarks is that they are currently extremely flaky/noisy for this PR in particular. I don't know why that is but we cannot really trust those benchmarks fully with respect to this PR. I will take a look today on it and decide if we want to merge it. Generally I think the code of the PR is an improvement, however, I can remember that I programmed the structure so far in this way due to performance regressions back then. However, code has changed a lot since then and FuncFrame also became much smaller and therefore moving a FuncFrame around is no longer that bad.

Robbepop avatar Oct 31 '22 08:10 Robbepop