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

Optimization: differentiate function calls #724

Merged
merged 20 commits into from
May 28, 2023
Merged

Conversation

Robbepop
Copy link
Member

Closes #711.

This is to make it possible to use CompiledFunc in wasmi bytecode.
"insts" is ambiguous in Wasm with "instances" therefore we always want to use "instr" to refer to an instruction.
Now instead of allocation CompiledFunc to the `wasmi` Engine as the result of validation and translation of a Wasm function, the CompiledFunc is already allocated and initialized instead.
This allows to access the CompiledFunc index for function calls in other translation units which finally provides the possibility to optimize calls to internal functions.
Also this will make it simpler to run function translations concurrently if we ever decide to want this feature.
Maybe we should specialize Call to CallImported and mandate that it is only used for imported functions. This could further optimize the call infrastructure in the engine by relying on this.
@paritytech-cicd-pr
Copy link

paritytech-cicd-pr commented May 28, 2023

BENCHMARKS

NATIVEWASMTIME
BENCHMARKMASTERPRDIFFMASTERPRDIFFWASMTIME OVERHEAD
execute/
bare_call_0
1.53ms 1.54ms 🟢 0.83% 1.06ms 1.05ms 🟢 -1.20% 🟢 -32%
execute/
bare_call_0/typed
1.18ms 1.15ms 🟢 -2.23% 693.11µs 680.56µs 🟢 -1.77% 🟢 -41%
execute/
bare_call_1
1.58ms 1.58ms 🟢 -0.15% 1.27ms 1.19ms 🟢 -6.63% 🟢 -25%
execute/
bare_call_16
2.57ms 2.52ms 🟢 -1.81% 3.49ms 3.27ms 🟢 -5.94% 🟢 30%
execute/
bare_call_16/typed
1.57ms 1.59ms ⚪ 0.99% 1.91ms 1.82ms 🟢 -4.88% 🟢 15%
execute/
bare_call_1/typed
1.25ms 1.22ms 🟢 -2.43% 1.02ms 1.01ms ⚪ -0.96% 🟢 -18%
execute/
bare_call_4
1.78ms 1.75ms ⚪ -1.33% 1.63ms 1.60ms 🟢 -2.48% 🟢 -9%
execute/
bare_call_4/typed
1.21ms 1.21ms ⚪ -0.12% 1.00ms 966.41µs 🟢 -2.98% 🟢 -20%
execute/
br_table
1.33ms 1.40ms 🔴 5.28% 1.26ms 1.21ms 🟢 -3.67% 🟢 -14%
execute/
count_until
578.09µs 577.36µs ⚪ 0.02% 1.16ms 1.16ms ⚪ -0.34% 🟡 100%
execute/
factorial_iterative
319.97µs 318.87µs ⚪ -0.57% 554.71µs 539.69µs 🟢 -2.76% 🟡 69%
execute/
factorial_recursive
595.65µs 506.33µs 🟢 -15.21% 842.94µs 675.28µs 🟢 -19.71% 🟢 33%
execute/
fibonacci_iter
1.40ms 1.36ms 🟢 -3.21% 3.18ms 2.94ms 🟢 -7.50% 🔴 117%
execute/
fibonacci_rec
4.94ms 4.20ms 🟢 -15.09% 7.62ms 6.40ms 🟢 -15.96% 🟡 53%
execute/
fibonacci_tail
1.08ms 899.00µs 🟢 -16.62% 1.90ms 1.51ms 🟢 -20.58% 🟡 68%
execute/
global_bump
723.35µs 738.35µs 🔴 2.09% 1.41ms 1.54ms 🔴 9.47% 🔴 109%
execute/
global_const
683.54µs 659.48µs 🟢 -3.46% 1.31ms 1.31ms ⚪ 0.28% 🟡 99%
execute/
host_calls
36.36µs 36.35µs ⚪ 0.41% 40.00µs 41.44µs 🔴 3.53% 🟢 14%
execute/
memory_fill
1.14ms 1.15ms ⚪ 0.28% 2.26ms 2.21ms 🟢 -2.28% 🟡 93%
execute/
memory_sum
1.13ms 1.13ms ⚪ -0.17% 2.47ms 2.43ms 🟢 -1.40% 🔴 114%
execute/
memory_vec_add
2.24ms 2.24ms ⚪ 0.07% 4.77ms 4.36ms 🟢 -8.45% 🟡 95%
execute/
recursive_is_even
1.02ms 695.66µs 🟢 -32.24% 1.61ms 1.03ms 🟢 -35.86% 🟢 48%
execute/
recursive_ok
122.69µs 99.39µs 🟢 -19.19% 196.37µs 149.07µs 🟢 -24.10% 🟢 50%
execute/
recursive_scan
161.19µs 135.24µs 🟢 -15.68% 242.42µs 194.45µs 🟢 -19.65% 🟢 44%
execute/
recursive_trap
12.44µs 9.60µs 🟢 -23.48% 20.70µs 14.71µs 🟢 -28.92% 🟡 53%
execute/
regex_redux
491.74µs 458.48µs 🟢 -6.62% 889.69µs 846.71µs 🟢 -4.81% 🟡 85%
execute/
rev_complement
442.12µs 435.15µs ⚪ -1.34% 870.68µs 839.67µs 🟢 -3.52% 🟡 93%
execute/
tiny_keccak
320.50µs 320.77µs ⚪ 0.15% 661.45µs 658.96µs ⚪ -0.29% 🔴 105%
execute/
trunc_f2i
731.41µs 736.33µs ⚪ 1.19% 1.67ms 1.73ms 🔴 3.55% 🔴 135%
instantiate/
wasm_kernel
55.21µs 52.79µs 🟢 -3.23% 55.45µs 58.72µs 🔴 5.32% 🟢 11%
translate/
erc1155
197.45µs 198.79µs ⚪ 0.51% 417.94µs 442.34µs 🔴 5.71% 🔴 123%
translate/
erc20
97.58µs 97.16µs ⚪ -0.48% 200.51µs 210.01µs 🔴 4.80% 🔴 116%
translate/
erc721
138.92µs 137.99µs ⚪ -0.74% 292.31µs 305.87µs 🔴 4.60% 🔴 122%
translate/
spidermonkey
62.18ms 62.19ms ⚪ 0.12% 0.00ns 0.00ns 🔴 5.77% 🟢 -100%
translate/
wasm_kernel
3.53ms 4.12ms 🔴 16.28% 7.51ms 7.93ms 🔴 5.48% 🟡 93%

Link to pipeline

@codecov-commenter
Copy link

codecov-commenter commented May 28, 2023

Codecov Report

Merging #724 (ef6b5e6) into master (74c173c) will increase coverage by 0.03%.
The diff coverage is 85.71%.

@@            Coverage Diff             @@
##           master     #724      +/-   ##
==========================================
+ Coverage   79.03%   79.06%   +0.03%     
==========================================
  Files         102      102              
  Lines        8684     8757      +73     
==========================================
+ Hits         6863     6924      +61     
- Misses       1821     1833      +12     
Impacted Files Coverage Δ
crates/wasmi/src/engine/bytecode/mod.rs 94.11% <ø> (ø)
crates/wasmi/src/engine/func_builder/translator.rs 86.31% <61.53%> (-0.35%) ⬇️
crates/wasmi/src/engine/executor.rs 78.30% <72.72%> (-0.20%) ⬇️
crates/wasmi/src/module/parser.rs 72.10% <80.00%> (-0.39%) ⬇️
crates/wasmi/src/engine/code_map.rs 90.47% <93.18%> (+7.97%) ⬆️
...ates/wasmi/src/engine/func_builder/inst_builder.rs 80.64% <100.00%> (ø)
crates/wasmi/src/engine/func_builder/mod.rs 91.66% <100.00%> (ø)
crates/wasmi/src/engine/mod.rs 77.72% <100.00%> (+0.43%) ⬆️
crates/wasmi/src/engine/tests.rs 99.36% <100.00%> (ø)
crates/wasmi/src/func/mod.rs 77.16% <100.00%> (ø)
... and 3 more

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

@Robbepop Robbepop merged commit b68995e into master May 28, 2023
@Robbepop Robbepop deleted the rf-differentiate-calls branch May 28, 2023 13:23
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.

Optimization: Differentiate between imported and internal calls
3 participants