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

Implement fuel metering for the register-machine wasmi engine backend #810

Merged
merged 21 commits into from
Nov 28, 2023

Conversation

Robbepop
Copy link
Member

@Robbepop Robbepop commented Nov 27, 2023

  • Removed fields and fields accesses by methods.
  • Added new methods that make more sense for the new register-machine wasmi engine backend.
  • Adjusted both stack-machine and register-machine to the new model.
  • Reinvent register-machine translation API for fuel metering.
  • Implement fuel metering for all wasmi IR instruction of the new register-machine.
    • Control Flow
    • Branches
    • global instructions
    • call instructions
    • table instructions
    • memory instructions
    • select instructions
    • local.{set, tee} instructions
    • load instructions
    • store instructions
    • compare instructions
    • unary instructions
    • binary instructions
    • conversion instructions
    • copy instructions
    • return instructions
  • Implement fuel metering for function enclosing Wasm block.
    • Adhere for total register usage of the called function.
  • Add tests to check register-machine fuel metering works.
    • The whole Wasm spec testsuite ran fine with fuel metering enabled and enough fuel given.
  • Add benchmarks to check performance of fuel metered translation.

TODO

  • Make fuel_per_copy (et.al.) use usize for len parameter instead of u64.
    • Refactoring deemed too verbose on the stack-machine wasmi translator for the gained effect.
  • Use new FuelInfo enum type instead of raw Option<(FuelCost, Instr)>.

- Remove fields and fields accesses by methods.
- Add new methods that make more sense for the new register-machine wasmi engine backend.
- Adjusted both stack-machine and register-machine to the new model.
- Reinvent register-machine translation API for fuel metering.
@paritytech-cicd-pr
Copy link

paritytech-cicd-pr commented Nov 27, 2023

BENCHMARKS

NATIVEWASMTIME
BENCHMARKMASTERPRDIFFMASTERPRDIFFWASMTIME OVERHEAD
execute/
br_table
1.57ms 1.55ms ⚪ -0.60% 1.30ms 1.31ms ⚪ 1.03% 🟢 -15%
execute/
call/host/1
36.32µs 36.94µs 🔴 1.62% 40.62µs 39.28µs 🟢 -3.20% 🟢 6%
execute/
call/rec
167.21µs 165.81µs ⚪ -0.96% 357.33µs 353.21µs 🟢 -1.17% 🔴 113%
execute/
count_until
7.43ms 7.47ms ⚪ 0.62% 7.56ms 7.52ms ⚪ -0.38% 🟢 1%
execute/
factorial/iter
253.15µs 232.47µs 🟢 -8.41% 293.36µs 301.31µs 🔴 2.66% 🟢 30%
execute/
factorial/rec
695.36µs 672.40µs 🟢 -3.07% 1.36ms 1.29ms 🟢 -4.67% 🟡 92%
execute/
fibonacci/iter
1.34ms 1.36ms 🔴 1.78% 1.30ms 1.27ms 🟢 -2.53% 🟢 -7%
execute/
fibonacci/rec
6.17ms 6.15ms ⚪ -0.33% 13.52ms 13.37ms 🟢 -1.15% 🔴 117%
execute/
fibonacci/tail
1.38ms 1.34ms 🟢 -2.94% 3.69ms 3.62ms 🟢 -2.03% 🔴 170%
execute/
fuse
9.16ms 7.70ms 🟢 -15.75% 12.64ms 12.67ms ⚪ 0.20% 🟡 64%
execute/
global/bump
1.38ms 1.37ms ⚪ 1.12% 1.60ms 1.60ms ⚪ -0.08% 🟢 17%
execute/
global/get_const
709.52µs 647.50µs 🟢 -8.70% 748.16µs 749.83µs ⚪ 0.22% 🟢 16%
execute/
is_even/rec
1.08ms 1.09ms ⚪ -0.22% 2.23ms 2.23ms ⚪ 0.04% 🔴 106%
execute/
memory/fill_bytes
1.13ms 1.14ms ⚪ 1.06% 1.23ms 1.24ms ⚪ 0.86% 🟢 8%
execute/
memory/sum_bytes
1.09ms 1.07ms 🟢 -1.85% 1.23ms 1.25ms 🔴 2.16% 🟢 17%
execute/
memory/vec_add
2.94ms 2.94ms ⚪ 0.22% 3.62ms 3.58ms ⚪ -0.92% 🟢 22%
execute/
recursive_scan
189.36µs 182.70µs 🟢 -4.19% 375.97µs 374.04µs ⚪ -0.51% 🔴 105%
execute/
recursive_trap
15.47µs 15.33µs ⚪ -1.00% 34.94µs 37.13µs 🔴 6.17% 🔴 142%
execute/
regex_redux
601.91µs 608.33µs ⚪ 0.38% 1.04ms 1.02ms 🟢 -2.10% 🟡 68%
execute/
rev_complement
442.47µs 441.77µs ⚪ -0.11% 632.80µs 664.79µs 🔴 5.05% 🟢 50%
execute/
tiny_keccak
350.25µs 351.08µs ⚪ 0.23% 385.16µs 382.73µs ⚪ -0.69% 🟢 9%
execute/
trunc_f2i
615.47µs 618.19µs ⚪ 0.48% 938.82µs 942.43µs ⚪ 0.25% 🟡 52%
instantiate/
wasm_kernel
55.97µs 54.80µs ⚪ 0.60% 55.33µs 55.93µs ⚪ 1.44% 🟢 2%
overhead/
call/typed/0
1.21ms 1.22ms ⚪ 0.04% 844.27µs 851.74µs ⚪ 1.01% 🟢 -30%
overhead/
call/typed/16
1.80ms 1.62ms 🟢 -7.30% 2.10ms 1.94ms 🟢 -7.49% 🟢 20%
overhead/
call/untyped/0
1.63ms 1.66ms ⚪ 1.56% 1.30ms 1.34ms 🔴 2.67% 🟢 -19%
overhead/
call/untyped/16
2.58ms 2.47ms 🟢 -4.00% 3.91ms 3.88ms ⚪ -0.55% 🟡 57%
translate/
bz2/default
1.31ms 1.39ms 🔴 5.40% 2.45ms 2.54ms 🔴 3.69% 🟡 83%
translate/
bz2/fuel
1.32ms 1.44ms 🔴 8.98% 2.45ms 2.70ms 🔴 10.20% 🟡 88%
translate/
erc1155/default
275.66µs 281.95µs 🔴 2.40% 472.63µs 496.14µs 🔴 5.02% 🟡 76%
translate/
erc1155/fuel
276.64µs 302.99µs 🔴 9.40% 478.64µs 527.12µs 🔴 10.03% 🟡 74%
translate/
erc20/default
135.04µs 135.80µs ⚪ 0.43% 227.64µs 237.72µs 🔴 4.41% 🟡 75%
translate/
erc20/fuel
134.85µs 144.26µs 🔴 6.32% 227.64µs 250.18µs 🔴 9.83% 🟡 73%
translate/
erc721/default
190.75µs 194.11µs 🔴 1.73% 327.88µs 341.45µs 🔴 4.27% 🟡 76%
translate/
erc721/fuel
191.73µs 204.24µs 🔴 6.48% 330.27µs 356.86µs 🔴 7.89% 🟡 75%
translate/
pulldown_cmark/default
3.64ms 3.77ms 🔴 3.52% 6.44ms 6.63ms 🔴 2.93% 🟡 76%
translate/
pulldown_cmark/fuel
3.63ms 3.87ms 🔴 6.41% 6.44ms 6.98ms 🔴 8.27% 🟡 80%
translate/
spidermonkey/default
0.00ns 0.00ns 🔴 3.44% 0.00ns 0.00ns 🔴 3.50% 🟢 0%
translate/
spidermonkey/fuel
0.00ns 0.00ns 🔴 6.46% 0.00ns 0.00ns 🔴 7.40% 🟢 0%
translate/
wasm_kernel/default
4.88ms 5.02ms 🔴 2.97% 8.69ms 8.94ms 🔴 3.00% 🟡 78%
translate/
wasm_kernel/fuel
4.91ms 5.16ms 🔴 5.15% 8.74ms 9.34ms 🔴 7.01% 🟡 81%

Link to pipeline

@codecov-commenter
Copy link

codecov-commenter commented Nov 27, 2023

Codecov Report

Attention: 63 lines in your changes are missing coverage. Please review.

Comparison is base (80e1d21) 80.92% compared to head (553f01e) 81.47%.

Files Patch % Lines
crates/wasmi/src/engine/regmach/translator/mod.rs 71.64% 38 Missing ⚠️
...smi/src/engine/regmach/translator/instr_encoder.rs 73.68% 15 Missing ⚠️
...rates/wasmi/src/engine/regmach/translator/visit.rs 87.50% 9 Missing ⚠️
crates/wasmi/src/engine/config.rs 96.29% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #810      +/-   ##
==========================================
+ Coverage   80.92%   81.47%   +0.54%     
==========================================
  Files         274      274              
  Lines       25366    25381      +15     
==========================================
+ Hits        20528    20678     +150     
+ Misses       4838     4703     -135     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Robbepop Robbepop merged commit 52f180c into master Nov 28, 2023
18 checks passed
@Robbepop Robbepop deleted the rf-regmach-fuel-metering branch November 28, 2023 21:20
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.

3 participants