From 5a8c33610ef41854130c1fc2f25c2f14be348056 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Wed, 28 May 2025 13:41:12 +0200 Subject: [PATCH 01/19] add scopes --- benchmarks/Cargo.toml | 2 +- src/btreemap.rs | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/benchmarks/Cargo.toml b/benchmarks/Cargo.toml index 755d19bd..f04d02e6 100644 --- a/benchmarks/Cargo.toml +++ b/benchmarks/Cargo.toml @@ -10,7 +10,7 @@ canbench-rs.workspace = true candid.workspace = true ic-cdk.workspace = true ic-cdk-macros.workspace = true -ic-stable-structures = { path = "../", features = [] } +ic-stable-structures = { path = "../", features = ["bench_scope"] } maplit = "1.0.2" serde = "1.0" tiny-rng = "0.2.0" diff --git a/src/btreemap.rs b/src/btreemap.rs index b0a86620..473978dd 100644 --- a/src/btreemap.rs +++ b/src/btreemap.rs @@ -492,6 +492,9 @@ where /// key.to_bytes().len() <= max_size(Key) /// value.to_bytes().len() <= max_size(Value) pub fn insert(&mut self, key: K, value: V) -> Option { + #[cfg(feature = "bench_scope")] + let _p = canbench_rs::bench_scope("insert"); // May add significant overhead. + let value = value.to_bytes_checked().into_owned(); let root = if self.root_addr == NULL { @@ -544,6 +547,9 @@ where /// Inserts an entry into a node that is *not full*. fn insert_nonfull(&mut self, mut node: Node, key: K, value: Vec) -> Option> { + #[cfg(feature = "bench_scope")] + let _p = canbench_rs::bench_scope("insert_nonfull"); // May add significant overhead. + // We're guaranteed by the caller that the provided node is not full. assert!(!node.is_full()); From 4d8c480eac34eb8d485afc6a13ea2b7ab9c4cff5 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Mon, 2 Jun 2025 11:30:10 +0200 Subject: [PATCH 02/19] canbench main --- Cargo.lock | 6 ++---- Cargo.toml | 3 ++- scripts/ci_run_benchmark.sh | 3 ++- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5d1dc7c6..e4ee3c42 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -96,8 +96,7 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "canbench-rs" version = "0.1.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1c560e37bb75c6900e18e7d37174efaff09e266d138d9926e34f489d9d2f6a0" +source = "git+https://github.com/dfinity/canbench#7e0b420933608fffb2597b3bf666180a23be1a31" dependencies = [ "canbench-rs-macros", "candid", @@ -108,8 +107,7 @@ dependencies = [ [[package]] name = "canbench-rs-macros" version = "0.1.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "866a310ae95dfd273c2f1d17c8382d0d893c35851e9252cca98bd3a80a7e5635" +source = "git+https://github.com/dfinity/canbench#7e0b420933608fffb2597b3bf666180a23be1a31" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 9c5604dc..702dceda 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,7 +32,8 @@ bench_scope = ["dep:canbench-rs"] # May add significant overhead. members = ["benchmarks"] [workspace.dependencies] -canbench-rs = "0.1.15" +#canbench-rs = "0.1.15" +canbench-rs = { version = "0.1.15", git = "https://github.com/dfinity/canbench" } candid = "0.10.14" hex = "0.4.3" ic_principal = "0.1.1" diff --git a/scripts/ci_run_benchmark.sh b/scripts/ci_run_benchmark.sh index 2c771d2d..f0ed9e71 100644 --- a/scripts/ci_run_benchmark.sh +++ b/scripts/ci_run_benchmark.sh @@ -24,7 +24,8 @@ MAIN_BRANCH_RESULTS_FILE="$MAIN_BRANCH_DIR/$CANBENCH_RESULTS_FILE" CANBENCH_RESULTS_CSV_FILE="/tmp/canbench_results_${CANBENCH_JOB_NAME}.csv" # Install canbench. -cargo install --version 0.1.15 canbench +#cargo install --version 0.1.15 canbench +cargo install --git https://github.com/dfinity/canbench canbench # Verify that the canbench results file exists. if [ ! -f "$CANBENCH_RESULTS_FILE" ]; then From 4d9666655d59cf937b678ae588ba8a4848a72a54 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Wed, 4 Jun 2025 11:16:51 +0200 Subject: [PATCH 03/19] --locked --- scripts/ci_run_benchmark.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ci_run_benchmark.sh b/scripts/ci_run_benchmark.sh index f0ed9e71..672bd4a6 100644 --- a/scripts/ci_run_benchmark.sh +++ b/scripts/ci_run_benchmark.sh @@ -25,7 +25,7 @@ CANBENCH_RESULTS_CSV_FILE="/tmp/canbench_results_${CANBENCH_JOB_NAME}.csv" # Install canbench. #cargo install --version 0.1.15 canbench -cargo install --git https://github.com/dfinity/canbench canbench +cargo install --git https://github.com/dfinity/canbench canbench --locked # Verify that the canbench results file exists. if [ ! -f "$CANBENCH_RESULTS_FILE" ]; then From 1b08e378c79a5621080612a4fd5bcf63ac54ce7d Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Wed, 4 Jun 2025 11:32:29 +0200 Subject: [PATCH 04/19] . --- scripts/ci_run_benchmark.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ci_run_benchmark.sh b/scripts/ci_run_benchmark.sh index 672bd4a6..37dfd602 100644 --- a/scripts/ci_run_benchmark.sh +++ b/scripts/ci_run_benchmark.sh @@ -25,7 +25,7 @@ CANBENCH_RESULTS_CSV_FILE="/tmp/canbench_results_${CANBENCH_JOB_NAME}.csv" # Install canbench. #cargo install --version 0.1.15 canbench -cargo install --git https://github.com/dfinity/canbench canbench --locked +cargo install --git https://github.com/dfinity/canbench --locked canbench # Verify that the canbench results file exists. if [ ! -f "$CANBENCH_RESULTS_FILE" ]; then From fb00aa785ac294084e0ce2ad18af68f506644acc Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Wed, 4 Jun 2025 12:54:34 +0200 Subject: [PATCH 05/19] add scopes --- benchmarks/compare/canbench_results.yml | 278 +++++++++++++++++++++--- src/btreemap.rs | 7 +- src/btreemap/node.rs | 6 + src/btreemap/node/v2.rs | 141 +++++++----- 4 files changed, 345 insertions(+), 87 deletions(-) diff --git a/benchmarks/compare/canbench_results.yml b/benchmarks/compare/canbench_results.yml index f1c6ba48..24e7c92e 100644 --- a/benchmarks/compare/canbench_results.yml +++ b/benchmarks/compare/canbench_results.yml @@ -1,127 +1,349 @@ benches: read_chunks_btreemap_1: total: + start_instructions: 17235 calls: 1 - instructions: 1219162597 + instructions: 1219211020 heap_increase: 3233 stable_memory_increase: 1665 - scopes: {} + scopes: + node_load_v2: + start_instructions: 0 + calls: 1 + instructions: 18193641 + heap_increase: 0 + stable_memory_increase: 0 + node_load_v2_keys: + start_instructions: 0 + calls: 1 + instructions: 953 + heap_increase: 0 + stable_memory_increase: 0 + node_load_v2_values: + start_instructions: 0 + calls: 1 + instructions: 638 + heap_increase: 0 + stable_memory_increase: 0 read_chunks_btreemap_1k: total: + start_instructions: 17235 calls: 1 - instructions: 5414908676 - heap_increase: 1604 + instructions: 5525096947 + heap_increase: 1606 stable_memory_increase: 1665 - scopes: {} + scopes: + node_load_v2: + start_instructions: 0 + calls: 3806 + instructions: 393683288 + heap_increase: 0 + stable_memory_increase: 0 + node_load_v2_children: + start_instructions: 0 + calls: 2971 + instructions: 5385452 + heap_increase: 0 + stable_memory_increase: 0 + node_load_v2_keys: + start_instructions: 0 + calls: 3806 + instructions: 7390486 + heap_increase: 0 + stable_memory_increase: 0 + node_load_v2_values: + start_instructions: 0 + calls: 3806 + instructions: 8941646 + heap_increase: 0 + stable_memory_increase: 0 read_chunks_btreemap_1m: total: + start_instructions: 17235 calls: 1 - instructions: 133588820086 - heap_increase: 1892 + instructions: 298895577900 + heap_increase: 42863 stable_memory_increase: 3201 - scopes: {} + scopes: + node_load_v2: + start_instructions: 0 + calls: 7800012 + instructions: 88268773160 + heap_increase: 0 + stable_memory_increase: 0 + node_load_v2_children: + start_instructions: 0 + calls: 6966677 + instructions: 12091496391 + heap_increase: 0 + stable_memory_increase: 0 + node_load_v2_keys: + start_instructions: 0 + calls: 7800012 + instructions: 15072186082 + heap_increase: 0 + stable_memory_increase: 0 + node_load_v2_values: + start_instructions: 0 + calls: 7800012 + instructions: 11242964094 + heap_increase: 0 + stable_memory_increase: 0 read_chunks_stable_1: total: + start_instructions: 17235 calls: 1 - instructions: 812767514 + instructions: 812767320 heap_increase: 1601 stable_memory_increase: 1665 scopes: {} read_chunks_stable_1k: total: + start_instructions: 17235 calls: 1 - instructions: 525926853 + instructions: 525926659 heap_increase: 1600 stable_memory_increase: 1665 scopes: {} read_chunks_stable_1m: total: + start_instructions: 17235 calls: 1 - instructions: 1307625987 + instructions: 1307625793 heap_increase: 1892 stable_memory_increase: 1665 scopes: {} read_chunks_vec_1: total: + start_instructions: 17233 calls: 1 - instructions: 1363286620 + instructions: 1363286422 heap_increase: 3202 stable_memory_increase: 1665 scopes: {} read_chunks_vec_1k: total: + start_instructions: 17233 calls: 1 - instructions: 1378475066 + instructions: 1378474868 heap_increase: 3200 stable_memory_increase: 1665 scopes: {} read_chunks_vec_1m: total: + start_instructions: 17233 calls: 1 - instructions: 4721969149 + instructions: 4721968951 heap_increase: 3784 stable_memory_increase: 1665 scopes: {} write_chunks_btreemap_1: total: + start_instructions: 17235 calls: 1 - instructions: 1069803049 + instructions: 1069832141 heap_increase: 3233 stable_memory_increase: 1665 - scopes: {} + scopes: + insert: + start_instructions: 0 + calls: 1 + instructions: 781353807 + heap_increase: 1632 + stable_memory_increase: 1536 + node_save_v2: + start_instructions: 0 + calls: 1 + instructions: 361917969 + heap_increase: 31 + stable_memory_increase: 1536 + node_save_v2_keys: + start_instructions: 0 + calls: 1 + instructions: 988 + heap_increase: 0 + stable_memory_increase: 0 + node_save_v2_preload: + start_instructions: 0 + calls: 1 + instructions: 419 + heap_increase: 0 + stable_memory_increase: 0 + node_save_v2_values: + start_instructions: 0 + calls: 1 + instructions: 361911033 + heap_increase: 31 + stable_memory_increase: 1536 write_chunks_btreemap_1k: total: + start_instructions: 17235 calls: 1 - instructions: 4914919689 - heap_increase: 1604 + instructions: 4986997152 + heap_increase: 1606 stable_memory_increase: 1665 - scopes: {} + scopes: + insert: + start_instructions: 0 + calls: 1000 + instructions: 4690789008 + heap_increase: 6 + stable_memory_increase: 1536 + node_load_v2: + start_instructions: 0 + calls: 3868 + instructions: 536919993 + heap_increase: 0 + stable_memory_increase: 0 + node_load_v2_children: + start_instructions: 0 + calls: 2539 + instructions: 5221412 + heap_increase: 0 + stable_memory_increase: 0 + node_load_v2_keys: + start_instructions: 0 + calls: 3868 + instructions: 9679206 + heap_increase: 0 + stable_memory_increase: 0 + node_load_v2_values: + start_instructions: 0 + calls: 3868 + instructions: 12084334 + heap_increase: 0 + stable_memory_increase: 0 + node_save_v2: + start_instructions: 0 + calls: 1582 + instructions: 3562192802 + heap_increase: 4 + stable_memory_increase: 1536 + node_save_v2_keys: + start_instructions: 0 + calls: 1582 + instructions: 7925896 + heap_increase: 0 + stable_memory_increase: 0 + node_save_v2_preload: + start_instructions: 0 + calls: 1582 + instructions: 1293052823 + heap_increase: 4 + stable_memory_increase: 0 + node_save_v2_values: + start_instructions: 0 + calls: 1582 + instructions: 2103983593 + heap_increase: 0 + stable_memory_increase: 1536 write_chunks_btreemap_1m: total: + start_instructions: 17235 calls: 1 - instructions: 89822427791 - heap_increase: 1892 + instructions: 185123236723 + heap_increase: 42863 stable_memory_increase: 3201 - scopes: {} + scopes: + insert: + start_instructions: 0 + calls: 1000000 + instructions: 173028062117 + heap_increase: 31065 + stable_memory_increase: 3072 + node_load_v2: + start_instructions: 0 + calls: 7728110 + instructions: 102535863220 + heap_increase: 30737 + stable_memory_increase: 0 + node_load_v2_children: + start_instructions: 0 + calls: 6394781 + instructions: 13940598859 + heap_increase: 0 + stable_memory_increase: 0 + node_load_v2_keys: + start_instructions: 0 + calls: 7728110 + instructions: 20083873931 + heap_increase: 0 + stable_memory_increase: 0 + node_load_v2_values: + start_instructions: 0 + calls: 7728110 + instructions: 15372493490 + heap_increase: 0 + stable_memory_increase: 0 + node_save_v2: + start_instructions: 0 + calls: 1599964 + instructions: 42877765831 + heap_increase: 214 + stable_memory_increase: 384 + node_save_v2_keys: + start_instructions: 0 + calls: 1599964 + instructions: 8171886346 + heap_increase: 0 + stable_memory_increase: 0 + node_save_v2_preload: + start_instructions: 0 + calls: 1599964 + instructions: 8340186694 + heap_increase: 0 + stable_memory_increase: 0 + node_save_v2_values: + start_instructions: 0 + calls: 1599964 + instructions: 9771367318 + heap_increase: 0 + stable_memory_increase: 384 write_chunks_stable_1: total: + start_instructions: 17235 calls: 1 - instructions: 418914609 + instructions: 418914513 heap_increase: 1601 stable_memory_increase: 1665 scopes: {} write_chunks_stable_1k: total: + start_instructions: 17235 calls: 1 - instructions: 420017351 + instructions: 420017255 heap_increase: 1600 stable_memory_increase: 1665 scopes: {} write_chunks_stable_1m: total: + start_instructions: 17235 calls: 1 - instructions: 1076987632 + instructions: 1076987536 heap_increase: 1892 stable_memory_increase: 1665 scopes: {} write_chunks_vec_1: total: + start_instructions: 17234 calls: 1 - instructions: 1257791061 + instructions: 1257790961 heap_increase: 3202 stable_memory_increase: 1665 scopes: {} write_chunks_vec_1k: total: + start_instructions: 17234 calls: 1 - instructions: 1272012769 + instructions: 1272012669 heap_increase: 3200 stable_memory_increase: 1665 scopes: {} write_chunks_vec_1m: total: + start_instructions: 17234 calls: 1 - instructions: 3712427406 + instructions: 3712427306 heap_increase: 3784 stable_memory_increase: 1665 scopes: {} diff --git a/src/btreemap.rs b/src/btreemap.rs index 473978dd..9828165e 100644 --- a/src/btreemap.rs +++ b/src/btreemap.rs @@ -547,8 +547,8 @@ where /// Inserts an entry into a node that is *not full*. fn insert_nonfull(&mut self, mut node: Node, key: K, value: Vec) -> Option> { - #[cfg(feature = "bench_scope")] - let _p = canbench_rs::bench_scope("insert_nonfull"); // May add significant overhead. + // #[cfg(feature = "bench_scope")] + // let _p = canbench_rs::bench_scope("insert_nonfull"); // May add significant overhead. // We're guaranteed by the caller that the provided node is not full. assert!(!node.is_full()); @@ -632,6 +632,9 @@ where /// ``` /// fn split_child(&mut self, node: &mut Node, full_child_idx: usize) { + // #[cfg(feature = "bench_scope")] + // let _p = canbench_rs::bench_scope("split_child"); // May add significant overhead. + // The node must not be full. assert!(!node.is_full()); diff --git a/src/btreemap/node.rs b/src/btreemap/node.rs index d4096918..80b594eb 100644 --- a/src/btreemap/node.rs +++ b/src/btreemap/node.rs @@ -163,6 +163,9 @@ impl Node { (key, value): Entry, memory: &M, ) -> Entry { + // #[cfg(feature = "bench_scope")] + // let _p = canbench_rs::bench_scope("swap_entry"); // May add significant overhead. + let (old_key, old_value) = core::mem::replace( &mut self.keys_and_encoded_values[idx], (LazyKey::by_value(key), LazyValue::by_value(value)), @@ -453,6 +456,9 @@ impl Node { /// returned, containing the index where a matching key could be inserted /// while maintaining sorted order. pub fn search(&self, key: &K, memory: &M) -> Result { + // #[cfg(feature = "bench_scope")] + // let _p = canbench_rs::bench_scope("search"); // May add significant overhead. + self.keys_and_encoded_values .binary_search_by_key(&key, |entry| self.get_key(entry, memory)) } diff --git a/src/btreemap/node/v2.rs b/src/btreemap/node/v2.rs index dab0bba2..7c55af71 100644 --- a/src/btreemap/node/v2.rs +++ b/src/btreemap/node/v2.rs @@ -140,6 +140,9 @@ impl Node { offset += ENTRIES_OFFSET; let mut children = vec![]; if node_type == NodeType::Internal { + #[cfg(feature = "bench_scope")] + let _p = canbench_rs::bench_scope("node_load_v2_children"); // May add significant overhead. + // The number of children is equal to the number of entries + 1. children.reserve_exact(num_entries + 1); for _ in 0..num_entries + 1 { @@ -154,41 +157,50 @@ impl Node { let mut keys_encoded_values = Vec::with_capacity(num_entries); let mut buf = vec![]; - for _ in 0..num_entries { - let key_offset = Bytes::from(offset.get()); - - // Get key size. - let key_size = if K::BOUND.is_fixed_size() { - K::BOUND.max_size() - } else { - let size = read_u32(&reader, offset); - offset += U32_SIZE; - size - }; - - // Eager-load small keys, defer large ones. - let key = if key_size <= EAGER_LOAD_KEY_SIZE_THRESHOLD { - read_to_vec( - &reader, - Address::from(offset.get()), - &mut buf, - key_size as usize, - ); - LazyKey::by_value(K::from_bytes(Cow::Borrowed(&buf))) - } else { - LazyKey::by_ref(key_offset) - }; - - offset += Bytes::from(key_size); - keys_encoded_values.push((key, LazyValue::by_ref(Bytes::from(0_u64)))); + { + #[cfg(feature = "bench_scope")] + let _p = canbench_rs::bench_scope("node_load_v2_keys"); // May add significant overhead. + + for _ in 0..num_entries { + let key_offset = Bytes::from(offset.get()); + + // Get key size. + let key_size = if K::BOUND.is_fixed_size() { + K::BOUND.max_size() + } else { + let size = read_u32(&reader, offset); + offset += U32_SIZE; + size + }; + + // Eager-load small keys, defer large ones. + let key = if key_size <= EAGER_LOAD_KEY_SIZE_THRESHOLD { + read_to_vec( + &reader, + Address::from(offset.get()), + &mut buf, + key_size as usize, + ); + LazyKey::by_value(K::from_bytes(Cow::Borrowed(&buf))) + } else { + LazyKey::by_ref(key_offset) + }; + + offset += Bytes::from(key_size); + keys_encoded_values.push((key, LazyValue::by_ref(Bytes::from(0_u64)))); + } } // Load the values - for (_key, value) in keys_encoded_values.iter_mut() { - // Load the values lazily. - *value = LazyValue::by_ref(Bytes::from(offset.get())); - let value_size = read_u32(&reader, offset) as usize; - offset += U32_SIZE + Bytes::from(value_size as u64); + { + #[cfg(feature = "bench_scope")] + let _p = canbench_rs::bench_scope("node_load_v2_values"); // May add significant overhead. + for (_key, value) in keys_encoded_values.iter_mut() { + // Load the values lazily. + *value = LazyValue::by_ref(Bytes::from(offset.get())); + let value_size = read_u32(&reader, offset) as usize; + offset += U32_SIZE + Bytes::from(value_size as u64); + } } Self { @@ -209,10 +221,15 @@ impl Node { let page_size = self.version.page_size().get(); assert!(page_size >= MINIMUM_PAGE_SIZE); - // Load all the entries. One pass is required to load all entries; - // results are not stored to avoid unnecessary allocations. - for i in 0..self.keys_and_encoded_values.len() { - self.entry(i, allocator.memory()); + { + #[cfg(feature = "bench_scope")] + let _p = canbench_rs::bench_scope("node_save_v2_preload"); // May add significant overhead. + + // Load all the entries. One pass is required to load all entries; + // results are not stored to avoid unnecessary allocations. + for i in 0..self.keys_and_encoded_values.len() { + self.entry(i, allocator.memory()); + } } // Initialize a NodeWriter. The NodeWriter takes care of allocating/deallocating @@ -250,32 +267,42 @@ impl Node { offset += Address::size(); } - // Write the keys. - for i in 0..self.keys_and_encoded_values.len() { - let key = self.key(i, writer.memory()); - let key_bytes = key.to_bytes_checked(); + { + #[cfg(feature = "bench_scope")] + let _p = canbench_rs::bench_scope("node_save_v2_keys"); // May add significant overhead. - // Write the size of the key if it isn't fixed in size. - if !K::BOUND.is_fixed_size() { - writer.write_u32(offset, key_bytes.len() as u32); - offset += U32_SIZE; - } + // Write the keys. + for i in 0..self.keys_and_encoded_values.len() { + let key = self.key(i, writer.memory()); + let key_bytes = key.to_bytes_checked(); - // Write the key. - writer.write(offset, key_bytes.borrow()); - offset += Bytes::from(key_bytes.len()); + // Write the size of the key if it isn't fixed in size. + if !K::BOUND.is_fixed_size() { + writer.write_u32(offset, key_bytes.len() as u32); + offset += U32_SIZE; + } + + // Write the key. + writer.write(offset, key_bytes.borrow()); + offset += Bytes::from(key_bytes.len()); + } } - // Write the values. - for i in 0..self.keys_and_encoded_values.len() { - // Write the size of the value. - let value = self.value(i, writer.memory()); - writer.write_u32(offset, value.len() as u32); - offset += U32_SIZE; + { + #[cfg(feature = "bench_scope")] + let _p = canbench_rs::bench_scope("node_save_v2_values"); // May add significant overhead. - // Write the value. - writer.write(offset, value); - offset += Bytes::from(value.len()); + // Write the values. + for i in 0..self.keys_and_encoded_values.len() { + // Write the size of the value. + let value = self.value(i, writer.memory()); + writer.write_u32(offset, value.len() as u32); + offset += U32_SIZE; + + // Write the value. + writer.write(offset, value); + offset += Bytes::from(value.len()); + } } self.overflows = writer.finish(); From 4c2331e20d35184ed4a5004c0c8d25e4ff42319d Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Wed, 4 Jun 2025 13:42:59 +0200 Subject: [PATCH 06/19] . --- src/btreemap/node.rs | 2 +- src/btreemap/node/io.rs | 8 ++++++++ src/btreemap/node/v2.rs | 11 +++++++++++ src/lib.rs | 10 ++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/btreemap/node.rs b/src/btreemap/node.rs index 80b594eb..7cc81ae9 100644 --- a/src/btreemap/node.rs +++ b/src/btreemap/node.rs @@ -1,6 +1,6 @@ use crate::{ btreemap::Allocator, - read_struct, read_to_vec, read_u32, read_u64, + read_struct, read_to_vec, read_u32, read_u64, read_u64_vec, storable::Storable, types::{Address, Bytes}, write, write_struct, write_u32, Memory, diff --git a/src/btreemap/node/io.rs b/src/btreemap/node/io.rs index 9061f9fb..97f2e2eb 100644 --- a/src/btreemap/node/io.rs +++ b/src/btreemap/node/io.rs @@ -283,6 +283,14 @@ impl<'a, M: Memory> NodeWriter<'a, M> { self.write(offset, &val.to_le_bytes()); } + pub fn write_u64_vec(&mut self, offset: Address, values: &[u64]) { + let mut buf = vec![0u8; values.len() * 8]; + for (i, &value) in values.iter().enumerate() { + buf[i * 8..(i + 1) * 8].copy_from_slice(&value.to_le_bytes()); + } + self.write(offset, &buf); + } + pub fn write_struct(&mut self, t: &T, addr: Address) { let slice = unsafe { core::slice::from_raw_parts(t as *const _ as *const u8, core::mem::size_of::()) diff --git a/src/btreemap/node/v2.rs b/src/btreemap/node/v2.rs index 7c55af71..d207e1bd 100644 --- a/src/btreemap/node/v2.rs +++ b/src/btreemap/node/v2.rs @@ -150,6 +150,12 @@ impl Node { offset += Address::size(); children.push(child); } + + // let total_children = num_entries + 1; + // children.reserve_exact(total_children); + // let u64s = read_u64_vec(&reader, offset, total_children); + // children.extend(u64s.into_iter().map(Address::from)); + // offset += Address::size() * Bytes::from(total_children as u64); } // Load the keys (eagerly if small). @@ -266,6 +272,11 @@ impl Node { writer.write_u64(offset, child.get()); offset += Address::size(); } + // writer.write_u64_vec( + // offset, + // &self.children.iter().map(|c| c.get()).collect::>(), + // ); + // offset += Address::size() * Bytes::from(self.children.len() as u64); { #[cfg(feature = "bench_scope")] diff --git a/src/lib.rs b/src/lib.rs index e528dd4b..64432e2c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -118,6 +118,16 @@ fn read_u64(m: &M, addr: Address) -> u64 { u64::from_le_bytes(buf) } +/// Reads `count` consecutive u64 values from memory starting at `addr` into a Vec. +/// This is more efficient than calling `read_u64` in a loop. +fn read_u64_vec(m: &M, addr: Address, count: usize) -> std::vec::Vec { + let mut buf = vec![0u8; count * 8]; + m.read(addr.get(), &mut buf); + buf.chunks_exact(8) + .map(|chunk| u64::from_le_bytes(chunk.try_into().unwrap())) + .collect() +} + /// Writes a single 32-bit integer encoded as little-endian. fn write_u32(m: &M, addr: Address, val: u32) { write(m, addr.get(), &val.to_le_bytes()); From 4f786303eb4955c1548da5a64074e74e57c4ec39 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Wed, 4 Jun 2025 14:37:24 +0200 Subject: [PATCH 07/19] swap_value --- src/btreemap.rs | 14 ++++++-------- src/btreemap/node.rs | 8 ++++++++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/btreemap.rs b/src/btreemap.rs index 9828165e..10bd658e 100644 --- a/src/btreemap.rs +++ b/src/btreemap.rs @@ -509,8 +509,8 @@ where // Check if the key already exists in the root. if let Ok(idx) = root.search(&key, self.memory()) { - // The key exists. Overwrite it and return the previous value. - let (_, previous_value) = root.swap_entry(idx, (key, value), self.memory()); + // Key found, replace its value and return the old one. + let previous_value = root.swap_value(idx, value, self.memory()); self.save_node(&mut root); return Some(V::from_bytes(Cow::Owned(previous_value))); } @@ -556,9 +556,8 @@ where // Look for the key in the node. match node.search(&key, self.memory()) { Ok(idx) => { - // The key is already in the node. - // Overwrite it and return the previous value. - let (_, previous_value) = node.swap_entry(idx, (key, value), self.memory()); + // Key found, replace its value and return the old one. + let previous_value = node.swap_value(idx, value, self.memory()); self.save_node(&mut node); Some(previous_value) @@ -588,9 +587,8 @@ where if child.is_full() { // Check if the key already exists in the child. if let Ok(idx) = child.search(&key, self.memory()) { - // The key exists. Overwrite it and return the previous value. - let (_, previous_value) = - child.swap_entry(idx, (key, value), self.memory()); + // Key found, replace its value and return the old one. + let previous_value = child.swap_value(idx, value, self.memory()); self.save_node(&mut child); return Some(previous_value); } diff --git a/src/btreemap/node.rs b/src/btreemap/node.rs index 7cc81ae9..c0a55332 100644 --- a/src/btreemap/node.rs +++ b/src/btreemap/node.rs @@ -156,6 +156,14 @@ impl Node { self.keys_and_encoded_values.len() >= CAPACITY } + /// Swaps the value at index `idx` with the given value, returning the old value. + /// The key is left untouched. + pub fn swap_value(&mut self, idx: usize, new_value: Vec, memory: &M) -> Vec { + let entry = &mut self.keys_and_encoded_values[idx]; + let old_value = core::mem::replace(&mut entry.1, LazyValue::by_value(new_value)); + self.extract_value(old_value, memory) + } + /// Swaps the entry at index `idx` with the given entry, returning the old entry. pub fn swap_entry( &mut self, From a57f58cd5cdbe3a0d1dcd3960a3b3194f4538dea Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Wed, 4 Jun 2025 14:53:02 +0200 Subject: [PATCH 08/19] . --- src/btreemap.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/btreemap.rs b/src/btreemap.rs index 10bd658e..79472858 100644 --- a/src/btreemap.rs +++ b/src/btreemap.rs @@ -510,9 +510,9 @@ where // Check if the key already exists in the root. if let Ok(idx) = root.search(&key, self.memory()) { // Key found, replace its value and return the old one. - let previous_value = root.swap_value(idx, value, self.memory()); - self.save_node(&mut root); - return Some(V::from_bytes(Cow::Owned(previous_value))); + return Some(V::from_bytes(Cow::Owned( + self.swap_value(&mut root, idx, value), + ))); } // If the root is full, we need to introduce a new node as the root. @@ -557,10 +557,7 @@ where match node.search(&key, self.memory()) { Ok(idx) => { // Key found, replace its value and return the old one. - let previous_value = node.swap_value(idx, value, self.memory()); - - self.save_node(&mut node); - Some(previous_value) + Some(self.swap_value(&mut node, idx, value)) } Err(idx) => { // The key isn't in the node. `idx` is where that key should be inserted. @@ -588,9 +585,7 @@ where // Check if the key already exists in the child. if let Ok(idx) = child.search(&key, self.memory()) { // Key found, replace its value and return the old one. - let previous_value = child.swap_value(idx, value, self.memory()); - self.save_node(&mut child); - return Some(previous_value); + return Some(self.swap_value(&mut child, idx, value)); } // The child is full. Split the child. @@ -1288,6 +1283,12 @@ where node.save(self.allocator_mut()); } + fn swap_value(&mut self, node: &mut Node, idx: usize, new_value: Vec) -> Vec { + let old_value = node.swap_value(idx, new_value, self.memory()); + self.save_node(node); + old_value + } + /// Saves the map to memory. fn save_header(&self) { let header = BTreeHeader { From 2b7ecaf7fd3b012b29552cc372e0ef92cc354c16 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Thu, 5 Jun 2025 09:37:06 +0200 Subject: [PATCH 09/19] cleanup --- src/btreemap.rs | 6 ------ src/btreemap/node.rs | 6 ------ 2 files changed, 12 deletions(-) diff --git a/src/btreemap.rs b/src/btreemap.rs index a9094318..c8e08481 100644 --- a/src/btreemap.rs +++ b/src/btreemap.rs @@ -547,9 +547,6 @@ where /// Inserts an entry into a node that is *not full*. fn insert_nonfull(&mut self, mut node: Node, key: K, value: Vec) -> Option> { - // #[cfg(feature = "bench_scope")] - // let _p = canbench_rs::bench_scope("insert_nonfull"); // May add significant overhead. - // We're guaranteed by the caller that the provided node is not full. assert!(!node.is_full()); @@ -625,9 +622,6 @@ where /// ``` /// fn split_child(&mut self, node: &mut Node, full_child_idx: usize) { - // #[cfg(feature = "bench_scope")] - // let _p = canbench_rs::bench_scope("split_child"); // May add significant overhead. - // The node must not be full. assert!(!node.is_full()); diff --git a/src/btreemap/node.rs b/src/btreemap/node.rs index 47277510..f7e4f85c 100644 --- a/src/btreemap/node.rs +++ b/src/btreemap/node.rs @@ -172,9 +172,6 @@ impl Node { (key, value): Entry, memory: &M, ) -> Entry { - // #[cfg(feature = "bench_scope")] - // let _p = canbench_rs::bench_scope("swap_entry"); // May add significant overhead. - let (old_key, old_value) = core::mem::replace( &mut self.keys_and_encoded_values[idx], (LazyKey::by_value(key), LazyValue::by_value(value)), @@ -465,9 +462,6 @@ impl Node { /// returned, containing the index where a matching key could be inserted /// while maintaining sorted order. pub fn search(&self, key: &K, memory: &M) -> Result { - // #[cfg(feature = "bench_scope")] - // let _p = canbench_rs::bench_scope("search"); // May add significant overhead. - self.keys_and_encoded_values .binary_search_by_key(&key, |entry| self.get_key(entry, memory)) } From 3b77d14ca3d9c5f4c24ffbe1ca02b2498e3b9055 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Thu, 5 Jun 2025 09:41:19 +0200 Subject: [PATCH 10/19] read children vec --- src/btreemap/node/v2.rs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/btreemap/node/v2.rs b/src/btreemap/node/v2.rs index d207e1bd..55bb14f3 100644 --- a/src/btreemap/node/v2.rs +++ b/src/btreemap/node/v2.rs @@ -144,18 +144,19 @@ impl Node { let _p = canbench_rs::bench_scope("node_load_v2_children"); // May add significant overhead. // The number of children is equal to the number of entries + 1. - children.reserve_exact(num_entries + 1); - for _ in 0..num_entries + 1 { - let child = Address::from(read_u64(&reader, offset)); - offset += Address::size(); - children.push(child); - } - - // let total_children = num_entries + 1; - // children.reserve_exact(total_children); - // let u64s = read_u64_vec(&reader, offset, total_children); - // children.extend(u64s.into_iter().map(Address::from)); - // offset += Address::size() * Bytes::from(total_children as u64); + // children.reserve_exact(num_entries + 1); + // for _ in 0..num_entries + 1 { + // let child = Address::from(read_u64(&reader, offset)); + // offset += Address::size(); + // children.push(child); + // } + + let total_children = num_entries + 1; + children = read_u64_vec(&reader, offset, total_children) + .into_iter() + .map(Address::from) + .collect(); + offset += Address::size() * Bytes::from(total_children as u64); } // Load the keys (eagerly if small). From c984f5954fa54f6907f816aa8b06240415e42104 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Thu, 5 Jun 2025 09:57:27 +0200 Subject: [PATCH 11/19] rename --- src/btreemap/node.rs | 54 +++++++++++++++++------------------------ src/btreemap/node/v1.rs | 22 ++++++++--------- src/btreemap/node/v2.rs | 18 +++++++------- 3 files changed, 42 insertions(+), 52 deletions(-) diff --git a/src/btreemap/node.rs b/src/btreemap/node.rs index f7e4f85c..6674af06 100644 --- a/src/btreemap/node.rs +++ b/src/btreemap/node.rs @@ -54,7 +54,7 @@ pub struct Node { address: Address, // List of tuples consisting of a key and the encoded value. // INVARIANT: the list is sorted by key. - keys_and_encoded_values: Vec>, + entries: Vec>, // For the key at position I, children[I] points to the left // child of this key and children[I + 1] points to the right child. children: Vec
, @@ -108,10 +108,7 @@ impl Node { pub fn get_max(&self, memory: &M) -> Entry { match self.node_type { NodeType::Leaf => { - let last_entry = self - .keys_and_encoded_values - .last() - .expect("A node can never be empty"); + let last_entry = self.entries.last().expect("A node can never be empty"); ( self.get_key(last_entry, memory).clone(), self.get_value(last_entry, memory).to_vec(), @@ -153,15 +150,12 @@ impl Node { /// Returns true if the node cannot store anymore entries, false otherwise. pub fn is_full(&self) -> bool { - self.keys_and_encoded_values.len() >= CAPACITY + self.entries.len() >= CAPACITY } /// Replaces the value at `idx` and returns the old one. pub fn swap_value(&mut self, idx: usize, new: Vec, memory: &M) -> Vec { - let old = core::mem::replace( - &mut self.keys_and_encoded_values[idx].1, - LazyValue::by_value(new), - ); + let old = core::mem::replace(&mut self.entries[idx].1, LazyValue::by_value(new)); self.extract_value(old, memory) } @@ -173,7 +167,7 @@ impl Node { memory: &M, ) -> Entry { let (old_key, old_value) = core::mem::replace( - &mut self.keys_and_encoded_values[idx], + &mut self.entries[idx], (LazyKey::by_value(key), LazyValue::by_value(value)), ); ( @@ -202,13 +196,13 @@ impl Node { /// Returns a reference to the key at the specified index. #[inline(always)] pub fn key(&self, idx: usize, memory: &M) -> &K { - self.get_key(&self.keys_and_encoded_values[idx], memory) + self.get_key(&self.entries[idx], memory) } /// Returns a reference to the encoded value at the specified index. #[inline(always)] pub fn value(&self, idx: usize, memory: &M) -> &[u8] { - self.get_value(&self.keys_and_encoded_values[idx], memory) + self.get_value(&self.entries[idx], memory) } /// Extracts the contents of key (by loading it first if it's not loaded yet). @@ -312,14 +306,14 @@ impl Node { /// Inserts a new entry at the specified index. pub fn insert_entry(&mut self, idx: usize, (key, value): Entry) { - self.keys_and_encoded_values + self.entries .insert(idx, (LazyKey::by_value(key), LazyValue::by_value(value))); } /// Returns the entry at the specified index while consuming this node. pub fn into_entry(mut self, idx: usize, memory: &M) -> Entry { - let keys_and_encoded_values = core::mem::take(&mut self.keys_and_encoded_values); - let (key, value) = keys_and_encoded_values.into_iter().nth(idx).unwrap(); + let entries = core::mem::take(&mut self.entries); + let (key, value) = entries.into_iter().nth(idx).unwrap(); ( self.extract_key(key, memory), self.extract_value(value, memory), @@ -328,7 +322,7 @@ impl Node { /// Removes the entry at the specified index. pub fn remove_entry(&mut self, idx: usize, memory: &M) -> Entry { - let (key, value) = self.keys_and_encoded_values.remove(idx); + let (key, value) = self.entries.remove(idx); ( self.extract_key(key, memory), self.extract_value(value, memory), @@ -337,7 +331,7 @@ impl Node { /// Adds a new entry at the back of the node. pub fn push_entry(&mut self, (key, value): Entry) { - self.keys_and_encoded_values + self.entries .push((LazyKey::by_value(key), LazyValue::by_value(value))); } @@ -348,10 +342,7 @@ impl Node { return None; } - let (key, value) = self - .keys_and_encoded_values - .pop() - .expect("node must not be empty"); + let (key, value) = self.entries.pop().expect("node must not be empty"); Some(( self.extract_key(key, memory), @@ -391,7 +382,7 @@ impl Node { Self::append(&mut source, self, median, allocator.memory()); // Move the entries and children into self. - self.keys_and_encoded_values = core::mem::take(&mut source.keys_and_encoded_values); + self.entries = core::mem::take(&mut source.entries); self.children = core::mem::take(&mut source.children); } @@ -420,27 +411,26 @@ impl Node { a.push_entry(median); - a.keys_and_encoded_values - .append(&mut b.keys_and_encoded_values); + a.entries.append(&mut b.entries); // Move the children (if any exist). a.children.append(&mut b.children); // Assert postconditions. - assert_eq!(b.keys_and_encoded_values.len(), 0); + assert_eq!(b.entries.len(), 0); assert_eq!(b.children.len(), 0); } #[cfg(test)] pub fn entries(&self, memory: &M) -> Vec> { - (0..self.keys_and_encoded_values.len()) + (0..self.entries.len()) .map(|i| (self.key(i, memory).clone(), self.value(i, memory).to_vec())) .collect() } #[cfg(test)] pub fn keys(&self, memory: &M) -> Vec<&K> { - (0..self.keys_and_encoded_values.len()) + (0..self.entries.len()) .map(|i| self.key(i, memory)) .collect() } @@ -452,7 +442,7 @@ impl Node { /// Returns the number of entries in the node. pub fn entries_len(&self) -> usize { - self.keys_and_encoded_values.len() + self.entries.len() } /// Searches for the key in the node's entries. @@ -462,7 +452,7 @@ impl Node { /// returned, containing the index where a matching key could be inserted /// while maintaining sorted order. pub fn search(&self, key: &K, memory: &M) -> Result { - self.keys_and_encoded_values + self.entries .binary_search_by_key(&key, |entry| self.get_key(entry, memory)) } @@ -475,7 +465,7 @@ impl Node { /// Returns true if the node is at the minimum required size, false otherwise. pub fn at_minimum(&self) -> bool { - self.keys_and_encoded_values.len() < B + self.entries.len() < B } /// Returns true if an entry can be removed without having to merge it into another node @@ -494,7 +484,7 @@ impl Node { } // Move the entries and children above the median into the new sibling. - sibling.keys_and_encoded_values = self.keys_and_encoded_values.split_off(B); + sibling.entries = self.entries.split_off(B); if self.node_type == NodeType::Internal { sibling.children = self.children.split_off(B); } diff --git a/src/btreemap/node/v1.rs b/src/btreemap/node/v1.rs index 63e13327..2f9bcd05 100644 --- a/src/btreemap/node/v1.rs +++ b/src/btreemap/node/v1.rs @@ -48,7 +48,7 @@ impl Node { Node { address, node_type, - keys_and_encoded_values: vec![], + entries: vec![], children: vec![], version: Version::V1(page_size), overflows: Vec::with_capacity(0), @@ -67,7 +67,7 @@ impl Node { let _p = canbench_rs::bench_scope("node_load_v1"); // May add significant overhead. // Load the entries. - let mut keys_encoded_values = Vec::with_capacity(header.num_entries as usize); + let mut entries = Vec::with_capacity(header.num_entries as usize); let mut offset = NodeHeader::size(); for _ in 0..header.num_entries { let key_offset = offset; @@ -80,7 +80,7 @@ impl Node { let value = LazyValue::by_ref(value_offset); offset += Bytes::from(max_value_size); - keys_encoded_values.push((key, value)); + entries.push((key, value)); } // Load children if this is an internal node. @@ -94,12 +94,12 @@ impl Node { children.push(child); } - assert_eq!(children.len(), keys_encoded_values.len() + 1); + assert_eq!(children.len(), entries.len() + 1); } Self { address, - keys_and_encoded_values: keys_encoded_values, + entries, children, node_type: match header.node_type { LEAF_NODE_TYPE => NodeType::Leaf, @@ -123,16 +123,16 @@ impl Node { assert!(self.children.is_empty()); } NodeType::Internal => { - assert_eq!(self.children.len(), self.keys_and_encoded_values.len() + 1); + assert_eq!(self.children.len(), self.entries.len() + 1); } }; // We should never be saving an empty node. - assert!(!self.keys_and_encoded_values.is_empty() || !self.children.is_empty()); + assert!(!self.entries.is_empty() || !self.children.is_empty()); // Assert entries are sorted in strictly increasing order. assert!(self - .keys_and_encoded_values + .entries .windows(2) .all(|arr| self.get_key(&arr[0], memory) < self.get_key(&arr[1], memory))); @@ -151,7 +151,7 @@ impl Node { NodeType::Leaf => LEAF_NODE_TYPE, NodeType::Internal => INTERNAL_NODE_TYPE, }, - num_entries: self.keys_and_encoded_values.len() as u16, + num_entries: self.entries.len() as u16, }; write_struct(&header, self.address, memory); @@ -160,12 +160,12 @@ impl Node { // Load all the entries. This is necessary so that we don't overwrite referenced // entries when writing the entries to the node. - for i in 0..self.keys_and_encoded_values.len() { + for i in 0..self.entries.len() { self.entry(i, memory); } // Write the entries. - for i in 0..self.keys_and_encoded_values.len() { + for i in 0..self.entries.len() { // Write the size of the key. let key_bytes = self.key(i, memory).to_bytes_checked(); write_u32(memory, self.address + offset, key_bytes.len() as u32); diff --git a/src/btreemap/node/v2.rs b/src/btreemap/node/v2.rs index 55bb14f3..2bea8eab 100644 --- a/src/btreemap/node/v2.rs +++ b/src/btreemap/node/v2.rs @@ -98,7 +98,7 @@ impl Node { address, node_type, version: Version::V2(page_size), - keys_and_encoded_values: vec![], + entries: vec![], children: vec![], overflows: Vec::with_capacity(0), } @@ -161,7 +161,7 @@ impl Node { // Load the keys (eagerly if small). const EAGER_LOAD_KEY_SIZE_THRESHOLD: u32 = 16; - let mut keys_encoded_values = Vec::with_capacity(num_entries); + let mut entries = Vec::with_capacity(num_entries); let mut buf = vec![]; { @@ -194,7 +194,7 @@ impl Node { }; offset += Bytes::from(key_size); - keys_encoded_values.push((key, LazyValue::by_ref(Bytes::from(0_u64)))); + entries.push((key, LazyValue::by_ref(Bytes::from(0_u64)))); } } @@ -202,7 +202,7 @@ impl Node { { #[cfg(feature = "bench_scope")] let _p = canbench_rs::bench_scope("node_load_v2_values"); // May add significant overhead. - for (_key, value) in keys_encoded_values.iter_mut() { + for (_key, value) in entries.iter_mut() { // Load the values lazily. *value = LazyValue::by_ref(Bytes::from(offset.get())); let value_size = read_u32(&reader, offset) as usize; @@ -212,7 +212,7 @@ impl Node { Self { address, - keys_and_encoded_values: keys_encoded_values, + entries, children, node_type, version: Version::V2(page_size), @@ -234,7 +234,7 @@ impl Node { // Load all the entries. One pass is required to load all entries; // results are not stored to avoid unnecessary allocations. - for i in 0..self.keys_and_encoded_values.len() { + for i in 0..self.entries.len() { self.entry(i, allocator.memory()); } } @@ -257,7 +257,7 @@ impl Node { NodeType::Leaf => LEAF_NODE_TYPE, NodeType::Internal => INTERNAL_NODE_TYPE, }, - num_entries: self.keys_and_encoded_values.len() as u16, + num_entries: self.entries.len() as u16, }; writer.write_struct(&header, offset); @@ -284,7 +284,7 @@ impl Node { let _p = canbench_rs::bench_scope("node_save_v2_keys"); // May add significant overhead. // Write the keys. - for i in 0..self.keys_and_encoded_values.len() { + for i in 0..self.entries.len() { let key = self.key(i, writer.memory()); let key_bytes = key.to_bytes_checked(); @@ -305,7 +305,7 @@ impl Node { let _p = canbench_rs::bench_scope("node_save_v2_values"); // May add significant overhead. // Write the values. - for i in 0..self.keys_and_encoded_values.len() { + for i in 0..self.entries.len() { // Write the size of the value. let value = self.value(i, writer.memory()); writer.write_u32(offset, value.len() as u32); From c9699d9d622f8bf5bd1bdaae236809b239fbbd5d Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Thu, 5 Jun 2025 10:05:18 +0200 Subject: [PATCH 12/19] turn off bench_scope --- benchmarks/Cargo.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/benchmarks/Cargo.toml b/benchmarks/Cargo.toml index dd0cdae6..0718b21e 100644 --- a/benchmarks/Cargo.toml +++ b/benchmarks/Cargo.toml @@ -10,7 +10,8 @@ canbench-rs.workspace = true candid.workspace = true ic-cdk-macros.workspace = true ic-cdk.workspace = true -ic-stable-structures = { path = "../", features = ["bench_scope"] } +ic-stable-structures = { path = "../", features = [] } +#ic-stable-structures = { path = "../", features = ["bench_scope"] } maplit.workspace = true serde.workspace = true tiny-rng.workspace = true From d8ccd6830d1551f8c32031e77b6f57b31b109c14 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Thu, 5 Jun 2025 10:20:19 +0200 Subject: [PATCH 13/19] revert reading children vec --- src/btreemap/node/v2.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/btreemap/node/v2.rs b/src/btreemap/node/v2.rs index 2bea8eab..938adf45 100644 --- a/src/btreemap/node/v2.rs +++ b/src/btreemap/node/v2.rs @@ -144,19 +144,19 @@ impl Node { let _p = canbench_rs::bench_scope("node_load_v2_children"); // May add significant overhead. // The number of children is equal to the number of entries + 1. - // children.reserve_exact(num_entries + 1); - // for _ in 0..num_entries + 1 { - // let child = Address::from(read_u64(&reader, offset)); - // offset += Address::size(); - // children.push(child); - // } - - let total_children = num_entries + 1; - children = read_u64_vec(&reader, offset, total_children) - .into_iter() - .map(Address::from) - .collect(); - offset += Address::size() * Bytes::from(total_children as u64); + children.reserve_exact(num_entries + 1); + for _ in 0..num_entries + 1 { + let child = Address::from(read_u64(&reader, offset)); + offset += Address::size(); + children.push(child); + } + + // let total_children = num_entries + 1; + // children = read_u64_vec(&reader, offset, total_children) + // .into_iter() + // .map(Address::from) + // .collect(); + // offset += Address::size() * Bytes::from(total_children as u64); } // Load the keys (eagerly if small). From 112d514e1b0e852dbd0bd3e6ee64c5d77d430d9e Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Thu, 5 Jun 2025 15:04:33 +0200 Subject: [PATCH 14/19] read_u64_vec --- src/btreemap/node/v2.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/btreemap/node/v2.rs b/src/btreemap/node/v2.rs index 938adf45..2bea8eab 100644 --- a/src/btreemap/node/v2.rs +++ b/src/btreemap/node/v2.rs @@ -144,19 +144,19 @@ impl Node { let _p = canbench_rs::bench_scope("node_load_v2_children"); // May add significant overhead. // The number of children is equal to the number of entries + 1. - children.reserve_exact(num_entries + 1); - for _ in 0..num_entries + 1 { - let child = Address::from(read_u64(&reader, offset)); - offset += Address::size(); - children.push(child); - } - - // let total_children = num_entries + 1; - // children = read_u64_vec(&reader, offset, total_children) - // .into_iter() - // .map(Address::from) - // .collect(); - // offset += Address::size() * Bytes::from(total_children as u64); + // children.reserve_exact(num_entries + 1); + // for _ in 0..num_entries + 1 { + // let child = Address::from(read_u64(&reader, offset)); + // offset += Address::size(); + // children.push(child); + // } + + let total_children = num_entries + 1; + children = read_u64_vec(&reader, offset, total_children) + .into_iter() + .map(Address::from) + .collect(); + offset += Address::size() * Bytes::from(total_children as u64); } // Load the keys (eagerly if small). From b29df8837c27053210ea9c8afd42c6f39b3eeb77 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Mon, 7 Jul 2025 11:16:08 +0200 Subject: [PATCH 15/19] comment new code --- src/btreemap/node.rs | 2 +- src/btreemap/node/io.rs | 14 +++++++------- src/btreemap/node/v2.rs | 26 +++++++++++++------------- src/lib.rs | 14 +++++++------- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/btreemap/node.rs b/src/btreemap/node.rs index 4e241824..d0d75233 100644 --- a/src/btreemap/node.rs +++ b/src/btreemap/node.rs @@ -1,6 +1,6 @@ use crate::{ btreemap::Allocator, - read_struct, read_to_vec, read_u32, read_u64, read_u64_vec, + read_struct, read_to_vec, read_u32, read_u64, storable::Storable, types::{Address, Bytes}, write, write_struct, write_u32, Memory, diff --git a/src/btreemap/node/io.rs b/src/btreemap/node/io.rs index 0416c84a..ba01b4b6 100644 --- a/src/btreemap/node/io.rs +++ b/src/btreemap/node/io.rs @@ -289,13 +289,13 @@ impl<'a, M: Memory> NodeWriter<'a, M> { self.write(offset, &val.to_le_bytes()); } - pub fn write_u64_vec(&mut self, offset: Address, values: &[u64]) { - let mut buf = vec![0u8; values.len() * 8]; - for (i, &value) in values.iter().enumerate() { - buf[i * 8..(i + 1) * 8].copy_from_slice(&value.to_le_bytes()); - } - self.write(offset, &buf); - } + // pub fn write_u64_vec(&mut self, offset: Address, values: &[u64]) { + // let mut buf = vec![0u8; values.len() * 8]; + // for (i, &value) in values.iter().enumerate() { + // buf[i * 8..(i + 1) * 8].copy_from_slice(&value.to_le_bytes()); + // } + // self.write(offset, &buf); + // } pub fn write_struct(&mut self, t: &T, addr: Address) { let slice = unsafe { diff --git a/src/btreemap/node/v2.rs b/src/btreemap/node/v2.rs index 477d4a88..1ff5af04 100644 --- a/src/btreemap/node/v2.rs +++ b/src/btreemap/node/v2.rs @@ -144,19 +144,19 @@ impl Node { let _p = canbench_rs::bench_scope("node_load_v2_children"); // May add significant overhead. // The number of children is equal to the number of entries + 1. - // children.reserve_exact(num_entries + 1); - // for _ in 0..num_entries + 1 { - // let child = Address::from(read_u64(&reader, offset)); - // offset += Address::size(); - // children.push(child); - // } - - let total_children = num_entries + 1; - children = read_u64_vec(&reader, offset, total_children) - .into_iter() - .map(Address::from) - .collect(); - offset += Address::size() * Bytes::from(total_children as u64); + children.reserve_exact(num_entries + 1); + for _ in 0..num_entries + 1 { + let child = Address::from(read_u64(&reader, offset)); + offset += Address::size(); + children.push(child); + } + + // let total_children = num_entries + 1; + // children = read_u64_vec(&reader, offset, total_children) + // .into_iter() + // .map(Address::from) + // .collect(); + // offset += Address::size() * Bytes::from(total_children as u64); } // Load the keys (eagerly if small). diff --git a/src/lib.rs b/src/lib.rs index 6b334a76..06756d90 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -127,13 +127,13 @@ fn read_u64(m: &M, addr: Address) -> u64 { /// Reads `count` consecutive u64 values from memory starting at `addr` into a Vec. /// This is more efficient than calling `read_u64` in a loop. -fn read_u64_vec(m: &M, addr: Address, count: usize) -> std::vec::Vec { - let mut buf = vec![0u8; count * 8]; - m.read(addr.get(), &mut buf); - buf.chunks_exact(8) - .map(|chunk| u64::from_le_bytes(chunk.try_into().unwrap())) - .collect() -} +// fn read_u64_vec(m: &M, addr: Address, count: usize) -> std::vec::Vec { +// let mut buf = vec![0u8; count * 8]; +// m.read(addr.get(), &mut buf); +// buf.chunks_exact(8) +// .map(|chunk| u64::from_le_bytes(chunk.try_into().unwrap())) +// .collect() +// } /// Writes a single 32-bit integer encoded as little-endian. fn write_u32(m: &M, addr: Address, val: u32) { From 4675503f33dad325bf0afe1fa1acb7290aa9555b Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Mon, 7 Jul 2025 13:50:04 +0200 Subject: [PATCH 16/19] loop vs recursion --- benchmarks/btreemap/canbench_results.yml | 180 +++++++++++------------ benchmarks/compare/canbench_results.yml | 6 +- src/btreemap.rs | 24 +-- src/btreemap/node.rs | 2 +- 4 files changed, 108 insertions(+), 104 deletions(-) diff --git a/benchmarks/btreemap/canbench_results.yml b/benchmarks/btreemap/canbench_results.yml index 7d2d237a..52b55854 100644 --- a/benchmarks/btreemap/canbench_results.yml +++ b/benchmarks/btreemap/canbench_results.yml @@ -2,560 +2,560 @@ benches: btreemap_v2_contains_10mib_values: total: calls: 1 - instructions: 142211173 + instructions: 142221776 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob8_u64: total: calls: 1 - instructions: 284729276 + instructions: 297011261 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_1024_128: total: calls: 1 - instructions: 4287195962 + instructions: 4237984419 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_128_128: total: calls: 1 - instructions: 833911660 + instructions: 815949975 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_16_128: total: calls: 1 - instructions: 301679312 + instructions: 298889838 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_256_128: total: calls: 1 - instructions: 1319638527 + instructions: 1300551142 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_1024: total: calls: 1 - instructions: 335467579 + instructions: 328102465 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_128: total: calls: 1 - instructions: 335857875 + instructions: 328220130 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_16: total: calls: 1 - instructions: 328808633 + instructions: 321356702 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_256: total: calls: 1 - instructions: 334434277 + instructions: 326561840 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_32: total: calls: 1 - instructions: 339847402 + instructions: 330697847 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_4: total: calls: 1 - instructions: 332340488 + instructions: 324248398 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_512: total: calls: 1 - instructions: 331695205 + instructions: 324207523 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_64: total: calls: 1 - instructions: 334858994 + instructions: 327144396 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_8: total: calls: 1 - instructions: 334584158 + instructions: 326277252 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_4_128: total: calls: 1 - instructions: 253347390 + instructions: 252422690 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_512_128: total: calls: 1 - instructions: 2290838029 + instructions: 2261808705 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_64_128: total: calls: 1 - instructions: 414363928 + instructions: 400814817 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_8_128: total: calls: 1 - instructions: 275816922 + instructions: 270122929 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_u64_blob8: total: calls: 1 - instructions: 227932672 + instructions: 225265346 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_u64_u64: total: calls: 1 - instructions: 233050993 + instructions: 228332826 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_u64_vec8: total: calls: 1 - instructions: 227932672 + instructions: 225265346 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec8_u64: total: calls: 1 - instructions: 380704254 + instructions: 375898985 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_1024_128: total: calls: 1 - instructions: 1824658598 + instructions: 1847104615 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_128_128: total: calls: 1 - instructions: 574277483 + instructions: 564398532 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_16_128: total: calls: 1 - instructions: 448376101 + instructions: 436116862 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_256_128: total: calls: 1 - instructions: 902317934 + instructions: 894175321 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_1024: total: calls: 1 - instructions: 514204302 + instructions: 490728532 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_128: total: calls: 1 - instructions: 428712852 + instructions: 410643139 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_16: total: calls: 1 - instructions: 375067406 + instructions: 373668949 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_256: total: calls: 1 - instructions: 441718228 + instructions: 435832498 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_32: total: calls: 1 - instructions: 363350869 + instructions: 373972183 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_4: total: calls: 1 - instructions: 368447206 + instructions: 372439832 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_512: total: calls: 1 - instructions: 460605845 + instructions: 454776907 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_64: total: calls: 1 - instructions: 407446580 + instructions: 407431644 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_8: total: calls: 1 - instructions: 360599985 + instructions: 372364090 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_4_128: total: calls: 1 - instructions: 412997571 + instructions: 403007147 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_512_128: total: calls: 1 - instructions: 1252406681 + instructions: 1229386963 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_64_128: total: calls: 1 - instructions: 506200295 + instructions: 499897731 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_8_128: total: calls: 1 - instructions: 402314964 + instructions: 392932530 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_10mib_values: total: calls: 1 - instructions: 388591796 + instructions: 388599700 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob8_u64: total: calls: 1 - instructions: 305721002 + instructions: 303410583 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_1024_128: total: calls: 1 - instructions: 4425292179 + instructions: 4431236221 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_128_128: total: calls: 1 - instructions: 866438615 + instructions: 865186960 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_16_128: total: calls: 1 - instructions: 314408609 + instructions: 319658137 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_256_128: total: calls: 1 - instructions: 1364965202 + instructions: 1370571655 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_1024: total: calls: 1 - instructions: 354108428 + instructions: 435245859 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_128: total: calls: 1 - instructions: 349135019 + instructions: 351872656 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_16: total: calls: 1 - instructions: 338382931 + instructions: 332217819 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_256: total: calls: 1 - instructions: 348736208 + instructions: 361810687 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_32: total: calls: 1 - instructions: 350096818 + instructions: 342550961 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_4: total: calls: 1 - instructions: 340412926 + instructions: 333951108 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_512: total: calls: 1 - instructions: 347642364 + instructions: 383807352 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_64: total: calls: 1 - instructions: 346801708 + instructions: 342971097 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_8: total: calls: 1 - instructions: 343068558 + instructions: 336436146 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_4_128: total: calls: 1 - instructions: 264255336 + instructions: 272654752 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_512_128: total: calls: 1 - instructions: 2367049394 + instructions: 2372944398 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_64_128: total: calls: 1 - instructions: 436964612 + instructions: 437635161 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_8_128: total: calls: 1 - instructions: 287796661 + instructions: 290732342 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_u64_blob8: total: calls: 1 - instructions: 237235807 + instructions: 231673198 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_u64_u64: total: calls: 1 - instructions: 243863619 + instructions: 234381530 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_u64_vec8: total: calls: 1 - instructions: 237991852 + instructions: 230815115 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec8_u64: total: calls: 1 - instructions: 388751746 + instructions: 386577566 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_1024_128: total: calls: 1 - instructions: 1841512514 + instructions: 1839704148 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_128_128: total: calls: 1 - instructions: 583901094 + instructions: 575868358 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_16_128: total: calls: 1 - instructions: 456729377 + instructions: 446324071 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_256_128: total: calls: 1 - instructions: 912188247 + instructions: 905806771 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_1024: total: calls: 1 - instructions: 552829330 + instructions: 518627453 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_128: total: calls: 1 - instructions: 437331840 + instructions: 421254181 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_16: total: calls: 1 - instructions: 381657975 + instructions: 382019272 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_256: total: calls: 1 - instructions: 457027782 + instructions: 452903159 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_32: total: calls: 1 - instructions: 370072283 + instructions: 382499104 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_4: total: calls: 1 - instructions: 374915812 + instructions: 380671266 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_512: total: calls: 1 - instructions: 480046387 + instructions: 475720248 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_64: total: calls: 1 - instructions: 414392801 + instructions: 416345282 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_8: total: calls: 1 - instructions: 367113865 + instructions: 380632331 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_4_128: total: calls: 1 - instructions: 421113110 + instructions: 412707970 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_512_128: total: calls: 1 - instructions: 1262553242 + instructions: 1241202622 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_64_128: total: calls: 1 - instructions: 514950921 + instructions: 510558044 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_8_128: total: calls: 1 - instructions: 410396741 + instructions: 403187436 heap_increase: 0 stable_memory_increase: 0 scopes: {} @@ -842,70 +842,70 @@ benches: btreemap_v2_mem_manager_contains_blob512_u64: total: calls: 1 - instructions: 2376508246 + instructions: 2348439158 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_contains_u64_blob512: total: calls: 1 - instructions: 304790871 + instructions: 302147173 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_contains_u64_u64: total: calls: 1 - instructions: 309491909 + instructions: 305836182 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_contains_u64_vec512: total: calls: 1 - instructions: 393000497 + instructions: 384328838 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_contains_vec512_u64: total: calls: 1 - instructions: 1228107785 + instructions: 1282483221 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_get_blob512_u64: total: calls: 1 - instructions: 2461116382 + instructions: 2446358667 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_get_u64_blob512: total: calls: 1 - instructions: 320423967 + instructions: 358836161 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_get_u64_u64: total: calls: 1 - instructions: 320421253 + instructions: 313151287 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_get_u64_vec512: total: calls: 1 - instructions: 416742620 + instructions: 398720581 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_get_vec512_u64: total: calls: 1 - instructions: 1268826315 + instructions: 1294923259 heap_increase: 0 stable_memory_increase: 0 scopes: {} diff --git a/benchmarks/compare/canbench_results.yml b/benchmarks/compare/canbench_results.yml index 4c9ef89e..6509a3af 100644 --- a/benchmarks/compare/canbench_results.yml +++ b/benchmarks/compare/canbench_results.yml @@ -2,21 +2,21 @@ benches: read_chunks_btreemap_1: total: calls: 1 - instructions: 148723640 + instructions: 148723563 heap_increase: 1601 stable_memory_increase: 0 scopes: {} read_chunks_btreemap_1k: total: calls: 1 - instructions: 499445396 + instructions: 509871434 heap_increase: 0 stable_memory_increase: 0 scopes: {} read_chunks_btreemap_1m: total: calls: 1 - instructions: 43947440627 + instructions: 44269944024 heap_increase: 0 stable_memory_increase: 0 scopes: {} diff --git a/src/btreemap.rs b/src/btreemap.rs index 49f18a3d..3dffa95d 100644 --- a/src/btreemap.rs +++ b/src/btreemap.rs @@ -656,7 +656,7 @@ where return None; } self.traverse(self.root_addr, key, |node, idx| { - node.into_entry(idx, self.memory()).1 // Extract value. + node.to_entry(idx, self.memory()).1 // Extract value. }) .map(Cow::Owned) .map(V::from_bytes) @@ -669,18 +669,22 @@ where } /// Recursively traverses from `node_addr`, invoking `f` if `key` is found. Stops at a leaf if not. + #[inline(always)] fn traverse(&self, node_addr: Address, key: &K, f: F) -> Option where - F: Fn(Node, usize) -> R + Clone, + F: Fn(&mut Node, usize) -> R, { - let node = self.load_node(node_addr); - // Look for the key in the current node. - match node.search(key, self.memory()) { - Ok(idx) => Some(f(node, idx)), // Key found: apply `f`. - Err(idx) => match node.node_type() { - NodeType::Leaf => None, // At a leaf: key not present. - NodeType::Internal => self.traverse(node.child(idx), key, f), // Continue search in child. - }, + let mut addr = node_addr; + loop { + let mut node = self.load_node(addr); + // Look for the key in the current node. + match node.search(key, self.memory()) { + Ok(idx) => return Some(f(&mut node, idx)), // Key found: apply `f`. + Err(idx) => match node.node_type() { + NodeType::Leaf => return None, // At a leaf: key not present. + NodeType::Internal => addr = node.child(idx), // Continue search in child. + }, + } } } diff --git a/src/btreemap/node.rs b/src/btreemap/node.rs index d0d75233..a1fafe2d 100644 --- a/src/btreemap/node.rs +++ b/src/btreemap/node.rs @@ -319,7 +319,7 @@ impl Node { } /// Returns the entry at the specified index while consuming this node. - pub fn into_entry(mut self, idx: usize, memory: &M) -> Entry { + pub fn to_entry(&mut self, idx: usize, memory: &M) -> Entry { let entries = core::mem::take(&mut self.entries); let (key, value) = entries.into_iter().nth(idx).unwrap(); ( From 3b3f90c906fc92e003c6765ca4f70161d534b033 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Mon, 7 Jul 2025 14:02:32 +0200 Subject: [PATCH 17/19] . --- benchmarks/btreemap/canbench_results.yml | 500 +++++++++++------------ benchmarks/compare/canbench_results.yml | 12 +- src/btreemap.rs | 33 +- src/btreemap/node.rs | 7 +- 4 files changed, 275 insertions(+), 277 deletions(-) diff --git a/benchmarks/btreemap/canbench_results.yml b/benchmarks/btreemap/canbench_results.yml index 52b55854..a6f608be 100644 --- a/benchmarks/btreemap/canbench_results.yml +++ b/benchmarks/btreemap/canbench_results.yml @@ -2,910 +2,910 @@ benches: btreemap_v2_contains_10mib_values: total: calls: 1 - instructions: 142221776 + instructions: 142211043 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob8_u64: total: calls: 1 - instructions: 297011261 + instructions: 284589786 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_1024_128: total: calls: 1 - instructions: 4237984419 + instructions: 4287068465 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_128_128: total: calls: 1 - instructions: 815949975 + instructions: 833784184 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_16_128: total: calls: 1 - instructions: 298889838 + instructions: 301551729 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_256_128: total: calls: 1 - instructions: 1300551142 + instructions: 1319511032 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_1024: total: calls: 1 - instructions: 328102465 + instructions: 335340051 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_128: total: calls: 1 - instructions: 328220130 + instructions: 335730320 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_16: total: calls: 1 - instructions: 321356702 + instructions: 328681132 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_256: total: calls: 1 - instructions: 326561840 + instructions: 334306724 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_32: total: calls: 1 - instructions: 330697847 + instructions: 339719884 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_4: total: calls: 1 - instructions: 324248398 + instructions: 332212967 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_512: total: calls: 1 - instructions: 324207523 + instructions: 331567691 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_64: total: calls: 1 - instructions: 327144396 + instructions: 334731486 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_8: total: calls: 1 - instructions: 326277252 + instructions: 334456608 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_4_128: total: calls: 1 - instructions: 252422690 + instructions: 253230618 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_512_128: total: calls: 1 - instructions: 2261808705 + instructions: 2290710550 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_64_128: total: calls: 1 - instructions: 400814817 + instructions: 414236409 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_8_128: total: calls: 1 - instructions: 270122929 + instructions: 275689469 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_u64_blob8: total: calls: 1 - instructions: 225265346 + instructions: 227988492 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_u64_u64: total: calls: 1 - instructions: 228332826 + instructions: 233100051 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_u64_vec8: total: calls: 1 - instructions: 225265346 + instructions: 227988492 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec8_u64: total: calls: 1 - instructions: 375898985 + instructions: 381896109 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_1024_128: total: calls: 1 - instructions: 1847104615 + instructions: 1825765218 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_128_128: total: calls: 1 - instructions: 564398532 + instructions: 575403799 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_16_128: total: calls: 1 - instructions: 436116862 + instructions: 449528879 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_256_128: total: calls: 1 - instructions: 894175321 + instructions: 903444395 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_1024: total: calls: 1 - instructions: 490728532 + instructions: 515311243 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_128: total: calls: 1 - instructions: 410643139 + instructions: 429852442 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_16: total: calls: 1 - instructions: 373668949 + instructions: 376261507 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_256: total: calls: 1 - instructions: 435832498 + instructions: 442845574 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_32: total: calls: 1 - instructions: 373972183 + instructions: 364544986 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_4: total: calls: 1 - instructions: 372439832 + instructions: 369641376 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_512: total: calls: 1 - instructions: 454776907 + instructions: 461732663 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_64: total: calls: 1 - instructions: 407431644 + instructions: 408623694 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_8: total: calls: 1 - instructions: 372364090 + instructions: 361794590 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_4_128: total: calls: 1 - instructions: 403007147 + instructions: 413937091 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_512_128: total: calls: 1 - instructions: 1229386963 + instructions: 1253533021 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_64_128: total: calls: 1 - instructions: 499897731 + instructions: 507328031 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_8_128: total: calls: 1 - instructions: 392932530 + instructions: 403472521 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_10mib_values: total: calls: 1 - instructions: 388599700 + instructions: 388593444 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob8_u64: total: calls: 1 - instructions: 303410583 + instructions: 306985951 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_1024_128: total: calls: 1 - instructions: 4431236221 + instructions: 4468917732 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_128_128: total: calls: 1 - instructions: 865186960 + instructions: 874885878 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_16_128: total: calls: 1 - instructions: 319658137 + instructions: 317946651 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_256_128: total: calls: 1 - instructions: 1370571655 + instructions: 1377831075 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_1024: total: calls: 1 - instructions: 435245859 + instructions: 358820632 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_128: total: calls: 1 - instructions: 351872656 + instructions: 353395480 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_16: total: calls: 1 - instructions: 332217819 + instructions: 341465501 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_256: total: calls: 1 - instructions: 361810687 + instructions: 353215571 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_32: total: calls: 1 - instructions: 342550961 + instructions: 353560413 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_4: total: calls: 1 - instructions: 333951108 + instructions: 343423643 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_512: total: calls: 1 - instructions: 383807352 + instructions: 352284128 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_64: total: calls: 1 - instructions: 342971097 + instructions: 350593383 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_8: total: calls: 1 - instructions: 336436146 + instructions: 346117255 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_4_128: total: calls: 1 - instructions: 272654752 + instructions: 264595013 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_512_128: total: calls: 1 - instructions: 2372944398 + instructions: 2390162752 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_64_128: total: calls: 1 - instructions: 437635161 + instructions: 442751803 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_8_128: total: calls: 1 - instructions: 290732342 + instructions: 288637500 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_u64_blob8: total: calls: 1 - instructions: 231673198 + instructions: 236902495 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_u64_u64: total: calls: 1 - instructions: 234381530 + instructions: 244070893 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_u64_vec8: total: calls: 1 - instructions: 230815115 + instructions: 237695355 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec8_u64: total: calls: 1 - instructions: 386577566 + instructions: 387372198 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_1024_128: total: calls: 1 - instructions: 1839704148 + instructions: 1840901847 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_128_128: total: calls: 1 - instructions: 575868358 + instructions: 584411524 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_16_128: total: calls: 1 - instructions: 446324071 + instructions: 456289282 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_256_128: total: calls: 1 - instructions: 905806771 + instructions: 912705843 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_1024: total: calls: 1 - instructions: 518627453 + instructions: 539669193 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_128: total: calls: 1 - instructions: 421254181 + instructions: 437496159 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_16: total: calls: 1 - instructions: 382019272 + instructions: 382104186 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_256: total: calls: 1 - instructions: 452903159 + instructions: 456882291 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_32: total: calls: 1 - instructions: 382499104 + instructions: 370530527 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_4: total: calls: 1 - instructions: 380671266 + instructions: 375360033 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_512: total: calls: 1 - instructions: 475720248 + instructions: 479727856 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_64: total: calls: 1 - instructions: 416345282 + instructions: 414929747 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_8: total: calls: 1 - instructions: 380632331 + instructions: 367555913 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_4_128: total: calls: 1 - instructions: 412707970 + instructions: 420987616 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_512_128: total: calls: 1 - instructions: 1241202622 + instructions: 1262785802 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_64_128: total: calls: 1 - instructions: 510558044 + instructions: 515572988 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_8_128: total: calls: 1 - instructions: 403187436 + instructions: 410241154 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_insert_10mib_values: total: calls: 1 - instructions: 4389914887 + instructions: 4388588543 heap_increase: 161 stable_memory_increase: 3613 scopes: {} btreemap_v2_insert_blob8_u64: total: calls: 1 - instructions: 445148380 + instructions: 443775952 heap_increase: 0 stable_memory_increase: 4 scopes: {} btreemap_v2_insert_blob_1024_128: total: calls: 1 - instructions: 5500538279 + instructions: 5499071874 heap_increase: 0 stable_memory_increase: 196 scopes: {} btreemap_v2_insert_blob_128_128: total: calls: 1 - instructions: 1189575032 + instructions: 1188107343 heap_increase: 0 stable_memory_increase: 46 scopes: {} btreemap_v2_insert_blob_16_128: total: calls: 1 - instructions: 495692426 + instructions: 494269553 heap_increase: 0 stable_memory_increase: 24 scopes: {} btreemap_v2_insert_blob_256_128: total: calls: 1 - instructions: 1796924645 + instructions: 1795455828 heap_increase: 0 stable_memory_increase: 67 scopes: {} btreemap_v2_insert_blob_32_1024: total: calls: 1 - instructions: 711849765 + instructions: 710401042 heap_increase: 0 stable_memory_increase: 173 scopes: {} btreemap_v2_insert_blob_32_128: total: calls: 1 - instructions: 551938454 + instructions: 550494414 heap_increase: 0 stable_memory_increase: 28 scopes: {} btreemap_v2_insert_blob_32_16: total: calls: 1 - instructions: 526876092 + instructions: 525418870 heap_increase: 0 stable_memory_increase: 11 scopes: {} btreemap_v2_insert_blob_32_256: total: calls: 1 - instructions: 580539981 + instructions: 579088493 heap_increase: 0 stable_memory_increase: 49 scopes: {} btreemap_v2_insert_blob_32_32: total: calls: 1 - instructions: 536926289 + instructions: 535473021 heap_increase: 0 stable_memory_increase: 13 scopes: {} btreemap_v2_insert_blob_32_4: total: calls: 1 - instructions: 517270027 + instructions: 515820373 heap_increase: 0 stable_memory_increase: 8 scopes: {} btreemap_v2_insert_blob_32_512: total: calls: 1 - instructions: 619389665 + instructions: 617940529 heap_increase: 0 stable_memory_increase: 91 scopes: {} btreemap_v2_insert_blob_32_64: total: calls: 1 - instructions: 543098852 + instructions: 541647936 heap_increase: 0 stable_memory_increase: 18 scopes: {} btreemap_v2_insert_blob_32_8: total: calls: 1 - instructions: 525592612 + instructions: 524149607 heap_increase: 0 stable_memory_increase: 9 scopes: {} btreemap_v2_insert_blob_4_128: total: calls: 1 - instructions: 416771974 + instructions: 415487066 heap_increase: 0 stable_memory_increase: 13 scopes: {} btreemap_v2_insert_blob_512_128: total: calls: 1 - instructions: 3047890476 + instructions: 3046420165 heap_increase: 0 stable_memory_increase: 111 scopes: {} btreemap_v2_insert_blob_64_128: total: calls: 1 - instructions: 670229451 + instructions: 668768098 heap_increase: 0 stable_memory_increase: 34 scopes: {} btreemap_v2_insert_blob_8_128: total: calls: 1 - instructions: 468148607 + instructions: 466758920 heap_increase: 0 stable_memory_increase: 20 scopes: {} btreemap_v2_insert_u64_blob8: total: calls: 1 - instructions: 414573520 + instructions: 413423115 heap_increase: 0 stable_memory_increase: 5 scopes: {} btreemap_v2_insert_u64_u64: total: calls: 1 - instructions: 422311308 + instructions: 421162309 heap_increase: 0 stable_memory_increase: 6 scopes: {} btreemap_v2_insert_u64_vec8: total: calls: 1 - instructions: 417793976 + instructions: 416642967 heap_increase: 0 stable_memory_increase: 21 scopes: {} btreemap_v2_insert_vec8_u64: total: calls: 1 - instructions: 600241480 + instructions: 600143709 heap_increase: 0 stable_memory_increase: 16 scopes: {} btreemap_v2_insert_vec_1024_128: total: calls: 1 - instructions: 2751883354 + instructions: 2752109976 heap_increase: 0 stable_memory_increase: 193 scopes: {} btreemap_v2_insert_vec_128_128: total: calls: 1 - instructions: 1018986630 + instructions: 1019077984 heap_increase: 0 stable_memory_increase: 51 scopes: {} btreemap_v2_insert_vec_16_128: total: calls: 1 - instructions: 715440972 + instructions: 715389494 heap_increase: 0 stable_memory_increase: 31 scopes: {} btreemap_v2_insert_vec_256_128: total: calls: 1 - instructions: 1409430838 + instructions: 1409623299 heap_increase: 0 stable_memory_increase: 71 scopes: {} btreemap_v2_insert_vec_32_1024: total: calls: 1 - instructions: 1184814611 + instructions: 1184846255 heap_increase: 0 stable_memory_increase: 171 scopes: {} btreemap_v2_insert_vec_32_128: total: calls: 1 - instructions: 762530013 + instructions: 762489690 heap_increase: 0 stable_memory_increase: 33 scopes: {} btreemap_v2_insert_vec_32_16: total: calls: 1 - instructions: 672563151 + instructions: 672434593 heap_increase: 0 stable_memory_increase: 20 scopes: {} btreemap_v2_insert_vec_32_256: total: calls: 1 - instructions: 875753632 + instructions: 875767829 heap_increase: 0 stable_memory_increase: 54 scopes: {} btreemap_v2_insert_vec_32_32: total: calls: 1 - instructions: 667983184 + instructions: 667852438 heap_increase: 0 stable_memory_increase: 20 scopes: {} btreemap_v2_insert_vec_32_4: total: calls: 1 - instructions: 666709196 + instructions: 666585797 heap_increase: 0 stable_memory_increase: 20 scopes: {} btreemap_v2_insert_vec_32_512: total: calls: 1 - instructions: 981187745 + instructions: 981227964 heap_increase: 0 stable_memory_increase: 91 scopes: {} btreemap_v2_insert_vec_32_64: total: calls: 1 - instructions: 699970006 + instructions: 699860935 heap_increase: 0 stable_memory_increase: 24 scopes: {} btreemap_v2_insert_vec_32_8: total: calls: 1 - instructions: 666308283 + instructions: 666186058 heap_increase: 0 stable_memory_increase: 20 scopes: {} btreemap_v2_insert_vec_4_128: total: calls: 1 - instructions: 610329720 + instructions: 610313639 heap_increase: 0 stable_memory_increase: 16 scopes: {} btreemap_v2_insert_vec_512_128: total: calls: 1 - instructions: 1866471276 + instructions: 1866701192 heap_increase: 0 stable_memory_increase: 112 scopes: {} btreemap_v2_insert_vec_64_128: total: calls: 1 - instructions: 853527323 + instructions: 853518752 heap_increase: 0 stable_memory_increase: 41 scopes: {} btreemap_v2_insert_vec_8_128: total: calls: 1 - instructions: 672412257 + instructions: 672363716 heap_increase: 0 stable_memory_increase: 23 scopes: {} btreemap_v2_mem_manager_contains_blob512_u64: total: calls: 1 - instructions: 2348439158 + instructions: 2376380756 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_contains_u64_blob512: total: calls: 1 - instructions: 302147173 + instructions: 304846623 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_contains_u64_u64: total: calls: 1 - instructions: 305836182 + instructions: 309540968 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_contains_u64_vec512: total: calls: 1 - instructions: 384328838 + instructions: 393028966 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_contains_vec512_u64: total: calls: 1 - instructions: 1282483221 + instructions: 1229234276 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_get_blob512_u64: total: calls: 1 - instructions: 2446358667 + instructions: 2485080720 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_get_u64_blob512: total: calls: 1 - instructions: 358836161 + instructions: 321510059 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_get_u64_u64: total: calls: 1 - instructions: 313151287 + instructions: 320180896 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_get_u64_vec512: total: calls: 1 - instructions: 398720581 + instructions: 418668529 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_get_vec512_u64: total: calls: 1 - instructions: 1294923259 + instructions: 1270033294 heap_increase: 0 stable_memory_increase: 0 scopes: {} @@ -940,7 +940,7 @@ benches: btreemap_v2_mem_manager_insert_vec512_u64: total: calls: 1 - instructions: 1985385065 + instructions: 1986718151 heap_increase: 0 stable_memory_increase: 0 scopes: {} @@ -975,553 +975,553 @@ benches: btreemap_v2_mem_manager_remove_vec512_u64: total: calls: 1 - instructions: 3119370019 + instructions: 3120364334 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_blob8_u64: total: calls: 1 - instructions: 618004432 + instructions: 616238247 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_blob_1024_128: total: calls: 1 - instructions: 8407393947 + instructions: 8405110087 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_blob_128_128: total: calls: 1 - instructions: 1847105509 + instructions: 1844858965 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_blob_16_128: total: calls: 1 - instructions: 759917435 + instructions: 757881564 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_blob_256_128: total: calls: 1 - instructions: 2784099866 + instructions: 2781828963 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_blob_32_1024: total: calls: 1 - instructions: 1137118056 + instructions: 1134938499 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_blob_32_128: total: calls: 1 - instructions: 881420615 + instructions: 879223283 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_blob_32_16: total: calls: 1 - instructions: 816201283 + instructions: 814041416 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_blob_32_256: total: calls: 1 - instructions: 909759141 + instructions: 907574274 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_blob_32_32: total: calls: 1 - instructions: 830061311 + instructions: 827900605 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_blob_32_4: total: calls: 1 - instructions: 799112085 + instructions: 796941422 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_blob_32_512: total: calls: 1 - instructions: 974145553 + instructions: 971972894 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_blob_32_64: total: calls: 1 - instructions: 839453947 + instructions: 837291844 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_blob_32_8: total: calls: 1 - instructions: 817717399 + instructions: 815516687 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_blob_4_128: total: calls: 1 - instructions: 381495137 + instructions: 380325038 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_blob_512_128: total: calls: 1 - instructions: 4633016190 + instructions: 4630749005 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_blob_64_128: total: calls: 1 - instructions: 1051383954 + instructions: 1049152344 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_blob_8_128: total: calls: 1 - instructions: 621633869 + instructions: 619885081 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_u64_blob8: total: calls: 1 - instructions: 692329103 + instructions: 690529296 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_u64_u64: total: calls: 1 - instructions: 704283252 + instructions: 702491834 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_u64_vec8: total: calls: 1 - instructions: 694788529 + instructions: 692986646 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec8_u64: total: calls: 1 - instructions: 799659343 + instructions: 798617904 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_1024_128: total: calls: 1 - instructions: 4058561257 + instructions: 4057872681 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_128_128: total: calls: 1 - instructions: 1522614084 + instructions: 1521654350 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_16_128: total: calls: 1 - instructions: 1044640043 + instructions: 1043515356 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_256_128: total: calls: 1 - instructions: 2035052771 + instructions: 2034262071 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_32_1024: total: calls: 1 - instructions: 1702345063 + instructions: 1701398314 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_32_128: total: calls: 1 - instructions: 1108685023 + instructions: 1107501642 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_32_16: total: calls: 1 - instructions: 952540611 + instructions: 951292559 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_32_256: total: calls: 1 - instructions: 1234428372 + instructions: 1233366808 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_32_32: total: calls: 1 - instructions: 948692301 + instructions: 947441160 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_32_4: total: calls: 1 - instructions: 940976421 + instructions: 939706528 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_32_512: total: calls: 1 - instructions: 1387844690 + instructions: 1386851000 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_32_64: total: calls: 1 - instructions: 990795901 + instructions: 989555075 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_32_8: total: calls: 1 - instructions: 951913479 + instructions: 950622210 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_4_128: total: calls: 1 - instructions: 549923267 + instructions: 549240041 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_512_128: total: calls: 1 - instructions: 2728821380 + instructions: 2728108664 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_64_128: total: calls: 1 - instructions: 1251470670 + instructions: 1250341210 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_8_128: total: calls: 1 - instructions: 865247718 + instructions: 864263442 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_blob8_u64: total: calls: 1 - instructions: 596324464 + instructions: 594554793 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_blob_1024_128: total: calls: 1 - instructions: 8074544986 + instructions: 8072257193 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_blob_128_128: total: calls: 1 - instructions: 1777146013 + instructions: 1774896013 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_blob_16_128: total: calls: 1 - instructions: 733631722 + instructions: 731594742 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_blob_256_128: total: calls: 1 - instructions: 2689902060 + instructions: 2687630971 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_blob_32_1024: total: calls: 1 - instructions: 1101403747 + instructions: 1099225896 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_blob_32_128: total: calls: 1 - instructions: 846620590 + instructions: 844420849 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_blob_32_16: total: calls: 1 - instructions: 789994300 + instructions: 787834096 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_blob_32_256: total: calls: 1 - instructions: 878909990 + instructions: 876725357 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_blob_32_32: total: calls: 1 - instructions: 798906057 + instructions: 796749863 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_blob_32_4: total: calls: 1 - instructions: 776965442 + instructions: 774786952 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_blob_32_512: total: calls: 1 - instructions: 948839215 + instructions: 946668648 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_blob_32_64: total: calls: 1 - instructions: 813853996 + instructions: 811690345 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_blob_32_8: total: calls: 1 - instructions: 790947962 + instructions: 788744407 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_blob_4_128: total: calls: 1 - instructions: 367470484 + instructions: 366302758 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_blob_512_128: total: calls: 1 - instructions: 4464466989 + instructions: 4462199327 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_blob_64_128: total: calls: 1 - instructions: 1019568178 + instructions: 1017338731 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_blob_8_128: total: calls: 1 - instructions: 615779354 + instructions: 614030859 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_u64_blob8: total: calls: 1 - instructions: 670872335 + instructions: 669071901 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_u64_u64: total: calls: 1 - instructions: 682270872 + instructions: 680477690 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_u64_vec8: total: calls: 1 - instructions: 673168643 + instructions: 671365878 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec8_u64: total: calls: 1 - instructions: 774006741 + instructions: 772952168 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_1024_128: total: calls: 1 - instructions: 4276255634 + instructions: 4275574167 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_128_128: total: calls: 1 - instructions: 1528030235 + instructions: 1527066617 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_16_128: total: calls: 1 - instructions: 1025426502 + instructions: 1024295131 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_256_128: total: calls: 1 - instructions: 2095735884 + instructions: 2094936306 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_32_1024: total: calls: 1 - instructions: 1676567325 + instructions: 1675615913 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_32_128: total: calls: 1 - instructions: 1083533099 + instructions: 1082344052 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_32_16: total: calls: 1 - instructions: 925174029 + instructions: 923918138 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_32_256: total: calls: 1 - instructions: 1210196374 + instructions: 1209132451 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_32_32: total: calls: 1 - instructions: 925759641 + instructions: 924508518 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_32_4: total: calls: 1 - instructions: 921398027 + instructions: 920126340 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_32_512: total: calls: 1 - instructions: 1372237172 + instructions: 1371246157 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_32_64: total: calls: 1 - instructions: 969366613 + instructions: 968124641 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_32_8: total: calls: 1 - instructions: 925007419 + instructions: 923710585 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_4_128: total: calls: 1 - instructions: 535497301 + instructions: 534813424 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_512_128: total: calls: 1 - instructions: 2828271962 + instructions: 2827556556 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_64_128: total: calls: 1 - instructions: 1239503601 + instructions: 1238370730 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_8_128: total: calls: 1 - instructions: 864933984 + instructions: 863963180 heap_increase: 0 stable_memory_increase: 0 scopes: {} @@ -1591,280 +1591,280 @@ benches: btreemap_v2_remove_10mib_values: total: calls: 1 - instructions: 4711735840 + instructions: 4711113268 heap_increase: 0 stable_memory_increase: 657 scopes: {} btreemap_v2_remove_blob8_u64: total: calls: 1 - instructions: 597402521 + instructions: 595034392 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_blob_1024_128: total: calls: 1 - instructions: 7379667530 + instructions: 7376821978 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_blob_128_128: total: calls: 1 - instructions: 1607396971 + instructions: 1604578706 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_blob_16_128: total: calls: 1 - instructions: 680207076 + instructions: 677519725 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_blob_256_128: total: calls: 1 - instructions: 2438118145 + instructions: 2435285200 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_blob_32_1024: total: calls: 1 - instructions: 998591597 + instructions: 995853257 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_blob_32_128: total: calls: 1 - instructions: 762964319 + instructions: 760229442 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_blob_32_16: total: calls: 1 - instructions: 716725406 + instructions: 714008050 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_blob_32_256: total: calls: 1 - instructions: 799333504 + instructions: 796606463 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_blob_32_32: total: calls: 1 - instructions: 727478439 + instructions: 724749939 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_blob_32_4: total: calls: 1 - instructions: 712643752 + instructions: 709873769 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_blob_32_512: total: calls: 1 - instructions: 872035197 + instructions: 869263095 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_blob_32_64: total: calls: 1 - instructions: 754165215 + instructions: 751349928 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_blob_32_8: total: calls: 1 - instructions: 712284119 + instructions: 709570833 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_blob_4_128: total: calls: 1 - instructions: 464428655 + instructions: 462808100 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_blob_512_128: total: calls: 1 - instructions: 4087441997 + instructions: 4084598119 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_blob_64_128: total: calls: 1 - instructions: 925857471 + instructions: 923149106 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_blob_8_128: total: calls: 1 - instructions: 614717485 + instructions: 612305700 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_u64_blob8: total: calls: 1 - instructions: 582430661 + instructions: 580203408 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_u64_u64: total: calls: 1 - instructions: 603924879 + instructions: 601677776 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_u64_vec8: total: calls: 1 - instructions: 587919795 + instructions: 585690492 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec8_u64: total: calls: 1 - instructions: 768226679 + instructions: 766743041 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_1024_128: total: calls: 1 - instructions: 4486822914 + instructions: 4485750849 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_128_128: total: calls: 1 - instructions: 1441411708 + instructions: 1439981932 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_16_128: total: calls: 1 - instructions: 930370511 + instructions: 928725401 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_256_128: total: calls: 1 - instructions: 2253983036 + instructions: 2252781634 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_32_1024: total: calls: 1 - instructions: 1712407887 + instructions: 1711074495 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_32_128: total: calls: 1 - instructions: 1044675402 + instructions: 1043061815 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_32_16: total: calls: 1 - instructions: 885753202 + instructions: 884024105 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_32_256: total: calls: 1 - instructions: 1258480662 + instructions: 1256982415 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_32_32: total: calls: 1 - instructions: 879000014 + instructions: 877261732 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_32_4: total: calls: 1 - instructions: 875841943 + instructions: 874057069 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_32_512: total: calls: 1 - instructions: 1419720324 + instructions: 1418307126 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_32_64: total: calls: 1 - instructions: 982667924 + instructions: 980864089 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_32_8: total: calls: 1 - instructions: 869697878 + instructions: 867955409 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_4_128: total: calls: 1 - instructions: 670016444 + instructions: 669260985 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_512_128: total: calls: 1 - instructions: 3092666660 + instructions: 3091546912 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_64_128: total: calls: 1 - instructions: 1201307935 + instructions: 1199764677 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_8_128: total: calls: 1 - instructions: 833748512 + instructions: 832345144 heap_increase: 0 stable_memory_increase: 0 scopes: {} diff --git a/benchmarks/compare/canbench_results.yml b/benchmarks/compare/canbench_results.yml index 6509a3af..1bd5b910 100644 --- a/benchmarks/compare/canbench_results.yml +++ b/benchmarks/compare/canbench_results.yml @@ -2,21 +2,21 @@ benches: read_chunks_btreemap_1: total: calls: 1 - instructions: 148723563 + instructions: 148723587 heap_increase: 1601 stable_memory_increase: 0 scopes: {} read_chunks_btreemap_1k: total: calls: 1 - instructions: 509871434 + instructions: 499369650 heap_increase: 0 stable_memory_increase: 0 scopes: {} read_chunks_btreemap_1m: total: calls: 1 - instructions: 44269944024 + instructions: 44057615732 heap_increase: 0 stable_memory_increase: 0 scopes: {} @@ -107,21 +107,21 @@ benches: write_chunks_vec_1: total: calls: 1 - instructions: 549903573 + instructions: 549903558 heap_increase: 0 stable_memory_increase: 1536 scopes: {} write_chunks_vec_1k: total: calls: 1 - instructions: 562257515 + instructions: 562244513 heap_increase: 0 stable_memory_increase: 1536 scopes: {} write_chunks_vec_1m: total: calls: 1 - instructions: 1896593101 + instructions: 1883593099 heap_increase: 0 stable_memory_increase: 1536 scopes: {} diff --git a/src/btreemap.rs b/src/btreemap.rs index 3dffa95d..585cff3f 100644 --- a/src/btreemap.rs +++ b/src/btreemap.rs @@ -655,8 +655,8 @@ where if self.root_addr == NULL { return None; } - self.traverse(self.root_addr, key, |node, idx| { - node.to_entry(idx, self.memory()).1 // Extract value. + self.traverse(self.root_addr, key, self.memory(), |node, idx, mem| { + node.extract_entry_at(idx, mem).1 // Extract value. }) .map(Cow::Owned) .map(V::from_bytes) @@ -665,26 +665,25 @@ where /// Returns true if the key exists. pub fn contains_key(&self, key: &K) -> bool { // An empty closure returns Some(()) if the key is found. - self.root_addr != NULL && self.traverse(self.root_addr, key, |_, _| ()).is_some() + self.root_addr != NULL + && self + .traverse(self.root_addr, key, self.memory(), |_, _, _| ()) + .is_some() } /// Recursively traverses from `node_addr`, invoking `f` if `key` is found. Stops at a leaf if not. - #[inline(always)] - fn traverse(&self, node_addr: Address, key: &K, f: F) -> Option + fn traverse(&self, node_addr: Address, key: &K, mem: &M, f: F) -> Option where - F: Fn(&mut Node, usize) -> R, + F: Fn(&mut Node, usize, &M) -> R, { - let mut addr = node_addr; - loop { - let mut node = self.load_node(addr); - // Look for the key in the current node. - match node.search(key, self.memory()) { - Ok(idx) => return Some(f(&mut node, idx)), // Key found: apply `f`. - Err(idx) => match node.node_type() { - NodeType::Leaf => return None, // At a leaf: key not present. - NodeType::Internal => addr = node.child(idx), // Continue search in child. - }, - } + let mut node = self.load_node(node_addr); + // Look for the key in the current node. + match node.search(key, mem) { + Ok(idx) => Some(f(&mut node, idx, mem)), // Key found: apply `f`. + Err(idx) => match node.node_type() { + NodeType::Leaf => None, // At a leaf: key not present. + NodeType::Internal => self.traverse(node.child(idx), key, mem, f), // Continue search in child. + }, } } diff --git a/src/btreemap/node.rs b/src/btreemap/node.rs index a1fafe2d..f49d9b92 100644 --- a/src/btreemap/node.rs +++ b/src/btreemap/node.rs @@ -318,10 +318,9 @@ impl Node { .insert(idx, (LazyKey::by_value(key), LazyValue::by_value(value))); } - /// Returns the entry at the specified index while consuming this node. - pub fn to_entry(&mut self, idx: usize, memory: &M) -> Entry { - let entries = core::mem::take(&mut self.entries); - let (key, value) = entries.into_iter().nth(idx).unwrap(); + /// Removes and decodes the entry at `idx`. + pub fn extract_entry_at(&mut self, idx: usize, memory: &M) -> Entry { + let (key, value) = self.entries.swap_remove(idx); ( self.extract_key(key, memory), self.extract_value(value, memory), From 59f1412b5a7c4416590e21dc5dcd7d3b3b237a64 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Mon, 7 Jul 2025 14:08:56 +0200 Subject: [PATCH 18/19] loop --- benchmarks/btreemap/canbench_results.yml | 324 +++++++++++------------ benchmarks/compare/canbench_results.yml | 6 +- src/btreemap.rs | 28 +- src/btreemap/node/io.rs | 8 - src/btreemap/node/v2.rs | 12 - src/lib.rs | 10 - 6 files changed, 185 insertions(+), 203 deletions(-) diff --git a/benchmarks/btreemap/canbench_results.yml b/benchmarks/btreemap/canbench_results.yml index a6f608be..eba2abb1 100644 --- a/benchmarks/btreemap/canbench_results.yml +++ b/benchmarks/btreemap/canbench_results.yml @@ -2,560 +2,560 @@ benches: btreemap_v2_contains_10mib_values: total: calls: 1 - instructions: 142211043 + instructions: 142222786 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob8_u64: total: calls: 1 - instructions: 284589786 + instructions: 296985266 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_1024_128: total: calls: 1 - instructions: 4287068465 + instructions: 4285598481 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_128_128: total: calls: 1 - instructions: 833784184 + instructions: 827092739 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_16_128: total: calls: 1 - instructions: 301551729 + instructions: 298991793 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_256_128: total: calls: 1 - instructions: 1319511032 + instructions: 1317115671 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_1024: total: calls: 1 - instructions: 335340051 + instructions: 330786531 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_128: total: calls: 1 - instructions: 335730320 + instructions: 330692238 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_16: total: calls: 1 - instructions: 328681132 + instructions: 323879113 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_256: total: calls: 1 - instructions: 334306724 + instructions: 329017234 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_32: total: calls: 1 - instructions: 339719884 + instructions: 333534206 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_4: total: calls: 1 - instructions: 332212967 + instructions: 327040663 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_512: total: calls: 1 - instructions: 331567691 + instructions: 327026351 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_64: total: calls: 1 - instructions: 334731486 + instructions: 329799660 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_8: total: calls: 1 - instructions: 334456608 + instructions: 328866207 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_4_128: total: calls: 1 - instructions: 253230618 + instructions: 252375035 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_512_128: total: calls: 1 - instructions: 2290710550 + instructions: 2288747934 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_64_128: total: calls: 1 - instructions: 414236409 + instructions: 407917591 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_8_128: total: calls: 1 - instructions: 275689469 + instructions: 270112472 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_u64_blob8: total: calls: 1 - instructions: 227988492 + instructions: 225209610 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_u64_u64: total: calls: 1 - instructions: 233100051 + instructions: 228289902 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_u64_vec8: total: calls: 1 - instructions: 227988492 + instructions: 225209610 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec8_u64: total: calls: 1 - instructions: 381896109 + instructions: 379476508 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_1024_128: total: calls: 1 - instructions: 1825765218 + instructions: 1849683679 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_128_128: total: calls: 1 - instructions: 575403799 + instructions: 566972576 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_16_128: total: calls: 1 - instructions: 449528879 + instructions: 439645220 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_256_128: total: calls: 1 - instructions: 903444395 + instructions: 896750231 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_1024: total: calls: 1 - instructions: 515311243 + instructions: 493288576 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_128: total: calls: 1 - instructions: 429852442 + instructions: 413206649 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_16: total: calls: 1 - instructions: 376261507 + instructions: 376250470 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_256: total: calls: 1 - instructions: 442845574 + instructions: 438395955 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_32: total: calls: 1 - instructions: 364544986 + instructions: 376569802 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_4: total: calls: 1 - instructions: 369641376 + instructions: 375021932 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_512: total: calls: 1 - instructions: 461732663 + instructions: 457340128 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_64: total: calls: 1 - instructions: 408623694 + instructions: 410009071 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_8: total: calls: 1 - instructions: 361794590 + instructions: 374942767 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_4_128: total: calls: 1 - instructions: 413937091 + instructions: 406107438 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_512_128: total: calls: 1 - instructions: 1253533021 + instructions: 1231950058 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_64_128: total: calls: 1 - instructions: 507328031 + instructions: 502479396 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_8_128: total: calls: 1 - instructions: 403472521 + instructions: 396438333 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_10mib_values: total: calls: 1 - instructions: 388593444 + instructions: 388600648 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob8_u64: total: calls: 1 - instructions: 306985951 + instructions: 303710620 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_1024_128: total: calls: 1 - instructions: 4468917732 + instructions: 4474722172 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_128_128: total: calls: 1 - instructions: 874885878 + instructions: 872834803 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_16_128: total: calls: 1 - instructions: 317946651 + instructions: 322821802 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_256_128: total: calls: 1 - instructions: 1377831075 + instructions: 1383337886 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_1024: total: calls: 1 - instructions: 358820632 + instructions: 440323235 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_128: total: calls: 1 - instructions: 353395480 + instructions: 355714221 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_16: total: calls: 1 - instructions: 341465501 + instructions: 336061756 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_256: total: calls: 1 - instructions: 353215571 + instructions: 365675098 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_32: total: calls: 1 - instructions: 353560413 + instructions: 346396382 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_4: total: calls: 1 - instructions: 343423643 + instructions: 337793811 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_512: total: calls: 1 - instructions: 352284128 + instructions: 388405010 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_64: total: calls: 1 - instructions: 350593383 + instructions: 346813858 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_8: total: calls: 1 - instructions: 346117255 + instructions: 340277405 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_4_128: total: calls: 1 - instructions: 264595013 + instructions: 272915940 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_512_128: total: calls: 1 - instructions: 2390162752 + instructions: 2395951293 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_64_128: total: calls: 1 - instructions: 442751803 + instructions: 442719362 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_8_128: total: calls: 1 - instructions: 288637500 + instructions: 291044590 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_u64_blob8: total: calls: 1 - instructions: 236902495 + instructions: 231971193 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_u64_u64: total: calls: 1 - instructions: 244070893 + instructions: 234679489 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_u64_vec8: total: calls: 1 - instructions: 237695355 + instructions: 231113190 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec8_u64: total: calls: 1 - instructions: 387372198 + instructions: 385138682 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_1024_128: total: calls: 1 - instructions: 1840901847 + instructions: 1840146043 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_128_128: total: calls: 1 - instructions: 584411524 + instructions: 576010847 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_16_128: total: calls: 1 - instructions: 456289282 + instructions: 446359439 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_256_128: total: calls: 1 - instructions: 912705843 + instructions: 905950713 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_1024: total: calls: 1 - instructions: 539669193 + instructions: 517622421 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_128: total: calls: 1 - instructions: 437496159 + instructions: 420816471 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_16: total: calls: 1 - instructions: 382104186 + instructions: 382163374 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_256: total: calls: 1 - instructions: 456882291 + instructions: 452449397 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_32: total: calls: 1 - instructions: 370530527 + instructions: 382642484 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_4: total: calls: 1 - instructions: 375360033 + instructions: 380815061 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_512: total: calls: 1 - instructions: 479727856 + instructions: 475257931 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_64: total: calls: 1 - instructions: 414929747 + instructions: 416485272 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_8: total: calls: 1 - instructions: 367555913 + instructions: 380775858 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_4_128: total: calls: 1 - instructions: 420987616 + instructions: 412713348 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_512_128: total: calls: 1 - instructions: 1262785802 + instructions: 1241343705 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_64_128: total: calls: 1 - instructions: 515572988 + instructions: 510697028 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_8_128: total: calls: 1 - instructions: 410241154 + instructions: 403111998 heap_increase: 0 stable_memory_increase: 0 scopes: {} @@ -716,196 +716,196 @@ benches: btreemap_v2_insert_vec8_u64: total: calls: 1 - instructions: 600143709 + instructions: 598853183 heap_increase: 0 stable_memory_increase: 16 scopes: {} btreemap_v2_insert_vec_1024_128: total: calls: 1 - instructions: 2752109976 + instructions: 2750777903 heap_increase: 0 stable_memory_increase: 193 scopes: {} btreemap_v2_insert_vec_128_128: total: calls: 1 - instructions: 1019077984 + instructions: 1017752326 heap_increase: 0 stable_memory_increase: 51 scopes: {} btreemap_v2_insert_vec_16_128: total: calls: 1 - instructions: 715389494 + instructions: 714074112 heap_increase: 0 stable_memory_increase: 31 scopes: {} btreemap_v2_insert_vec_256_128: total: calls: 1 - instructions: 1409623299 + instructions: 1408291409 heap_increase: 0 stable_memory_increase: 71 scopes: {} btreemap_v2_insert_vec_32_1024: total: calls: 1 - instructions: 1184846255 + instructions: 1183523309 heap_increase: 0 stable_memory_increase: 171 scopes: {} btreemap_v2_insert_vec_32_128: total: calls: 1 - instructions: 762489690 + instructions: 761163819 heap_increase: 0 stable_memory_increase: 33 scopes: {} btreemap_v2_insert_vec_32_16: total: calls: 1 - instructions: 672434593 + instructions: 671107054 heap_increase: 0 stable_memory_increase: 20 scopes: {} btreemap_v2_insert_vec_32_256: total: calls: 1 - instructions: 875767829 + instructions: 874446323 heap_increase: 0 stable_memory_increase: 54 scopes: {} btreemap_v2_insert_vec_32_32: total: calls: 1 - instructions: 667852438 + instructions: 666529916 heap_increase: 0 stable_memory_increase: 20 scopes: {} btreemap_v2_insert_vec_32_4: total: calls: 1 - instructions: 666585797 + instructions: 665259447 heap_increase: 0 stable_memory_increase: 20 scopes: {} btreemap_v2_insert_vec_32_512: total: calls: 1 - instructions: 981227964 + instructions: 979903192 heap_increase: 0 stable_memory_increase: 91 scopes: {} btreemap_v2_insert_vec_32_64: total: calls: 1 - instructions: 699860935 + instructions: 698533349 heap_increase: 0 stable_memory_increase: 24 scopes: {} btreemap_v2_insert_vec_32_8: total: calls: 1 - instructions: 666186058 + instructions: 664865362 heap_increase: 0 stable_memory_increase: 20 scopes: {} btreemap_v2_insert_vec_4_128: total: calls: 1 - instructions: 610313639 + instructions: 609089416 heap_increase: 0 stable_memory_increase: 16 scopes: {} btreemap_v2_insert_vec_512_128: total: calls: 1 - instructions: 1866701192 + instructions: 1865371046 heap_increase: 0 stable_memory_increase: 112 scopes: {} btreemap_v2_insert_vec_64_128: total: calls: 1 - instructions: 853518752 + instructions: 852187004 heap_increase: 0 stable_memory_increase: 41 scopes: {} btreemap_v2_insert_vec_8_128: total: calls: 1 - instructions: 672363716 + instructions: 671071785 heap_increase: 0 stable_memory_increase: 23 scopes: {} btreemap_v2_mem_manager_contains_blob512_u64: total: calls: 1 - instructions: 2376380756 + instructions: 2375216736 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_contains_u64_blob512: total: calls: 1 - instructions: 304846623 + instructions: 302629953 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_contains_u64_u64: total: calls: 1 - instructions: 309540968 + instructions: 306318496 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_contains_u64_vec512: total: calls: 1 - instructions: 393028966 + instructions: 384791620 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_contains_vec512_u64: total: calls: 1 - instructions: 1229234276 + instructions: 1286253240 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_get_blob512_u64: total: calls: 1 - instructions: 2485080720 + instructions: 2471199322 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_get_u64_blob512: total: calls: 1 - instructions: 321510059 + instructions: 359910391 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_get_u64_u64: total: calls: 1 - instructions: 320180896 + instructions: 313449246 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_get_u64_vec512: total: calls: 1 - instructions: 418668529 + instructions: 400730138 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_get_vec512_u64: total: calls: 1 - instructions: 1270033294 + instructions: 1296272808 heap_increase: 0 stable_memory_increase: 0 scopes: {} @@ -1129,126 +1129,126 @@ benches: btreemap_v2_pop_first_vec8_u64: total: calls: 1 - instructions: 798617904 + instructions: 797883630 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_1024_128: total: calls: 1 - instructions: 4057872681 + instructions: 4056925524 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_128_128: total: calls: 1 - instructions: 1521654350 + instructions: 1520705042 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_16_128: total: calls: 1 - instructions: 1043515356 + instructions: 1042672030 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_256_128: total: calls: 1 - instructions: 2034262071 + instructions: 2033297324 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_32_1024: total: calls: 1 - instructions: 1701398314 + instructions: 1700489656 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_32_128: total: calls: 1 - instructions: 1107501642 + instructions: 1106587903 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_32_16: total: calls: 1 - instructions: 951292559 + instructions: 950380375 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_32_256: total: calls: 1 - instructions: 1233366808 + instructions: 1232462974 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_32_32: total: calls: 1 - instructions: 947441160 + instructions: 946532385 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_32_4: total: calls: 1 - instructions: 939706528 + instructions: 938805516 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_32_512: total: calls: 1 - instructions: 1386851000 + instructions: 1385950928 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_32_64: total: calls: 1 - instructions: 989555075 + instructions: 988652926 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_32_8: total: calls: 1 - instructions: 950622210 + instructions: 949713535 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_4_128: total: calls: 1 - instructions: 549240041 + instructions: 548783428 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_512_128: total: calls: 1 - instructions: 2728108664 + instructions: 2727159366 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_64_128: total: calls: 1 - instructions: 1250341210 + instructions: 1249407926 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_8_128: total: calls: 1 - instructions: 864263442 + instructions: 863551398 heap_increase: 0 stable_memory_increase: 0 scopes: {} @@ -1402,126 +1402,126 @@ benches: btreemap_v2_pop_last_vec8_u64: total: calls: 1 - instructions: 772952168 + instructions: 772227812 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_1024_128: total: calls: 1 - instructions: 4275574167 + instructions: 4274616966 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_128_128: total: calls: 1 - instructions: 1527066617 + instructions: 1526118224 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_16_128: total: calls: 1 - instructions: 1024295131 + instructions: 1023457709 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_256_128: total: calls: 1 - instructions: 2094936306 + instructions: 2093980844 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_32_1024: total: calls: 1 - instructions: 1675615913 + instructions: 1674712733 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_32_128: total: calls: 1 - instructions: 1082344052 + instructions: 1081434150 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_32_16: total: calls: 1 - instructions: 923918138 + instructions: 923013553 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_32_256: total: calls: 1 - instructions: 1209132451 + instructions: 1208231266 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_32_32: total: calls: 1 - instructions: 924508518 + instructions: 923604177 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_32_4: total: calls: 1 - instructions: 920126340 + instructions: 919219253 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_32_512: total: calls: 1 - instructions: 1371246157 + instructions: 1370345179 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_32_64: total: calls: 1 - instructions: 968124641 + instructions: 967222477 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_32_8: total: calls: 1 - instructions: 923710585 + instructions: 922804703 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_4_128: total: calls: 1 - instructions: 534813424 + instructions: 534360396 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_512_128: total: calls: 1 - instructions: 2827556556 + instructions: 2826609667 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_64_128: total: calls: 1 - instructions: 1238370730 + instructions: 1237442729 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_8_128: total: calls: 1 - instructions: 863963180 + instructions: 863237741 heap_increase: 0 stable_memory_increase: 0 scopes: {} @@ -1745,126 +1745,126 @@ benches: btreemap_v2_remove_vec8_u64: total: calls: 1 - instructions: 766743041 + instructions: 765785405 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_1024_128: total: calls: 1 - instructions: 4485750849 + instructions: 4484755155 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_128_128: total: calls: 1 - instructions: 1439981932 + instructions: 1438991491 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_16_128: total: calls: 1 - instructions: 928725401 + instructions: 927741252 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_256_128: total: calls: 1 - instructions: 2252781634 + instructions: 2251793667 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_32_1024: total: calls: 1 - instructions: 1711074495 + instructions: 1710090933 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_32_128: total: calls: 1 - instructions: 1043061815 + instructions: 1042077084 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_32_16: total: calls: 1 - instructions: 884024105 + instructions: 883036873 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_32_256: total: calls: 1 - instructions: 1256982415 + instructions: 1255993471 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_32_32: total: calls: 1 - instructions: 877261732 + instructions: 876271717 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_32_4: total: calls: 1 - instructions: 874057069 + instructions: 873071796 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_32_512: total: calls: 1 - instructions: 1418307126 + instructions: 1417315689 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_32_64: total: calls: 1 - instructions: 980864089 + instructions: 979873125 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_32_8: total: calls: 1 - instructions: 867955409 + instructions: 866964825 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_4_128: total: calls: 1 - instructions: 669260985 + instructions: 668372726 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_512_128: total: calls: 1 - instructions: 3091546912 + instructions: 3090551072 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_64_128: total: calls: 1 - instructions: 1199764677 + instructions: 1198777801 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_8_128: total: calls: 1 - instructions: 832345144 + instructions: 831385315 heap_increase: 0 stable_memory_increase: 0 scopes: {} diff --git a/benchmarks/compare/canbench_results.yml b/benchmarks/compare/canbench_results.yml index 1bd5b910..64e400a6 100644 --- a/benchmarks/compare/canbench_results.yml +++ b/benchmarks/compare/canbench_results.yml @@ -2,21 +2,21 @@ benches: read_chunks_btreemap_1: total: calls: 1 - instructions: 148723587 + instructions: 148723585 heap_increase: 1601 stable_memory_increase: 0 scopes: {} read_chunks_btreemap_1k: total: calls: 1 - instructions: 499369650 + instructions: 509883102 heap_increase: 0 stable_memory_increase: 0 scopes: {} read_chunks_btreemap_1m: total: calls: 1 - instructions: 44057615732 + instructions: 42306613376 heap_increase: 0 stable_memory_increase: 0 scopes: {} diff --git a/src/btreemap.rs b/src/btreemap.rs index 585cff3f..58be367e 100644 --- a/src/btreemap.rs +++ b/src/btreemap.rs @@ -676,14 +676,26 @@ where where F: Fn(&mut Node, usize, &M) -> R, { - let mut node = self.load_node(node_addr); - // Look for the key in the current node. - match node.search(key, mem) { - Ok(idx) => Some(f(&mut node, idx, mem)), // Key found: apply `f`. - Err(idx) => match node.node_type() { - NodeType::Leaf => None, // At a leaf: key not present. - NodeType::Internal => self.traverse(node.child(idx), key, mem, f), // Continue search in child. - }, + // let mut node = self.load_node(node_addr); + // // Look for the key in the current node. + // match node.search(key, mem) { + // Ok(idx) => Some(f(&mut node, idx, mem)), // Key found: apply `f`. + // Err(idx) => match node.node_type() { + // NodeType::Leaf => None, // At a leaf: key not present. + // NodeType::Internal => self.traverse(node.child(idx), key, mem, f), // Continue search in child. + // }, + // } + let mut addr = node_addr; + loop { + let mut node = self.load_node(addr); + // Look for the key in the current node. + match node.search(key, mem) { + Ok(idx) => return Some(f(&mut node, idx, mem)), // Key found: apply `f`. + Err(idx) => match node.node_type() { + NodeType::Leaf => return None, // At a leaf: key not present. + NodeType::Internal => addr = node.child(idx), // Continue search in child. + }, + } } } diff --git a/src/btreemap/node/io.rs b/src/btreemap/node/io.rs index ba01b4b6..4a2c97e8 100644 --- a/src/btreemap/node/io.rs +++ b/src/btreemap/node/io.rs @@ -289,14 +289,6 @@ impl<'a, M: Memory> NodeWriter<'a, M> { self.write(offset, &val.to_le_bytes()); } - // pub fn write_u64_vec(&mut self, offset: Address, values: &[u64]) { - // let mut buf = vec![0u8; values.len() * 8]; - // for (i, &value) in values.iter().enumerate() { - // buf[i * 8..(i + 1) * 8].copy_from_slice(&value.to_le_bytes()); - // } - // self.write(offset, &buf); - // } - pub fn write_struct(&mut self, t: &T, addr: Address) { let slice = unsafe { core::slice::from_raw_parts(t as *const _ as *const u8, core::mem::size_of::()) diff --git a/src/btreemap/node/v2.rs b/src/btreemap/node/v2.rs index 1ff5af04..4573052c 100644 --- a/src/btreemap/node/v2.rs +++ b/src/btreemap/node/v2.rs @@ -150,13 +150,6 @@ impl Node { offset += Address::size(); children.push(child); } - - // let total_children = num_entries + 1; - // children = read_u64_vec(&reader, offset, total_children) - // .into_iter() - // .map(Address::from) - // .collect(); - // offset += Address::size() * Bytes::from(total_children as u64); } // Load the keys (eagerly if small). @@ -274,11 +267,6 @@ impl Node { writer.write_u64(offset, child.get()); offset += Address::size(); } - // writer.write_u64_vec( - // offset, - // &self.children.iter().map(|c| c.get()).collect::>(), - // ); - // offset += Address::size() * Bytes::from(self.children.len() as u64); { #[cfg(feature = "bench_scope")] diff --git a/src/lib.rs b/src/lib.rs index 06756d90..4326bea4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -125,16 +125,6 @@ fn read_u64(m: &M, addr: Address) -> u64 { u64::from_le_bytes(buf) } -/// Reads `count` consecutive u64 values from memory starting at `addr` into a Vec. -/// This is more efficient than calling `read_u64` in a loop. -// fn read_u64_vec(m: &M, addr: Address, count: usize) -> std::vec::Vec { -// let mut buf = vec![0u8; count * 8]; -// m.read(addr.get(), &mut buf); -// buf.chunks_exact(8) -// .map(|chunk| u64::from_le_bytes(chunk.try_into().unwrap())) -// .collect() -// } - /// Writes a single 32-bit integer encoded as little-endian. fn write_u32(m: &M, addr: Address, val: u32) { write(m, addr.get(), &val.to_le_bytes()); From 7fc0c891ec6543bcd19e26363cdf00e5e200dfb5 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Mon, 7 Jul 2025 14:29:42 +0200 Subject: [PATCH 19/19] recursive --- benchmarks/btreemap/canbench_results.yml | 324 +++++++++++------------ benchmarks/compare/canbench_results.yml | 6 +- src/btreemap.rs | 40 +-- 3 files changed, 185 insertions(+), 185 deletions(-) diff --git a/benchmarks/btreemap/canbench_results.yml b/benchmarks/btreemap/canbench_results.yml index eba2abb1..a6f608be 100644 --- a/benchmarks/btreemap/canbench_results.yml +++ b/benchmarks/btreemap/canbench_results.yml @@ -2,560 +2,560 @@ benches: btreemap_v2_contains_10mib_values: total: calls: 1 - instructions: 142222786 + instructions: 142211043 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob8_u64: total: calls: 1 - instructions: 296985266 + instructions: 284589786 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_1024_128: total: calls: 1 - instructions: 4285598481 + instructions: 4287068465 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_128_128: total: calls: 1 - instructions: 827092739 + instructions: 833784184 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_16_128: total: calls: 1 - instructions: 298991793 + instructions: 301551729 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_256_128: total: calls: 1 - instructions: 1317115671 + instructions: 1319511032 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_1024: total: calls: 1 - instructions: 330786531 + instructions: 335340051 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_128: total: calls: 1 - instructions: 330692238 + instructions: 335730320 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_16: total: calls: 1 - instructions: 323879113 + instructions: 328681132 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_256: total: calls: 1 - instructions: 329017234 + instructions: 334306724 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_32: total: calls: 1 - instructions: 333534206 + instructions: 339719884 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_4: total: calls: 1 - instructions: 327040663 + instructions: 332212967 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_512: total: calls: 1 - instructions: 327026351 + instructions: 331567691 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_64: total: calls: 1 - instructions: 329799660 + instructions: 334731486 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_8: total: calls: 1 - instructions: 328866207 + instructions: 334456608 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_4_128: total: calls: 1 - instructions: 252375035 + instructions: 253230618 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_512_128: total: calls: 1 - instructions: 2288747934 + instructions: 2290710550 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_64_128: total: calls: 1 - instructions: 407917591 + instructions: 414236409 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_8_128: total: calls: 1 - instructions: 270112472 + instructions: 275689469 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_u64_blob8: total: calls: 1 - instructions: 225209610 + instructions: 227988492 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_u64_u64: total: calls: 1 - instructions: 228289902 + instructions: 233100051 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_u64_vec8: total: calls: 1 - instructions: 225209610 + instructions: 227988492 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec8_u64: total: calls: 1 - instructions: 379476508 + instructions: 381896109 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_1024_128: total: calls: 1 - instructions: 1849683679 + instructions: 1825765218 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_128_128: total: calls: 1 - instructions: 566972576 + instructions: 575403799 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_16_128: total: calls: 1 - instructions: 439645220 + instructions: 449528879 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_256_128: total: calls: 1 - instructions: 896750231 + instructions: 903444395 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_1024: total: calls: 1 - instructions: 493288576 + instructions: 515311243 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_128: total: calls: 1 - instructions: 413206649 + instructions: 429852442 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_16: total: calls: 1 - instructions: 376250470 + instructions: 376261507 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_256: total: calls: 1 - instructions: 438395955 + instructions: 442845574 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_32: total: calls: 1 - instructions: 376569802 + instructions: 364544986 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_4: total: calls: 1 - instructions: 375021932 + instructions: 369641376 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_512: total: calls: 1 - instructions: 457340128 + instructions: 461732663 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_64: total: calls: 1 - instructions: 410009071 + instructions: 408623694 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_8: total: calls: 1 - instructions: 374942767 + instructions: 361794590 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_4_128: total: calls: 1 - instructions: 406107438 + instructions: 413937091 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_512_128: total: calls: 1 - instructions: 1231950058 + instructions: 1253533021 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_64_128: total: calls: 1 - instructions: 502479396 + instructions: 507328031 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_8_128: total: calls: 1 - instructions: 396438333 + instructions: 403472521 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_10mib_values: total: calls: 1 - instructions: 388600648 + instructions: 388593444 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob8_u64: total: calls: 1 - instructions: 303710620 + instructions: 306985951 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_1024_128: total: calls: 1 - instructions: 4474722172 + instructions: 4468917732 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_128_128: total: calls: 1 - instructions: 872834803 + instructions: 874885878 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_16_128: total: calls: 1 - instructions: 322821802 + instructions: 317946651 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_256_128: total: calls: 1 - instructions: 1383337886 + instructions: 1377831075 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_1024: total: calls: 1 - instructions: 440323235 + instructions: 358820632 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_128: total: calls: 1 - instructions: 355714221 + instructions: 353395480 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_16: total: calls: 1 - instructions: 336061756 + instructions: 341465501 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_256: total: calls: 1 - instructions: 365675098 + instructions: 353215571 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_32: total: calls: 1 - instructions: 346396382 + instructions: 353560413 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_4: total: calls: 1 - instructions: 337793811 + instructions: 343423643 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_512: total: calls: 1 - instructions: 388405010 + instructions: 352284128 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_64: total: calls: 1 - instructions: 346813858 + instructions: 350593383 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_8: total: calls: 1 - instructions: 340277405 + instructions: 346117255 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_4_128: total: calls: 1 - instructions: 272915940 + instructions: 264595013 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_512_128: total: calls: 1 - instructions: 2395951293 + instructions: 2390162752 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_64_128: total: calls: 1 - instructions: 442719362 + instructions: 442751803 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_8_128: total: calls: 1 - instructions: 291044590 + instructions: 288637500 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_u64_blob8: total: calls: 1 - instructions: 231971193 + instructions: 236902495 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_u64_u64: total: calls: 1 - instructions: 234679489 + instructions: 244070893 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_u64_vec8: total: calls: 1 - instructions: 231113190 + instructions: 237695355 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec8_u64: total: calls: 1 - instructions: 385138682 + instructions: 387372198 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_1024_128: total: calls: 1 - instructions: 1840146043 + instructions: 1840901847 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_128_128: total: calls: 1 - instructions: 576010847 + instructions: 584411524 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_16_128: total: calls: 1 - instructions: 446359439 + instructions: 456289282 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_256_128: total: calls: 1 - instructions: 905950713 + instructions: 912705843 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_1024: total: calls: 1 - instructions: 517622421 + instructions: 539669193 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_128: total: calls: 1 - instructions: 420816471 + instructions: 437496159 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_16: total: calls: 1 - instructions: 382163374 + instructions: 382104186 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_256: total: calls: 1 - instructions: 452449397 + instructions: 456882291 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_32: total: calls: 1 - instructions: 382642484 + instructions: 370530527 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_4: total: calls: 1 - instructions: 380815061 + instructions: 375360033 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_512: total: calls: 1 - instructions: 475257931 + instructions: 479727856 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_64: total: calls: 1 - instructions: 416485272 + instructions: 414929747 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_8: total: calls: 1 - instructions: 380775858 + instructions: 367555913 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_4_128: total: calls: 1 - instructions: 412713348 + instructions: 420987616 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_512_128: total: calls: 1 - instructions: 1241343705 + instructions: 1262785802 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_64_128: total: calls: 1 - instructions: 510697028 + instructions: 515572988 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_8_128: total: calls: 1 - instructions: 403111998 + instructions: 410241154 heap_increase: 0 stable_memory_increase: 0 scopes: {} @@ -716,196 +716,196 @@ benches: btreemap_v2_insert_vec8_u64: total: calls: 1 - instructions: 598853183 + instructions: 600143709 heap_increase: 0 stable_memory_increase: 16 scopes: {} btreemap_v2_insert_vec_1024_128: total: calls: 1 - instructions: 2750777903 + instructions: 2752109976 heap_increase: 0 stable_memory_increase: 193 scopes: {} btreemap_v2_insert_vec_128_128: total: calls: 1 - instructions: 1017752326 + instructions: 1019077984 heap_increase: 0 stable_memory_increase: 51 scopes: {} btreemap_v2_insert_vec_16_128: total: calls: 1 - instructions: 714074112 + instructions: 715389494 heap_increase: 0 stable_memory_increase: 31 scopes: {} btreemap_v2_insert_vec_256_128: total: calls: 1 - instructions: 1408291409 + instructions: 1409623299 heap_increase: 0 stable_memory_increase: 71 scopes: {} btreemap_v2_insert_vec_32_1024: total: calls: 1 - instructions: 1183523309 + instructions: 1184846255 heap_increase: 0 stable_memory_increase: 171 scopes: {} btreemap_v2_insert_vec_32_128: total: calls: 1 - instructions: 761163819 + instructions: 762489690 heap_increase: 0 stable_memory_increase: 33 scopes: {} btreemap_v2_insert_vec_32_16: total: calls: 1 - instructions: 671107054 + instructions: 672434593 heap_increase: 0 stable_memory_increase: 20 scopes: {} btreemap_v2_insert_vec_32_256: total: calls: 1 - instructions: 874446323 + instructions: 875767829 heap_increase: 0 stable_memory_increase: 54 scopes: {} btreemap_v2_insert_vec_32_32: total: calls: 1 - instructions: 666529916 + instructions: 667852438 heap_increase: 0 stable_memory_increase: 20 scopes: {} btreemap_v2_insert_vec_32_4: total: calls: 1 - instructions: 665259447 + instructions: 666585797 heap_increase: 0 stable_memory_increase: 20 scopes: {} btreemap_v2_insert_vec_32_512: total: calls: 1 - instructions: 979903192 + instructions: 981227964 heap_increase: 0 stable_memory_increase: 91 scopes: {} btreemap_v2_insert_vec_32_64: total: calls: 1 - instructions: 698533349 + instructions: 699860935 heap_increase: 0 stable_memory_increase: 24 scopes: {} btreemap_v2_insert_vec_32_8: total: calls: 1 - instructions: 664865362 + instructions: 666186058 heap_increase: 0 stable_memory_increase: 20 scopes: {} btreemap_v2_insert_vec_4_128: total: calls: 1 - instructions: 609089416 + instructions: 610313639 heap_increase: 0 stable_memory_increase: 16 scopes: {} btreemap_v2_insert_vec_512_128: total: calls: 1 - instructions: 1865371046 + instructions: 1866701192 heap_increase: 0 stable_memory_increase: 112 scopes: {} btreemap_v2_insert_vec_64_128: total: calls: 1 - instructions: 852187004 + instructions: 853518752 heap_increase: 0 stable_memory_increase: 41 scopes: {} btreemap_v2_insert_vec_8_128: total: calls: 1 - instructions: 671071785 + instructions: 672363716 heap_increase: 0 stable_memory_increase: 23 scopes: {} btreemap_v2_mem_manager_contains_blob512_u64: total: calls: 1 - instructions: 2375216736 + instructions: 2376380756 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_contains_u64_blob512: total: calls: 1 - instructions: 302629953 + instructions: 304846623 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_contains_u64_u64: total: calls: 1 - instructions: 306318496 + instructions: 309540968 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_contains_u64_vec512: total: calls: 1 - instructions: 384791620 + instructions: 393028966 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_contains_vec512_u64: total: calls: 1 - instructions: 1286253240 + instructions: 1229234276 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_get_blob512_u64: total: calls: 1 - instructions: 2471199322 + instructions: 2485080720 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_get_u64_blob512: total: calls: 1 - instructions: 359910391 + instructions: 321510059 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_get_u64_u64: total: calls: 1 - instructions: 313449246 + instructions: 320180896 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_get_u64_vec512: total: calls: 1 - instructions: 400730138 + instructions: 418668529 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_get_vec512_u64: total: calls: 1 - instructions: 1296272808 + instructions: 1270033294 heap_increase: 0 stable_memory_increase: 0 scopes: {} @@ -1129,126 +1129,126 @@ benches: btreemap_v2_pop_first_vec8_u64: total: calls: 1 - instructions: 797883630 + instructions: 798617904 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_1024_128: total: calls: 1 - instructions: 4056925524 + instructions: 4057872681 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_128_128: total: calls: 1 - instructions: 1520705042 + instructions: 1521654350 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_16_128: total: calls: 1 - instructions: 1042672030 + instructions: 1043515356 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_256_128: total: calls: 1 - instructions: 2033297324 + instructions: 2034262071 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_32_1024: total: calls: 1 - instructions: 1700489656 + instructions: 1701398314 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_32_128: total: calls: 1 - instructions: 1106587903 + instructions: 1107501642 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_32_16: total: calls: 1 - instructions: 950380375 + instructions: 951292559 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_32_256: total: calls: 1 - instructions: 1232462974 + instructions: 1233366808 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_32_32: total: calls: 1 - instructions: 946532385 + instructions: 947441160 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_32_4: total: calls: 1 - instructions: 938805516 + instructions: 939706528 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_32_512: total: calls: 1 - instructions: 1385950928 + instructions: 1386851000 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_32_64: total: calls: 1 - instructions: 988652926 + instructions: 989555075 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_32_8: total: calls: 1 - instructions: 949713535 + instructions: 950622210 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_4_128: total: calls: 1 - instructions: 548783428 + instructions: 549240041 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_512_128: total: calls: 1 - instructions: 2727159366 + instructions: 2728108664 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_64_128: total: calls: 1 - instructions: 1249407926 + instructions: 1250341210 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_first_vec_8_128: total: calls: 1 - instructions: 863551398 + instructions: 864263442 heap_increase: 0 stable_memory_increase: 0 scopes: {} @@ -1402,126 +1402,126 @@ benches: btreemap_v2_pop_last_vec8_u64: total: calls: 1 - instructions: 772227812 + instructions: 772952168 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_1024_128: total: calls: 1 - instructions: 4274616966 + instructions: 4275574167 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_128_128: total: calls: 1 - instructions: 1526118224 + instructions: 1527066617 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_16_128: total: calls: 1 - instructions: 1023457709 + instructions: 1024295131 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_256_128: total: calls: 1 - instructions: 2093980844 + instructions: 2094936306 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_32_1024: total: calls: 1 - instructions: 1674712733 + instructions: 1675615913 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_32_128: total: calls: 1 - instructions: 1081434150 + instructions: 1082344052 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_32_16: total: calls: 1 - instructions: 923013553 + instructions: 923918138 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_32_256: total: calls: 1 - instructions: 1208231266 + instructions: 1209132451 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_32_32: total: calls: 1 - instructions: 923604177 + instructions: 924508518 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_32_4: total: calls: 1 - instructions: 919219253 + instructions: 920126340 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_32_512: total: calls: 1 - instructions: 1370345179 + instructions: 1371246157 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_32_64: total: calls: 1 - instructions: 967222477 + instructions: 968124641 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_32_8: total: calls: 1 - instructions: 922804703 + instructions: 923710585 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_4_128: total: calls: 1 - instructions: 534360396 + instructions: 534813424 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_512_128: total: calls: 1 - instructions: 2826609667 + instructions: 2827556556 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_64_128: total: calls: 1 - instructions: 1237442729 + instructions: 1238370730 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_pop_last_vec_8_128: total: calls: 1 - instructions: 863237741 + instructions: 863963180 heap_increase: 0 stable_memory_increase: 0 scopes: {} @@ -1745,126 +1745,126 @@ benches: btreemap_v2_remove_vec8_u64: total: calls: 1 - instructions: 765785405 + instructions: 766743041 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_1024_128: total: calls: 1 - instructions: 4484755155 + instructions: 4485750849 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_128_128: total: calls: 1 - instructions: 1438991491 + instructions: 1439981932 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_16_128: total: calls: 1 - instructions: 927741252 + instructions: 928725401 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_256_128: total: calls: 1 - instructions: 2251793667 + instructions: 2252781634 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_32_1024: total: calls: 1 - instructions: 1710090933 + instructions: 1711074495 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_32_128: total: calls: 1 - instructions: 1042077084 + instructions: 1043061815 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_32_16: total: calls: 1 - instructions: 883036873 + instructions: 884024105 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_32_256: total: calls: 1 - instructions: 1255993471 + instructions: 1256982415 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_32_32: total: calls: 1 - instructions: 876271717 + instructions: 877261732 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_32_4: total: calls: 1 - instructions: 873071796 + instructions: 874057069 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_32_512: total: calls: 1 - instructions: 1417315689 + instructions: 1418307126 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_32_64: total: calls: 1 - instructions: 979873125 + instructions: 980864089 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_32_8: total: calls: 1 - instructions: 866964825 + instructions: 867955409 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_4_128: total: calls: 1 - instructions: 668372726 + instructions: 669260985 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_512_128: total: calls: 1 - instructions: 3090551072 + instructions: 3091546912 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_64_128: total: calls: 1 - instructions: 1198777801 + instructions: 1199764677 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_remove_vec_8_128: total: calls: 1 - instructions: 831385315 + instructions: 832345144 heap_increase: 0 stable_memory_increase: 0 scopes: {} diff --git a/benchmarks/compare/canbench_results.yml b/benchmarks/compare/canbench_results.yml index 64e400a6..1bd5b910 100644 --- a/benchmarks/compare/canbench_results.yml +++ b/benchmarks/compare/canbench_results.yml @@ -2,21 +2,21 @@ benches: read_chunks_btreemap_1: total: calls: 1 - instructions: 148723585 + instructions: 148723587 heap_increase: 1601 stable_memory_increase: 0 scopes: {} read_chunks_btreemap_1k: total: calls: 1 - instructions: 509883102 + instructions: 499369650 heap_increase: 0 stable_memory_increase: 0 scopes: {} read_chunks_btreemap_1m: total: calls: 1 - instructions: 42306613376 + instructions: 44057615732 heap_increase: 0 stable_memory_increase: 0 scopes: {} diff --git a/src/btreemap.rs b/src/btreemap.rs index 58be367e..28d49770 100644 --- a/src/btreemap.rs +++ b/src/btreemap.rs @@ -676,27 +676,27 @@ where where F: Fn(&mut Node, usize, &M) -> R, { - // let mut node = self.load_node(node_addr); - // // Look for the key in the current node. - // match node.search(key, mem) { - // Ok(idx) => Some(f(&mut node, idx, mem)), // Key found: apply `f`. - // Err(idx) => match node.node_type() { - // NodeType::Leaf => None, // At a leaf: key not present. - // NodeType::Internal => self.traverse(node.child(idx), key, mem, f), // Continue search in child. - // }, - // } - let mut addr = node_addr; - loop { - let mut node = self.load_node(addr); - // Look for the key in the current node. - match node.search(key, mem) { - Ok(idx) => return Some(f(&mut node, idx, mem)), // Key found: apply `f`. - Err(idx) => match node.node_type() { - NodeType::Leaf => return None, // At a leaf: key not present. - NodeType::Internal => addr = node.child(idx), // Continue search in child. - }, - } + let mut node = self.load_node(node_addr); + // Look for the key in the current node. + match node.search(key, mem) { + Ok(idx) => Some(f(&mut node, idx, mem)), // Key found: apply `f`. + Err(idx) => match node.node_type() { + NodeType::Leaf => None, // At a leaf: key not present. + NodeType::Internal => self.traverse(node.child(idx), key, mem, f), // Continue search in child. + }, } + // let mut addr = node_addr; + // loop { + // let mut node = self.load_node(addr); + // // Look for the key in the current node. + // match node.search(key, mem) { + // Ok(idx) => return Some(f(&mut node, idx, mem)), // Key found: apply `f`. + // Err(idx) => match node.node_type() { + // NodeType::Leaf => return None, // At a leaf: key not present. + // NodeType::Internal => addr = node.child(idx), // Continue search in child. + // }, + // } + // } } /// Returns `true` if the map contains no elements.