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

CI: Add Wasm based benchmarking #443

Closed
Robbepop opened this issue Sep 16, 2022 · 2 comments
Closed

CI: Add Wasm based benchmarking #443

Robbepop opened this issue Sep 16, 2022 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@Robbepop
Copy link
Member

Since the PR for #322 was merged recently we now have a benchmarking CI.

However, the current benchmark CI only checks native performance while wasmi is mainly used as a WebAssembly binary executed via the Wasmtime engine.

Therefore having additional Wasm based testruns is really important information for us, too.

The current table that the CI outputs is as follows:

BENCHMARK MASTER PR DIFF
compile_and_validate xxx yyy ⚪ zzz %
instantiate aaa bbb 🟢 ccc %
execute_foo mmm nnn 🔴 ppp %
etc...

etc.

With additional Wasm based tests we need more columns:

BENCHMARK MASTER PR DIFF MASTER (Wasm) PR (Wasm) DIFF (Wasm)
compile_and_validate xxx yyy ⚪ zzz % www vvv ⚪ uuu %
instantiate aaa bbb 🟢 ccc % ddd eee 🔴 fff %
execute_foo mmm nnn 🔴 ppp % qqq rrr 🟢 sss %
etc...

Criterion has a whole section as to how to benchmark Criterion benchmarks as Wasm:
https://github.com/bheisler/criterion.rs/blob/5e27b692a43a05736d073fd449e16dcf1c24628c/book/src/user_guide/wasi.md

@Robbepop Robbepop added the enhancement New feature or request label Sep 16, 2022
@Robbepop
Copy link
Member Author

Robbepop commented Sep 23, 2022

Today I experimented with running wasmi benchmarks locally compiled to wasm32-wasi and ran via Wasmtime version 1.0.0.
While this process was not as smooth as running the benchmarks on native target it worked properly and will provide us with valuable information in the future since we are mostly interested in wasmi's performance when running inside a Wasm VM such as Wasmtime.

For this I followed the user guide linked above: User Guide

  • The first step is to install Wasmtime on your system. I am working on ARCHlinux so for me this step was fairly simple: sudo pacman -S wasmtime and it came with version 1.0.0 already.
  • Now we need to install Binaryen's wasm-opt tool. For me this again was a trivial sudo pacman -S binaryen which provides me with a recent version of wasm-opt since Binaryen is a Wasm toolkit with many different useful tools.
  • Finally we need to install the cargo-wasi cargo plugin: cargo install cargo-wasi.
  • As with the native benchmarks we first benchmark the master branch and afterwards the PR branch: git checkout master
  • Next we need to change wasmi's Cargo.toml slightly as described in the user guide and disable default features:
criterion = { version = "0.4.0", default-features = false }
  • We are now ready to build wasmi benchmarks for the wasm32-wasi target using the following command:
cargo wasi build --profile bench --bench benches --verbose

Note: This will already run wasm-opt after building the wasmi benchmarks so everything is already optimized properly.

  • Unfortunately cargo wasi bench command does not allow us to forward a --dir parameter to the underlying Wasmtime in order to allow the executed Wasm benchmarks to read and write some benchmark files. Therefore we need to run Wasmtime manually, but first we need to copy the compiled Wasm from the depth of the target directory: cp target/wasm32-wasi/release/deps/benches-HEX.wasi.wasm target/ci/benches.wasm.
  • As with the usual benchmarking we need to change our working directory from root to wasmi_v1 folder: cd wasmi_v1
  • Now we can finally run the master branch benchmarks using:
wasmtime run --dir=. ../target/ci/benches.wasm -- --bench --save-baseline master-wasm
  • Repeat the steps with the PR branch and using the following Wasmtime benchmark command:
wasmtime run --dir=. ../target/ci/benches.wasm -- --bench --baseline master-wasm
  • Now everything that is left to do is to collect the information and display it in the table just with the usual native benchmarks.
  • I have not tested this but I assume that cargo-criterion unfortunately won't work with Wasm benchmarks. I am not 100% sure though.

@Robbepop
Copy link
Member Author

This has been implemented in #483. Closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants