diff --git a/mina-p2p-messages/.github/workflows/unit-tests.yml b/mina-p2p-messages/.github/workflows/unit-tests.yml index 2ac045a78d50..13e0153fb968 100644 --- a/mina-p2p-messages/.github/workflows/unit-tests.yml +++ b/mina-p2p-messages/.github/workflows/unit-tests.yml @@ -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 diff --git a/mina-p2p-messages/tests/decode-alloc.rs b/mina-p2p-messages/tests/decode-alloc.rs index ab0edf4f5a10..0bf1093c7be5 100644 --- a/mina-p2p-messages/tests/decode-alloc.rs +++ b/mina-p2p-messages/tests/decode-alloc.rs @@ -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; @@ -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::<::Response>::binprot_read( &mut p, diff --git a/mina-p2p-messages/tests/decode-alloc/mem-benchmarks/incoming_rpc.wasm.toml b/mina-p2p-messages/tests/decode-alloc/mem-benchmarks/incoming_rpc.wasm.toml new file mode 100644 index 000000000000..585765bc720b --- /dev/null +++ b/mina-p2p-messages/tests/decode-alloc/mem-benchmarks/incoming_rpc.wasm.toml @@ -0,0 +1,5 @@ +current = 0 +peak = 27504386 +total_size = 116678802 +total_num = 3567201 +reallocs = 24 diff --git a/mina-p2p-messages/tests/decode-alloc/mem-benchmarks/staged_ledger.wasm.toml b/mina-p2p-messages/tests/decode-alloc/mem-benchmarks/staged_ledger.wasm.toml new file mode 100644 index 000000000000..ed32bbda01b2 --- /dev/null +++ b/mina-p2p-messages/tests/decode-alloc/mem-benchmarks/staged_ledger.wasm.toml @@ -0,0 +1,5 @@ +current = 0 +peak = 27504335 +total_size = 27507791 +total_num = 837591 +reallocs = 24 diff --git a/mina-p2p-messages/tests/decode-alloc/mem-benchmarks/tx_pool_diff.wasm.toml b/mina-p2p-messages/tests/decode-alloc/mem-benchmarks/tx_pool_diff.wasm.toml new file mode 100644 index 000000000000..a138d5467952 --- /dev/null +++ b/mina-p2p-messages/tests/decode-alloc/mem-benchmarks/tx_pool_diff.wasm.toml @@ -0,0 +1,5 @@ +current = 0 +peak = 22634 +total_size = 22634 +total_num = 763 +reallocs = 0