From 291bfc65512726f28d5bce353200d05af7cc0558 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C5=A1a=20Tomi=C4=87?= Date: Fri, 13 Mar 2026 15:39:29 +0100 Subject: [PATCH 1/3] bench: add vec_nat, vec_nat32, vec_nat64 benchmarks Cover variable-length (Nat/LEB128) and fixed-width (u32, u64) vector serialization to complement the existing vec_int16 benchmark. Made-with: Cursor --- rust/bench/bench.rs | 51 ++++++++ rust/bench/canbench_results.yml | 201 ++++++++++++++++++++++++++++++++ 2 files changed, 252 insertions(+) create mode 100644 rust/bench/canbench_results.yml diff --git a/rust/bench/bench.rs b/rust/bench/bench.rs index 9ec60beed..dbea5e46d 100644 --- a/rust/bench/bench.rs +++ b/rust/bench/bench.rs @@ -62,6 +62,57 @@ fn vec_int16() -> BenchResult { }) } +#[bench(raw)] +fn vec_nat() -> BenchResult { + let vec: Vec = (0u64..262144).map(Nat::from).collect(); + let mut config = DecoderConfig::new(); + config.set_decoding_quota(COST).set_skipping_quota(SKIP); + bench_fn(|| { + let bytes = { + let _p = bench_scope("1. Encoding"); + Encode!(&vec).unwrap() + }; + { + let _p = bench_scope("2. Decoding"); + Decode!([config]; &bytes, Vec).unwrap(); + } + }) +} + +#[bench(raw)] +fn vec_nat64() -> BenchResult { + let vec: Vec = (0u64..N as u64).collect(); + let mut config = DecoderConfig::new(); + config.set_decoding_quota(25_000_000).set_skipping_quota(SKIP); + bench_fn(|| { + let bytes = { + let _p = bench_scope("1. Encoding"); + Encode!(&vec).unwrap() + }; + { + let _p = bench_scope("2. Decoding"); + Decode!([config]; &bytes, Vec).unwrap(); + } + }) +} + +#[bench(raw)] +fn vec_nat32() -> BenchResult { + let vec: Vec = (0u32..N as u32).collect(); + let mut config = DecoderConfig::new(); + config.set_decoding_quota(COST).set_skipping_quota(SKIP); + bench_fn(|| { + let bytes = { + let _p = bench_scope("1. Encoding"); + Encode!(&vec).unwrap() + }; + { + let _p = bench_scope("2. Decoding"); + Decode!([config]; &bytes, Vec).unwrap(); + } + }) +} + #[bench(raw)] fn btreemap() -> BenchResult { let mut config = DecoderConfig::new(); diff --git a/rust/bench/canbench_results.yml b/rust/bench/canbench_results.yml new file mode 100644 index 000000000..69f250ace --- /dev/null +++ b/rust/bench/canbench_results.yml @@ -0,0 +1,201 @@ +benches: + blob: + total: + calls: 1 + instructions: 6334106 + heap_increase: 66 + stable_memory_increase: 0 + scopes: + 1. Encoding: + calls: 1 + instructions: 4207626 + heap_increase: 66 + stable_memory_increase: 0 + 2. Decoding: + calls: 1 + instructions: 2123815 + heap_increase: 0 + stable_memory_increase: 0 + btreemap: + total: + calls: 1 + instructions: 20444564541 + heap_increase: 1179 + stable_memory_increase: 0 + scopes: + 1. Encoding: + calls: 1 + instructions: 4701848503 + heap_increase: 159 + stable_memory_increase: 0 + 2. Decoding: + calls: 1 + instructions: 15742713839 + heap_increase: 1020 + stable_memory_increase: 0 + extra_args: + total: + calls: 1 + instructions: 3509512 + heap_increase: 0 + stable_memory_increase: 0 + scopes: {} + nns: + total: + calls: 1 + instructions: 26638344 + heap_increase: 2 + stable_memory_increase: 0 + scopes: + 0. Parsing: + calls: 1 + instructions: 17856363 + heap_increase: 2 + stable_memory_increase: 0 + 1. Encoding: + calls: 1 + instructions: 2091556 + heap_increase: 0 + stable_memory_increase: 0 + 2. Decoding: + calls: 1 + instructions: 5739905 + heap_increase: 0 + stable_memory_increase: 0 + nns_list_proposal: + total: + calls: 1 + instructions: 77377790 + heap_increase: 17 + stable_memory_increase: 0 + scopes: + 1. Encoding: + calls: 1 + instructions: 6878988 + heap_increase: 3 + stable_memory_increase: 0 + 2. Decoding: + calls: 1 + instructions: 70496590 + heap_increase: 14 + stable_memory_increase: 0 + option_list: + total: + calls: 1 + instructions: 36382258 + heap_increase: 2 + stable_memory_increase: 0 + scopes: + 1. Encoding: + calls: 1 + instructions: 8026927 + heap_increase: 0 + stable_memory_increase: 0 + 2. Decoding: + calls: 1 + instructions: 28352941 + heap_increase: 2 + stable_memory_increase: 0 + text: + total: + calls: 1 + instructions: 12085058 + heap_increase: 99 + stable_memory_increase: 0 + scopes: + 1. Encoding: + calls: 1 + instructions: 4204261 + heap_increase: 66 + stable_memory_increase: 0 + 2. Decoding: + calls: 1 + instructions: 7878453 + heap_increase: 33 + stable_memory_increase: 0 + variant_list: + total: + calls: 1 + instructions: 35275846 + heap_increase: 2 + stable_memory_increase: 0 + scopes: + 1. Encoding: + calls: 1 + instructions: 8224004 + heap_increase: 0 + stable_memory_increase: 0 + 2. Decoding: + calls: 1 + instructions: 27049630 + heap_increase: 2 + stable_memory_increase: 0 + vec_int16: + total: + calls: 1 + instructions: 1191174179 + heap_increase: 261 + stable_memory_increase: 0 + scopes: + 1. Encoding: + calls: 1 + instructions: 123695816 + heap_increase: 261 + stable_memory_increase: 0 + 2. Decoding: + calls: 1 + instructions: 1067476062 + heap_increase: 0 + stable_memory_increase: 0 + vec_nat: + total: + calls: 1 + instructions: 2585408968 + heap_increase: 172 + stable_memory_increase: 0 + scopes: + 1. Encoding: + calls: 1 + instructions: 1095177748 + heap_increase: 33 + stable_memory_increase: 0 + 2. Decoding: + calls: 1 + instructions: 1490228877 + heap_increase: 139 + stable_memory_increase: 0 + vec_nat32: + total: + calls: 1 + instructions: 1197467371 + heap_increase: 518 + stable_memory_increase: 0 + scopes: + 1. Encoding: + calls: 1 + instructions: 136280132 + heap_increase: 518 + stable_memory_increase: 0 + 2. Decoding: + calls: 1 + instructions: 1061184938 + heap_increase: 0 + stable_memory_increase: 0 + vec_nat64: + total: + calls: 1 + instructions: 1222634919 + heap_increase: 1031 + stable_memory_increase: 0 + scopes: + 1. Encoding: + calls: 1 + instructions: 161447366 + heap_increase: 1031 + stable_memory_increase: 0 + 2. Decoding: + calls: 1 + instructions: 1061185270 + heap_increase: 0 + stable_memory_increase: 0 +version: 0.4.1 From 37c143572149ca67ca89753beb9036fb1692c6ed Mon Sep 17 00:00:00 2001 From: Linwei Shang Date: Sun, 15 Mar 2026 14:15:51 -0400 Subject: [PATCH 2/3] chore: remove generated canbench_results.yml and add to .gitignore Co-Authored-By: Claude Sonnet 4.6 --- .gitignore | 1 + rust/bench/canbench_results.yml | 201 -------------------------------- 2 files changed, 1 insertion(+), 201 deletions(-) delete mode 100644 rust/bench/canbench_results.yml diff --git a/.gitignore b/.gitignore index fa8bf2662..75e44429f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ target/ .canbench/ +canbench_results.yml # IDEs .idea/ diff --git a/rust/bench/canbench_results.yml b/rust/bench/canbench_results.yml deleted file mode 100644 index 69f250ace..000000000 --- a/rust/bench/canbench_results.yml +++ /dev/null @@ -1,201 +0,0 @@ -benches: - blob: - total: - calls: 1 - instructions: 6334106 - heap_increase: 66 - stable_memory_increase: 0 - scopes: - 1. Encoding: - calls: 1 - instructions: 4207626 - heap_increase: 66 - stable_memory_increase: 0 - 2. Decoding: - calls: 1 - instructions: 2123815 - heap_increase: 0 - stable_memory_increase: 0 - btreemap: - total: - calls: 1 - instructions: 20444564541 - heap_increase: 1179 - stable_memory_increase: 0 - scopes: - 1. Encoding: - calls: 1 - instructions: 4701848503 - heap_increase: 159 - stable_memory_increase: 0 - 2. Decoding: - calls: 1 - instructions: 15742713839 - heap_increase: 1020 - stable_memory_increase: 0 - extra_args: - total: - calls: 1 - instructions: 3509512 - heap_increase: 0 - stable_memory_increase: 0 - scopes: {} - nns: - total: - calls: 1 - instructions: 26638344 - heap_increase: 2 - stable_memory_increase: 0 - scopes: - 0. Parsing: - calls: 1 - instructions: 17856363 - heap_increase: 2 - stable_memory_increase: 0 - 1. Encoding: - calls: 1 - instructions: 2091556 - heap_increase: 0 - stable_memory_increase: 0 - 2. Decoding: - calls: 1 - instructions: 5739905 - heap_increase: 0 - stable_memory_increase: 0 - nns_list_proposal: - total: - calls: 1 - instructions: 77377790 - heap_increase: 17 - stable_memory_increase: 0 - scopes: - 1. Encoding: - calls: 1 - instructions: 6878988 - heap_increase: 3 - stable_memory_increase: 0 - 2. Decoding: - calls: 1 - instructions: 70496590 - heap_increase: 14 - stable_memory_increase: 0 - option_list: - total: - calls: 1 - instructions: 36382258 - heap_increase: 2 - stable_memory_increase: 0 - scopes: - 1. Encoding: - calls: 1 - instructions: 8026927 - heap_increase: 0 - stable_memory_increase: 0 - 2. Decoding: - calls: 1 - instructions: 28352941 - heap_increase: 2 - stable_memory_increase: 0 - text: - total: - calls: 1 - instructions: 12085058 - heap_increase: 99 - stable_memory_increase: 0 - scopes: - 1. Encoding: - calls: 1 - instructions: 4204261 - heap_increase: 66 - stable_memory_increase: 0 - 2. Decoding: - calls: 1 - instructions: 7878453 - heap_increase: 33 - stable_memory_increase: 0 - variant_list: - total: - calls: 1 - instructions: 35275846 - heap_increase: 2 - stable_memory_increase: 0 - scopes: - 1. Encoding: - calls: 1 - instructions: 8224004 - heap_increase: 0 - stable_memory_increase: 0 - 2. Decoding: - calls: 1 - instructions: 27049630 - heap_increase: 2 - stable_memory_increase: 0 - vec_int16: - total: - calls: 1 - instructions: 1191174179 - heap_increase: 261 - stable_memory_increase: 0 - scopes: - 1. Encoding: - calls: 1 - instructions: 123695816 - heap_increase: 261 - stable_memory_increase: 0 - 2. Decoding: - calls: 1 - instructions: 1067476062 - heap_increase: 0 - stable_memory_increase: 0 - vec_nat: - total: - calls: 1 - instructions: 2585408968 - heap_increase: 172 - stable_memory_increase: 0 - scopes: - 1. Encoding: - calls: 1 - instructions: 1095177748 - heap_increase: 33 - stable_memory_increase: 0 - 2. Decoding: - calls: 1 - instructions: 1490228877 - heap_increase: 139 - stable_memory_increase: 0 - vec_nat32: - total: - calls: 1 - instructions: 1197467371 - heap_increase: 518 - stable_memory_increase: 0 - scopes: - 1. Encoding: - calls: 1 - instructions: 136280132 - heap_increase: 518 - stable_memory_increase: 0 - 2. Decoding: - calls: 1 - instructions: 1061184938 - heap_increase: 0 - stable_memory_increase: 0 - vec_nat64: - total: - calls: 1 - instructions: 1222634919 - heap_increase: 1031 - stable_memory_increase: 0 - scopes: - 1. Encoding: - calls: 1 - instructions: 161447366 - heap_increase: 1031 - stable_memory_increase: 0 - 2. Decoding: - calls: 1 - instructions: 1061185270 - heap_increase: 0 - stable_memory_increase: 0 -version: 0.4.1 From e7eeb2589d202918aafa170e96908b182f9bb17b Mon Sep 17 00:00:00 2001 From: Linwei Shang Date: Sun, 15 Mar 2026 14:21:54 -0400 Subject: [PATCH 3/3] bench: raise COST quota to 25M and use it consistently in vec_nat64 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit vec_u64 decoding costs ~409M instructions but the quota only gates memory-cost accounting, not wall time — 25M accommodates vec_nat64 while keeping all benchmarks on the same constant. Co-Authored-By: Claude Sonnet 4.6 --- rust/bench/bench.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/bench/bench.rs b/rust/bench/bench.rs index dbea5e46d..770d8aac2 100644 --- a/rust/bench/bench.rs +++ b/rust/bench/bench.rs @@ -6,7 +6,7 @@ use std::collections::BTreeMap; mod nns; const N: usize = 2097152; -const COST: usize = 20_000_000; +const COST: usize = 25_000_000; const SKIP: usize = 10_000; #[bench(raw)] @@ -83,7 +83,7 @@ fn vec_nat() -> BenchResult { fn vec_nat64() -> BenchResult { let vec: Vec = (0u64..N as u64).collect(); let mut config = DecoderConfig::new(); - config.set_decoding_quota(25_000_000).set_skipping_quota(SKIP); + config.set_decoding_quota(COST).set_skipping_quota(SKIP); bench_fn(|| { let bytes = { let _p = bench_scope("1. Encoding");