Skip to content

Commit

Permalink
Implement allocation benchmark test in wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
akoptelov committed Oct 17, 2023
1 parent f6dcefa commit 90b3684
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 2 deletions.
16 changes: 16 additions & 0 deletions mina-p2p-messages/.github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,19 @@ jobs:
with:
command: test
args: --test decode-alloc -- decode_alloc --exact --nocapture --ignored -- --load-baseline=tests/decode-alloc/mem-benchmarks

tests-wasm:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- uses: actions-rs/toolchain@v1
with:
toolchain: stable

- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

- name: Run memory allocations benchmarks
run: wasm-pack test --node . --test decode-alloc -- decode_alloc_wasm
32 changes: 30 additions & 2 deletions mina-p2p-messages/tests/decode-alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,35 @@ fn decode_alloc() -> Result<(), BenchmarkError> {
Ok(())
}

#[cfg(target_family = "wasm")]
#[wasm_bindgen_test::wasm_bindgen_test]
fn decode_alloc_wasm() -> Result<(), BenchmarkError> {
use alloc_test::mem_bench_cmp_with_toml;
let limits = limits();
mem_bench_cmp_with_toml!(
tx_pool_diff,
Some(include_str!(
"decode-alloc/mem-benchmarks/tx_pool_diff.wasm.toml"
)),
&limits
)?;
mem_bench_cmp_with_toml!(
staged_ledger,
Some(include_str!(
"decode-alloc/mem-benchmarks/staged_ledger.wasm.toml"
)),
&limits
)?;
mem_bench_cmp_with_toml!(
incoming_rpc,
Some(include_str!(
"decode-alloc/mem-benchmarks/incoming_rpc.wasm.toml"
)),
&limits
)?;
Ok(())
}

fn tx_pool_diff() {
const BYTES: &[u8] = include_bytes!("files/v2/gossip/new_state.bin");
let mut p = BYTES;
Expand Down Expand Up @@ -76,8 +105,7 @@ fn incoming_rpc_one_by_one() {
mod utils;

pub fn staged_ledger() {
static ENCODED: &[u8] =
include_bytes!("files/v2/rpc/get-staged-ledger-aux/response/00.bin");
static ENCODED: &[u8] = include_bytes!("files/v2/rpc/get-staged-ledger-aux/response/00.bin");
let mut p = ENCODED;
Message::<<GetStagedLedgerAuxAndPendingCoinbasesAtHashV2 as RpcMethod>::Response>::binprot_read(
&mut p,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
current = 0
peak = 27504386
total_size = 116678802
total_num = 3567201
reallocs = 24
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
current = 0
peak = 27504335
total_size = 27507791
total_num = 837591
reallocs = 24
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
current = 0
peak = 22634
total_size = 22634
total_num = 763
reallocs = 0

0 comments on commit 90b3684

Please sign in to comment.