From c1c0a5602edf4dd0fd3d7c26a585b56c890dc2ce Mon Sep 17 00:00:00 2001 From: Dragoljub Duric Date: Thu, 8 Feb 2024 14:03:42 +0000 Subject: [PATCH 1/6] . --- benchmarks/src/btreemap.rs | 49 +++++++++ canbench_results.yml | 210 +++++++++++++++++++------------------ 2 files changed, 159 insertions(+), 100 deletions(-) diff --git a/benchmarks/src/btreemap.rs b/benchmarks/src/btreemap.rs index 868dbd91..2ffc683f 100644 --- a/benchmarks/src/btreemap.rs +++ b/benchmarks/src/btreemap.rs @@ -1,3 +1,5 @@ +use std::ops::Bound; + use crate::Random; use canbench::{benchmark, macros::bench, BenchResult}; use ic_stable_structures::{storable::Blob, BTreeMap, DefaultMemoryImpl, Storable}; @@ -219,6 +221,53 @@ pub fn btreemap_insert_10mib_values() -> BenchResult { }) } +#[bench] +pub fn btreemap_iter_count() -> BenchResult { + let mut btree = BTreeMap::new(DefaultMemoryImpl::default()); + let size: u8 = 200; + for i in 0..size { + btree.insert(i, i); + } + + benchmark(|| { + for i in 0..size { + for j in i + 1..size { + btree + .range((Bound::Included(i), Bound::Included(j))) + .count(); + } + } + }) +} + +#[bench] +pub fn btreemap_iter_count_10mib_values() -> BenchResult { + let mut btree = BTreeMap::new(DefaultMemoryImpl::default()); + + // Insert 200 10MiB values. + let mut rng = Rng::from_seed(0); + let mut values = vec![]; + for _ in 0..200 { + values.push(rng.iter(Rand::rand_u8).take(10 * 1024).collect::>()); + } + + let mut i = 0u8; + for value in values.into_iter() { + btree.insert(i, value); + i += 1; + } + + benchmark(|| { + for j in 0..i { + for k in j + 1..i { + btree + .range((Bound::Included(j), Bound::Included(k))) + .count(); + } + } + }) +} + /// Benchmarks removing keys from a BTreeMap. #[bench] pub fn btreemap_remove_blob_4_1024() -> BenchResult { diff --git a/canbench_results.yml b/canbench_results.yml index 8ad5889d..adea6cc1 100644 --- a/canbench_results.yml +++ b/canbench_results.yml @@ -1,544 +1,554 @@ btreemap_get_blob_128_1024: measurements: - instructions: 1006573538 + instructions: 1006573497 node_load_v1: 832328557 stable_memory_size: 261 btreemap_get_blob_128_1024_v2: measurements: - instructions: 1123805990 + instructions: 1123805949 node_load_v2: 938155476 stable_memory_size: 196 btreemap_get_blob_16_1024: measurements: - instructions: 487229806 + instructions: 487229765 node_load_v1: 339804418 stable_memory_size: 216 btreemap_get_blob_16_1024_v2: measurements: - instructions: 583474971 + instructions: 583474930 node_load_v2: 430852270 stable_memory_size: 162 btreemap_get_blob_256_1024: measurements: - instructions: 1510660940 + instructions: 1510660899 node_load_v1: 1309093774 stable_memory_size: 293 btreemap_get_blob_256_1024_v2: measurements: - instructions: 1626341678 + instructions: 1626341637 node_load_v2: 1410845462 stable_memory_size: 220 btreemap_get_blob_32_1024: measurements: - instructions: 534895222 + instructions: 534895181 node_load_v1: 378516147 stable_memory_size: 231 btreemap_get_blob_32_1024_v2: measurements: - instructions: 633048491 + instructions: 633048450 node_load_v2: 471574348 stable_memory_size: 174 btreemap_get_blob_4_1024: measurements: - instructions: 355650535 + instructions: 355650494 node_load_v1: 231720942 stable_memory_size: 124 btreemap_get_blob_4_1024_v2: measurements: - instructions: 446660432 + instructions: 446660391 node_load_v2: 313869359 stable_memory_size: 93 btreemap_get_blob_512_1024: measurements: - instructions: 2506597898 + instructions: 2506597857 node_load_v1: 2251570705 stable_memory_size: 352 btreemap_get_blob_512_1024_v2: measurements: - instructions: 2625838052 + instructions: 2625838011 node_load_v2: 2356816367 stable_memory_size: 264 btreemap_get_blob_64_1024: measurements: - instructions: 780061526 + instructions: 780061485 node_load_v1: 616669297 stable_memory_size: 246 btreemap_get_blob_64_1024_v2: measurements: - instructions: 878745163 + instructions: 878745122 node_load_v2: 706540951 stable_memory_size: 184 btreemap_get_blob_8_1024: measurements: - instructions: 406432578 + instructions: 406432537 node_load_v1: 259168629 stable_memory_size: 184 btreemap_get_blob_8_1024_v2: measurements: - instructions: 493282925 + instructions: 493282884 node_load_v2: 336415667 stable_memory_size: 139 btreemap_get_blob_8_u64: measurements: - instructions: 368106593 + instructions: 368106552 node_load_v1: 253569163 stable_memory_size: 7 btreemap_get_blob_8_u64_v2: measurements: - instructions: 466009078 + instructions: 466009037 node_load_v2: 345475118 stable_memory_size: 5 btreemap_get_u64_blob_8: measurements: - instructions: 351156467 + instructions: 351156426 node_load_v1: 250986516 stable_memory_size: 8 btreemap_get_u64_blob_8_v2: measurements: - instructions: 413554294 + instructions: 413554253 node_load_v2: 309705639 stable_memory_size: 6 btreemap_get_u64_u64: measurements: - instructions: 353621464 + instructions: 353621423 node_load_v1: 249502481 stable_memory_size: 8 btreemap_get_u64_u64_v2: measurements: - instructions: 422146359 + instructions: 422146318 node_load_v2: 312364993 stable_memory_size: 7 btreemap_insert_10mib_values: measurements: - instructions: 107942355 + instructions: 107942333 node_load_v2: 10057317 node_save_v2: 77823608 stable_memory_size: 33 btreemap_insert_blob_1024_128: measurements: - instructions: 5115889431 + instructions: 5115889409 node_load_v1: 4062772095 node_save_v1: 185771186 stable_memory_size: 263 btreemap_insert_blob_1024_128_v2: measurements: - instructions: 5394772440 + instructions: 5394772418 node_load_v2: 4190686429 node_save_v2: 206085822 stable_memory_size: 197 btreemap_insert_blob_1024_16: measurements: - instructions: 5074839717 + instructions: 5074839695 node_load_v1: 4058526995 node_save_v1: 172957200 stable_memory_size: 242 btreemap_insert_blob_1024_16_v2: measurements: - instructions: 5358731374 + instructions: 5358731352 node_load_v2: 4195507437 node_save_v2: 193208733 stable_memory_size: 182 btreemap_insert_blob_1024_256: measurements: - instructions: 5130740072 + instructions: 5130740050 node_load_v1: 4039224210 node_save_v1: 201310396 stable_memory_size: 293 btreemap_insert_blob_1024_256_v2: measurements: - instructions: 5352948952 + instructions: 5352948930 node_load_v2: 4171364974 node_save_v2: 221531887 stable_memory_size: 220 btreemap_insert_blob_1024_32: measurements: - instructions: 5089791785 + instructions: 5089791763 node_load_v1: 4079908295 node_save_v1: 173954636 stable_memory_size: 240 btreemap_insert_blob_1024_32_v2: measurements: - instructions: 5357513466 + instructions: 5357513444 node_load_v2: 4214236378 node_save_v2: 194114909 stable_memory_size: 181 btreemap_insert_blob_1024_4: measurements: - instructions: 4968257212 + instructions: 4968257190 node_load_v1: 4058890666 node_save_v1: 162657999 stable_memory_size: 236 btreemap_insert_blob_1024_4_v2: measurements: - instructions: 5264404231 + instructions: 5264404209 node_load_v2: 4189301776 node_save_v2: 182905394 stable_memory_size: 177 btreemap_insert_blob_1024_512: measurements: - instructions: 5224338924 + instructions: 5224338902 node_load_v1: 4064093845 node_save_v1: 236696639 stable_memory_size: 349 btreemap_insert_blob_1024_512_v2: measurements: - instructions: 5481571968 + instructions: 5481571946 node_load_v2: 4201549676 node_save_v2: 257610609 stable_memory_size: 262 btreemap_insert_blob_1024_64: measurements: - instructions: 5110806943 + instructions: 5110806921 node_load_v1: 4075394290 node_save_v1: 178905580 stable_memory_size: 251 btreemap_insert_blob_1024_64_v2: measurements: - instructions: 5377434456 + instructions: 5377434434 node_load_v2: 4214020891 node_save_v2: 199157099 stable_memory_size: 189 btreemap_insert_blob_1024_8: measurements: - instructions: 5053776980 + instructions: 5053776958 node_load_v1: 4051194851 node_save_v1: 167362943 stable_memory_size: 238 btreemap_insert_blob_1024_8_v2: measurements: - instructions: 5331593907 + instructions: 5331593885 node_load_v2: 4181516149 node_save_v2: 187604446 stable_memory_size: 179 btreemap_insert_blob_128_1024: measurements: - instructions: 1577091213 + instructions: 1577091191 node_load_v1: 812526962 node_save_v1: 301462572 stable_memory_size: 261 btreemap_insert_blob_128_1024_v2: measurements: - instructions: 1726441521 + instructions: 1726441499 node_load_v2: 925130424 node_save_v2: 322015815 stable_memory_size: 196 btreemap_insert_blob_16_1024: measurements: - instructions: 992366717 + instructions: 992366695 node_load_v1: 322073344 node_save_v1: 291094888 stable_memory_size: 216 btreemap_insert_blob_16_1024_v2: measurements: - instructions: 1108674244 + instructions: 1108674222 node_load_v2: 419541518 node_save_v2: 310638874 stable_memory_size: 162 btreemap_insert_blob_256_1024: measurements: - instructions: 2114284649 + instructions: 2114284627 node_load_v1: 1278881721 node_save_v1: 300728644 stable_memory_size: 293 btreemap_insert_blob_256_1024_v2: measurements: - instructions: 2273386999 + instructions: 2273386977 node_load_v2: 1395147359 node_save_v2: 321544817 stable_memory_size: 220 btreemap_insert_blob_32_1024: measurements: - instructions: 1041724177 + instructions: 1041724155 node_load_v1: 358626551 node_save_v1: 298295476 stable_memory_size: 231 btreemap_insert_blob_32_1024_v2: measurements: - instructions: 1156895178 + instructions: 1156895156 node_load_v2: 459271136 node_save_v2: 316798162 stable_memory_size: 174 btreemap_insert_blob_4_1024: measurements: - instructions: 772106359 + instructions: 772106337 node_load_v1: 212848724 node_save_v1: 267119730 stable_memory_size: 124 btreemap_insert_blob_4_1024_v2: measurements: - instructions: 862904908 + instructions: 862904886 node_load_v2: 286322995 node_save_v2: 284380143 stable_memory_size: 93 btreemap_insert_blob_512_1024: measurements: - instructions: 3195541992 + instructions: 3195541970 node_load_v1: 2200910325 node_save_v1: 306828402 stable_memory_size: 352 btreemap_insert_blob_512_1024_v2: measurements: - instructions: 3317431106 + instructions: 3317431084 node_load_v2: 2302979370 node_save_v2: 323365428 stable_memory_size: 264 btreemap_insert_blob_64_1024: measurements: - instructions: 1305958991 + instructions: 1305958969 node_load_v1: 584672643 node_save_v1: 300400388 stable_memory_size: 246 btreemap_insert_blob_64_1024_v2: measurements: - instructions: 1439210453 + instructions: 1439210431 node_load_v2: 692993072 node_save_v2: 319569550 stable_memory_size: 184 btreemap_insert_blob_8_1024: measurements: - instructions: 905706875 + instructions: 905706853 node_load_v1: 247335003 node_save_v1: 284445265 stable_memory_size: 184 btreemap_insert_blob_8_1024_v2: measurements: - instructions: 1002633716 + instructions: 1002633694 node_load_v2: 325787553 node_save_v2: 303101882 stable_memory_size: 139 btreemap_insert_blob_8_u64: measurements: - instructions: 589493749 + instructions: 589493727 node_load_v1: 243685209 node_save_v1: 164111004 stable_memory_size: 7 btreemap_insert_blob_8_u64_v2: measurements: - instructions: 697133799 + instructions: 697133777 node_load_v2: 329438301 node_save_v2: 184403609 stable_memory_size: 5 btreemap_insert_u64_blob_8: measurements: - instructions: 611656296 + instructions: 611656274 node_load_v1: 233854938 node_save_v1: 203753854 stable_memory_size: 8 btreemap_insert_u64_blob_8_v2: measurements: - instructions: 679823522 + instructions: 679823500 node_load_v2: 294338080 node_save_v2: 211575679 stable_memory_size: 6 btreemap_insert_u64_u64: measurements: - instructions: 627664728 + instructions: 627664706 node_load_v1: 234409394 node_save_v1: 211208718 stable_memory_size: 8 btreemap_insert_u64_u64_v2: measurements: - instructions: 703623870 + instructions: 703623848 node_load_v2: 300411584 node_save_v2: 220348622 stable_memory_size: 7 +btreemap_iter_count: + measurements: + instructions: 5649483487 + node_load_v2: 1321385334 + stable_memory_size: 1 +btreemap_iter_count_10mib_values: + measurements: + instructions: 165219849597 + node_load_v2: 4219296086 + stable_memory_size: 33 btreemap_remove_blob_128_1024: measurements: - instructions: 1957356649 + instructions: 1957356608 node_load_v1: 914434789 node_save_v1: 514074570 stable_memory_size: 261 btreemap_remove_blob_128_1024_v2: measurements: - instructions: 2117203127 + instructions: 2117203086 node_load_v2: 1032337866 node_save_v2: 556162319 stable_memory_size: 196 btreemap_remove_blob_16_1024: measurements: - instructions: 1247951670 + instructions: 1247951629 node_load_v1: 371456037 node_save_v1: 473518008 stable_memory_size: 216 btreemap_remove_blob_16_1024_v2: measurements: - instructions: 1391842517 + instructions: 1391842476 node_load_v2: 479235617 node_save_v2: 512046945 stable_memory_size: 162 btreemap_remove_blob_256_1024: measurements: - instructions: 2573453911 + instructions: 2573453870 node_load_v1: 1428465620 node_save_v1: 511120662 stable_memory_size: 293 btreemap_remove_blob_256_1024_v2: measurements: - instructions: 2738027594 + instructions: 2738027553 node_load_v2: 1548255619 node_save_v2: 551257725 stable_memory_size: 220 btreemap_remove_blob_32_1024: measurements: - instructions: 1324817959 + instructions: 1324817918 node_load_v1: 403513191 node_save_v1: 492234126 stable_memory_size: 231 btreemap_remove_blob_32_1024_v2: measurements: - instructions: 1476050369 + instructions: 1476050328 node_load_v2: 519013227 node_save_v2: 532132813 stable_memory_size: 174 btreemap_remove_blob_4_1024: measurements: - instructions: 807721649 + instructions: 807721608 node_load_v1: 233144442 node_save_v1: 306452731 stable_memory_size: 124 btreemap_remove_blob_4_1024_v2: measurements: - instructions: 913517563 + instructions: 913517522 node_load_v2: 314086802 node_save_v2: 331046095 stable_memory_size: 93 btreemap_remove_blob_512_1024: measurements: - instructions: 3867652464 + instructions: 3867652423 node_load_v1: 2474030645 node_save_v1: 527547819 stable_memory_size: 352 btreemap_remove_blob_512_1024_v2: measurements: - instructions: 4041285449 + instructions: 4041285408 node_load_v2: 2600718246 node_save_v2: 569534896 stable_memory_size: 264 btreemap_remove_blob_64_1024: measurements: - instructions: 1639040548 + instructions: 1639040507 node_load_v1: 661396112 node_save_v1: 505335855 stable_memory_size: 246 btreemap_remove_blob_64_1024_v2: measurements: - instructions: 1795315618 + instructions: 1795315577 node_load_v2: 778335609 node_save_v2: 546167574 stable_memory_size: 184 btreemap_remove_blob_8_1024: measurements: - instructions: 1038596601 + instructions: 1038596560 node_load_v1: 278756927 node_save_v1: 408063372 stable_memory_size: 184 btreemap_remove_blob_8_1024_v2: measurements: - instructions: 1150784585 + instructions: 1150784544 node_load_v2: 359148126 node_save_v2: 441289916 stable_memory_size: 139 btreemap_remove_blob_8_u64: measurements: - instructions: 756190189 + instructions: 756190148 node_load_v1: 271109869 node_save_v1: 258955340 stable_memory_size: 7 btreemap_remove_blob_8_u64_v2: measurements: - instructions: 902070967 + instructions: 902070926 node_load_v2: 371425008 node_save_v2: 300237913 stable_memory_size: 5 btreemap_remove_u64_blob_8: measurements: - instructions: 846321611 + instructions: 846321570 node_load_v1: 263317086 node_save_v1: 354096302 stable_memory_size: 8 btreemap_remove_u64_blob_8_v2: measurements: - instructions: 935942012 + instructions: 935941971 node_load_v2: 329460173 node_save_v2: 373120565 stable_memory_size: 6 btreemap_remove_u64_u64: measurements: - instructions: 874256488 + instructions: 874256447 node_load_v1: 264707458 node_save_v1: 370018389 stable_memory_size: 8 btreemap_remove_u64_u64_v2: measurements: - instructions: 976419924 + instructions: 976419883 node_load_v2: 337138522 node_save_v2: 394608862 stable_memory_size: 7 memory_manager_baseline: measurements: - instructions: 1144 + instructions: 1122 stable_memory_size: 8000 memory_manager_grow: measurements: - instructions: 287018881 + instructions: 287018859 stable_memory_size: 32001 memory_manager_overhead: measurements: - instructions: 4605248 + instructions: 4605226 stable_memory_size: 8321 vec_get_blob_128: measurements: - instructions: 22055455 + instructions: 22055433 stable_memory_size: 20 vec_get_blob_16: measurements: - instructions: 11055138 + instructions: 11055116 stable_memory_size: 3 vec_get_blob_32: measurements: - instructions: 11849080 + instructions: 11849058 stable_memory_size: 6 vec_get_blob_4: measurements: - instructions: 6830239 + instructions: 6830217 stable_memory_size: 1 vec_get_blob_64: measurements: - instructions: 16495665 + instructions: 16495643 stable_memory_size: 10 vec_get_blob_8: measurements: - instructions: 8222880 + instructions: 8222858 stable_memory_size: 2 vec_get_u64: measurements: - instructions: 7450346 + instructions: 7450324 stable_memory_size: 2 vec_insert_blob_128: measurements: - instructions: 4942837 + instructions: 4942815 stable_memory_size: 20 vec_insert_blob_16: measurements: - instructions: 4880610 + instructions: 4880588 stable_memory_size: 3 vec_insert_blob_32: measurements: - instructions: 4941003 + instructions: 4940981 stable_memory_size: 6 vec_insert_blob_4: measurements: - instructions: 4940348 + instructions: 4940326 stable_memory_size: 1 vec_insert_blob_64: measurements: - instructions: 4941527 + instructions: 4941505 stable_memory_size: 10 vec_insert_blob_8: measurements: - instructions: 4940479 + instructions: 4940457 stable_memory_size: 2 vec_insert_u64: measurements: - instructions: 7600479 + instructions: 7750457 stable_memory_size: 2 From aa45bf37f7d28486dad3239495616489855b62fc Mon Sep 17 00:00:00 2001 From: Dragoljub Duric Date: Fri, 9 Feb 2024 15:21:25 +0000 Subject: [PATCH 2/6] . --- .github/workflows/ci.yml | 2 +- rust-toolchain.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8edd4557..de0dcfcf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,7 +6,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - rust: [ 1.73.0 ] + rust: [ 1.76.0 ] steps: - uses: actions/checkout@v2 diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 6b9ac7bc..2cfa2b89 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "1.73.0" +channel = "1.76.0" targets = ["wasm32-unknown-unknown"] From b328ff6bdcf8fa691660e9114df87d13f63fc853 Mon Sep 17 00:00:00 2001 From: Dragoljub Duric Date: Fri, 9 Feb 2024 15:26:44 +0000 Subject: [PATCH 3/6] . --- src/btreemap/node/v2.rs | 2 +- src/lib.rs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/btreemap/node/v2.rs b/src/btreemap/node/v2.rs index b051921b..6d9cde7d 100644 --- a/src/btreemap/node/v2.rs +++ b/src/btreemap/node/v2.rs @@ -233,7 +233,7 @@ impl Node { // Add a null overflow address. // This might get overwritten later in case the node does overflow. - writer.write_u64(offset, self.overflows.get(0).unwrap_or(&NULL).get()); + writer.write_u64(offset, self.overflows.first().unwrap_or(&NULL).get()); offset += Bytes::from(8u64); // Write the children diff --git a/src/lib.rs b/src/lib.rs index 11ebfff7..efe8d1b1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -97,8 +97,7 @@ impl Display for GrowFailed { write!( f, "Failed to grow memory: current size={}, delta={}", - self.current_size, - self.delta + self.current_size, self.delta ) } } From 404a4817661ef6c88ee77785e75dcbe5b5f22d8b Mon Sep 17 00:00:00 2001 From: Dragoljub Djuric Date: Fri, 9 Feb 2024 16:31:06 +0100 Subject: [PATCH 4/6] Update benchmarks/src/btreemap.rs Co-authored-by: Islam El-Ashi --- benchmarks/src/btreemap.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmarks/src/btreemap.rs b/benchmarks/src/btreemap.rs index 2ffc683f..a7b8a20f 100644 --- a/benchmarks/src/btreemap.rs +++ b/benchmarks/src/btreemap.rs @@ -222,7 +222,7 @@ pub fn btreemap_insert_10mib_values() -> BenchResult { } #[bench] -pub fn btreemap_iter_count() -> BenchResult { +pub fn btreemap_iter_count_small_values() -> BenchResult { let mut btree = BTreeMap::new(DefaultMemoryImpl::default()); let size: u8 = 200; for i in 0..size { From 86c99bc8bc60bab7c7f4d631b7d391916affb06d Mon Sep 17 00:00:00 2001 From: Dragoljub Duric Date: Fri, 9 Feb 2024 15:50:21 +0000 Subject: [PATCH 5/6] Apply comments --- benchmarks/src/btreemap.rs | 38 ++++++++++++-------------------------- canbench_results.yml | 14 +++++++------- 2 files changed, 19 insertions(+), 33 deletions(-) diff --git a/benchmarks/src/btreemap.rs b/benchmarks/src/btreemap.rs index a7b8a20f..3c390a6d 100644 --- a/benchmarks/src/btreemap.rs +++ b/benchmarks/src/btreemap.rs @@ -224,19 +224,15 @@ pub fn btreemap_insert_10mib_values() -> BenchResult { #[bench] pub fn btreemap_iter_count_small_values() -> BenchResult { let mut btree = BTreeMap::new(DefaultMemoryImpl::default()); - let size: u8 = 200; + let size: u32 = 2000; for i in 0..size { - btree.insert(i, i); + btree.insert(i, vec![]); } benchmark(|| { - for i in 0..size { - for j in i + 1..size { - btree - .range((Bound::Included(i), Bound::Included(j))) - .count(); - } - } + btree + .range((Bound::Included(0), Bound::Included(size))) + .count(); }) } @@ -244,27 +240,17 @@ pub fn btreemap_iter_count_small_values() -> BenchResult { pub fn btreemap_iter_count_10mib_values() -> BenchResult { let mut btree = BTreeMap::new(DefaultMemoryImpl::default()); - // Insert 200 10MiB values. - let mut rng = Rng::from_seed(0); - let mut values = vec![]; - for _ in 0..200 { - values.push(rng.iter(Rand::rand_u8).take(10 * 1024).collect::>()); - } + let size: u8 = 200; - let mut i = 0u8; - for value in values.into_iter() { - btree.insert(i, value); - i += 1; + // Insert 200 10MiB values. + for i in 0..size { + btree.insert(i, vec![0u8; 10 * 1024]); } benchmark(|| { - for j in 0..i { - for k in j + 1..i { - btree - .range((Bound::Included(j), Bound::Included(k))) - .count(); - } - } + btree + .range((Bound::Included(0), Bound::Included(size))) + .count(); }) } diff --git a/canbench_results.yml b/canbench_results.yml index adea6cc1..bffd0b47 100644 --- a/canbench_results.yml +++ b/canbench_results.yml @@ -342,16 +342,16 @@ btreemap_insert_u64_u64_v2: node_load_v2: 300411584 node_save_v2: 220348622 stable_memory_size: 7 -btreemap_iter_count: - measurements: - instructions: 5649483487 - node_load_v2: 1321385334 - stable_memory_size: 1 btreemap_iter_count_10mib_values: measurements: - instructions: 165219849597 - node_load_v2: 4219296086 + instructions: 24074759 + node_load_v2: 520223 stable_memory_size: 33 +btreemap_iter_count_small_values: + measurements: + instructions: 6105654 + node_load_v2: 1641534 + stable_memory_size: 7 btreemap_remove_blob_128_1024: measurements: instructions: 1957356608 From a873bfb68513755f6e330cdcd3d3f571f36c6028 Mon Sep 17 00:00:00 2001 From: Dragoljub Duric Date: Mon, 12 Feb 2024 10:41:09 +0000 Subject: [PATCH 6/6] Change benchmark BTreeMap size to 10000. --- benchmarks/src/btreemap.rs | 2 +- canbench_results.yml | 496 ++++++++++++++++++------------------- 2 files changed, 249 insertions(+), 249 deletions(-) diff --git a/benchmarks/src/btreemap.rs b/benchmarks/src/btreemap.rs index 3c390a6d..39f5ed8b 100644 --- a/benchmarks/src/btreemap.rs +++ b/benchmarks/src/btreemap.rs @@ -224,7 +224,7 @@ pub fn btreemap_insert_10mib_values() -> BenchResult { #[bench] pub fn btreemap_iter_count_small_values() -> BenchResult { let mut btree = BTreeMap::new(DefaultMemoryImpl::default()); - let size: u32 = 2000; + let size: u32 = 10_000; for i in 0..size { btree.insert(i, vec![]); } diff --git a/canbench_results.yml b/canbench_results.yml index bffd0b47..cdad989b 100644 --- a/canbench_results.yml +++ b/canbench_results.yml @@ -1,488 +1,488 @@ btreemap_get_blob_128_1024: measurements: - instructions: 1006573497 - node_load_v1: 832328557 + instructions: 918297550 + node_load_v1: 754035202 stable_memory_size: 261 btreemap_get_blob_128_1024_v2: measurements: - instructions: 1123805949 - node_load_v2: 938155476 + instructions: 1012404828 + node_load_v2: 838471112 stable_memory_size: 196 btreemap_get_blob_16_1024: measurements: - instructions: 487229765 - node_load_v1: 339804418 + instructions: 402489372 + node_load_v1: 265476351 stable_memory_size: 216 btreemap_get_blob_16_1024_v2: measurements: - instructions: 583474930 - node_load_v2: 430852270 + instructions: 483065575 + node_load_v2: 341517378 stable_memory_size: 162 btreemap_get_blob_256_1024: measurements: - instructions: 1510660899 - node_load_v1: 1309093774 + instructions: 1419922692 + node_load_v1: 1228326401 stable_memory_size: 293 btreemap_get_blob_256_1024_v2: measurements: - instructions: 1626341637 - node_load_v2: 1410845462 + instructions: 1514269692 + node_load_v2: 1310914461 stable_memory_size: 220 btreemap_get_blob_32_1024: measurements: - instructions: 534895181 - node_load_v1: 378516147 + instructions: 445863040 + node_load_v1: 300380122 stable_memory_size: 231 btreemap_get_blob_32_1024_v2: measurements: - instructions: 633048450 - node_load_v2: 471574348 + instructions: 526615123 + node_load_v2: 376711582 stable_memory_size: 174 btreemap_get_blob_4_1024: measurements: - instructions: 355650494 - node_load_v1: 231720942 + instructions: 276611192 + node_load_v1: 161238932 stable_memory_size: 124 btreemap_get_blob_4_1024_v2: measurements: - instructions: 446660391 - node_load_v2: 313869359 + instructions: 355490148 + node_load_v2: 232414919 stable_memory_size: 93 btreemap_get_blob_512_1024: measurements: - instructions: 2506597857 - node_load_v1: 2251570705 + instructions: 2415920006 + node_load_v1: 2170866594 stable_memory_size: 352 btreemap_get_blob_512_1024_v2: measurements: - instructions: 2625838011 - node_load_v2: 2356816367 + instructions: 2511422025 + node_load_v2: 2254559660 stable_memory_size: 264 btreemap_get_blob_64_1024: measurements: - instructions: 780061485 - node_load_v1: 616669297 + instructions: 688360199 + node_load_v1: 535401984 stable_memory_size: 246 btreemap_get_blob_64_1024_v2: measurements: - instructions: 878745122 - node_load_v2: 706540951 + instructions: 769311566 + node_load_v2: 608827767 stable_memory_size: 184 btreemap_get_blob_8_1024: measurements: - instructions: 406432537 - node_load_v1: 259168629 + instructions: 324971280 + node_load_v1: 187633627 stable_memory_size: 184 btreemap_get_blob_8_1024_v2: measurements: - instructions: 493282884 - node_load_v2: 336415667 + instructions: 402008927 + node_load_v2: 256407446 stable_memory_size: 139 btreemap_get_blob_8_u64: measurements: - instructions: 368106552 - node_load_v1: 253569163 + instructions: 293440780 + node_load_v1: 187956979 stable_memory_size: 7 btreemap_get_blob_8_u64_v2: measurements: - instructions: 466009037 - node_load_v2: 345475118 + instructions: 372798113 + node_load_v2: 262576982 stable_memory_size: 5 btreemap_get_u64_blob_8: measurements: - instructions: 351156426 - node_load_v1: 250986516 + instructions: 274218978 + node_load_v1: 182442985 stable_memory_size: 8 btreemap_get_u64_blob_8_v2: measurements: - instructions: 413554253 - node_load_v2: 309705639 + instructions: 331020864 + node_load_v2: 236444481 stable_memory_size: 6 btreemap_get_u64_u64: measurements: - instructions: 353621423 - node_load_v1: 249502481 + instructions: 276850992 + node_load_v1: 181567530 stable_memory_size: 8 btreemap_get_u64_u64_v2: measurements: - instructions: 422146318 - node_load_v2: 312364993 + instructions: 338418081 + node_load_v2: 238660311 stable_memory_size: 7 btreemap_insert_10mib_values: measurements: - instructions: 107942333 - node_load_v2: 10057317 - node_save_v2: 77823608 + instructions: 99997294 + node_load_v2: 7855891 + node_save_v2: 72799502 stable_memory_size: 33 btreemap_insert_blob_1024_128: measurements: - instructions: 5115889409 - node_load_v1: 4062772095 - node_save_v1: 185771186 + instructions: 4984105840 + node_load_v1: 3988909453 + node_save_v1: 146460142 stable_memory_size: 263 btreemap_insert_blob_1024_128_v2: measurements: - instructions: 5394772418 - node_load_v2: 4190686429 - node_save_v2: 206085822 + instructions: 5239604456 + node_load_v2: 4090603010 + node_save_v2: 171846832 stable_memory_size: 197 btreemap_insert_blob_1024_16: measurements: - instructions: 5074839695 - node_load_v1: 4058526995 - node_save_v1: 172957200 + instructions: 4944664880 + node_load_v1: 3985448476 + node_save_v1: 133442320 stable_memory_size: 242 btreemap_insert_blob_1024_16_v2: measurements: - instructions: 5358731352 - node_load_v2: 4195507437 - node_save_v2: 193208733 + instructions: 5204903603 + node_load_v2: 4095654733 + node_save_v2: 158980711 stable_memory_size: 182 btreemap_insert_blob_1024_256: measurements: - instructions: 5130740050 - node_load_v1: 4039224210 - node_save_v1: 201310396 + instructions: 4998981709 + node_load_v1: 3965654660 + node_save_v1: 161983415 stable_memory_size: 293 btreemap_insert_blob_1024_256_v2: measurements: - instructions: 5352948930 - node_load_v2: 4171364974 - node_save_v2: 221531887 + instructions: 5197123201 + node_load_v2: 4070258951 + node_save_v2: 187329183 stable_memory_size: 220 btreemap_insert_blob_1024_32: measurements: - instructions: 5089791763 - node_load_v1: 4079908295 - node_save_v1: 173954636 + instructions: 4958594629 + node_load_v1: 4005822869 + node_save_v1: 134559317 stable_memory_size: 240 btreemap_insert_blob_1024_32_v2: measurements: - instructions: 5357513444 - node_load_v2: 4214236378 - node_save_v2: 194114909 + instructions: 5202700273 + node_load_v2: 4113362166 + node_save_v2: 159929338 stable_memory_size: 181 btreemap_insert_blob_1024_4: measurements: - instructions: 4968257190 - node_load_v1: 4058890666 - node_save_v1: 162657999 + instructions: 4840591273 + node_load_v1: 3985365549 + node_save_v1: 124687423 stable_memory_size: 236 btreemap_insert_blob_1024_4_v2: measurements: - instructions: 5264404209 - node_load_v2: 4189301776 - node_save_v2: 182905394 + instructions: 5113551566 + node_load_v2: 4089690715 + node_save_v2: 150184318 stable_memory_size: 177 btreemap_insert_blob_1024_512: measurements: - instructions: 5224338902 - node_load_v1: 4064093845 - node_save_v1: 236696639 + instructions: 5087635883 + node_load_v1: 3989806728 + node_save_v1: 193925745 stable_memory_size: 349 btreemap_insert_blob_1024_512_v2: measurements: - instructions: 5481571946 - node_load_v2: 4201549676 - node_save_v2: 257610609 + instructions: 5320097350 + node_load_v2: 4099519139 + node_save_v2: 219719584 stable_memory_size: 262 btreemap_insert_blob_1024_64: measurements: - instructions: 5110806921 - node_load_v1: 4075394290 - node_save_v1: 178905580 + instructions: 4979331968 + node_load_v1: 4001759787 + node_save_v1: 139286228 stable_memory_size: 251 btreemap_insert_blob_1024_64_v2: measurements: - instructions: 5377434434 - node_load_v2: 4214020891 - node_save_v2: 199157099 + instructions: 5221310486 + node_load_v2: 4112538215 + node_save_v2: 164772561 stable_memory_size: 189 btreemap_insert_blob_1024_8: measurements: - instructions: 5053776958 - node_load_v1: 4051194851 - node_save_v1: 167362943 + instructions: 4924885892 + node_load_v1: 3978237186 + node_save_v1: 128434218 stable_memory_size: 238 btreemap_insert_blob_1024_8_v2: measurements: - instructions: 5331593885 - node_load_v2: 4181516149 - node_save_v2: 187604446 + instructions: 5179644486 + node_load_v2: 4082400473 + node_save_v2: 153945446 stable_memory_size: 179 btreemap_insert_blob_128_1024: measurements: - instructions: 1577091191 - node_load_v1: 812526962 - node_save_v1: 301462572 + instructions: 1437616292 + node_load_v1: 739027550 + node_save_v1: 257309360 stable_memory_size: 261 btreemap_insert_blob_128_1024_v2: measurements: - instructions: 1726441499 - node_load_v2: 925130424 - node_save_v2: 322015815 + instructions: 1565933845 + node_load_v2: 826942435 + node_save_v2: 283053248 stable_memory_size: 196 btreemap_insert_blob_16_1024: measurements: - instructions: 992366695 - node_load_v1: 322073344 - node_save_v1: 291094888 + instructions: 858846535 + node_load_v1: 253207451 + node_save_v1: 248356858 stable_memory_size: 216 btreemap_insert_blob_16_1024_v2: measurements: - instructions: 1108674222 - node_load_v2: 419541518 - node_save_v2: 310638874 + instructions: 960083194 + node_load_v2: 330853838 + node_save_v2: 273042097 stable_memory_size: 162 btreemap_insert_blob_256_1024: measurements: - instructions: 2114284627 - node_load_v1: 1278881721 - node_save_v1: 300728644 + instructions: 1974624891 + node_load_v1: 1204369041 + node_save_v1: 256351524 stable_memory_size: 293 btreemap_insert_blob_256_1024_v2: measurements: - instructions: 2273386977 - node_load_v2: 1395147359 - node_save_v2: 321544817 + instructions: 2111102480 + node_load_v2: 1294504838 + node_save_v2: 282314461 stable_memory_size: 220 btreemap_insert_blob_32_1024: measurements: - instructions: 1041724155 - node_load_v1: 358626551 - node_save_v1: 298295476 + instructions: 904010965 + node_load_v1: 286588753 + node_save_v1: 254796471 stable_memory_size: 231 btreemap_insert_blob_32_1024_v2: measurements: - instructions: 1156895156 - node_load_v2: 459271136 - node_save_v2: 316798162 + instructions: 1004184959 + node_load_v2: 366954442 + node_save_v2: 278850203 stable_memory_size: 174 btreemap_insert_blob_4_1024: measurements: - instructions: 772106337 - node_load_v1: 212848724 - node_save_v1: 267119730 + instructions: 652382785 + node_load_v1: 149831245 + node_save_v1: 228197043 stable_memory_size: 124 btreemap_insert_blob_4_1024_v2: measurements: - instructions: 862904886 - node_load_v2: 286322995 - node_save_v2: 284380143 + instructions: 736453619 + node_load_v2: 212173910 + node_save_v2: 250260310 stable_memory_size: 93 btreemap_insert_blob_512_1024: measurements: - instructions: 3195541970 - node_load_v1: 2200910325 - node_save_v1: 306828402 + instructions: 3053462673 + node_load_v1: 2124633848 + node_save_v1: 261440735 stable_memory_size: 352 btreemap_insert_blob_512_1024_v2: measurements: - instructions: 3317431084 - node_load_v2: 2302979370 - node_save_v2: 323365428 + instructions: 3155320531 + node_load_v2: 2201526645 + node_save_v2: 283885891 stable_memory_size: 264 btreemap_insert_blob_64_1024: measurements: - instructions: 1305958969 - node_load_v1: 584672643 - node_save_v1: 300400388 + instructions: 1166106772 + node_load_v1: 510883301 + node_save_v1: 256301205 stable_memory_size: 246 btreemap_insert_blob_64_1024_v2: measurements: - instructions: 1439210431 - node_load_v2: 692993072 - node_save_v2: 319569550 + instructions: 1279910739 + node_load_v2: 595578889 + node_save_v2: 280900588 stable_memory_size: 184 btreemap_insert_blob_8_1024: measurements: - instructions: 905706853 - node_load_v1: 247335003 - node_save_v1: 284445265 + instructions: 776453148 + node_load_v1: 179790788 + node_save_v1: 242797687 stable_memory_size: 184 btreemap_insert_blob_8_1024_v2: measurements: - instructions: 1002633694 - node_load_v2: 325787553 - node_save_v2: 303101882 + instructions: 866232312 + node_load_v2: 246352950 + node_save_v2: 266596061 stable_memory_size: 139 btreemap_insert_blob_8_u64: measurements: - instructions: 589493727 - node_load_v1: 243685209 - node_save_v1: 164111004 + instructions: 472686878 + node_load_v1: 181986700 + node_save_v1: 126883358 stable_memory_size: 7 btreemap_insert_blob_8_u64_v2: measurements: - instructions: 697133777 - node_load_v2: 329438301 - node_save_v2: 184403609 + instructions: 566706828 + node_load_v2: 250601037 + node_save_v2: 151769417 stable_memory_size: 5 btreemap_insert_u64_blob_8: measurements: - instructions: 611656274 - node_load_v1: 233854938 - node_save_v1: 203753854 + instructions: 480324223 + node_load_v1: 170565445 + node_save_v1: 153183226 stable_memory_size: 8 btreemap_insert_u64_blob_8_v2: measurements: - instructions: 679823500 - node_load_v2: 294338080 - node_save_v2: 211575679 + instructions: 548609694 + node_load_v2: 224781217 + node_save_v2: 168239993 stable_memory_size: 6 btreemap_insert_u64_u64: measurements: - instructions: 627664706 - node_load_v1: 234409394 - node_save_v1: 211208718 + instructions: 494167871 + node_load_v1: 171859779 + node_save_v1: 159769002 stable_memory_size: 8 btreemap_insert_u64_u64_v2: measurements: - instructions: 703623848 - node_load_v2: 300411584 - node_save_v2: 220348622 + instructions: 569015520 + node_load_v2: 230782820 + node_save_v2: 175856694 stable_memory_size: 7 btreemap_iter_count_10mib_values: measurements: - instructions: 24074759 - node_load_v2: 520223 + instructions: 23627527 + node_load_v2: 402287 stable_memory_size: 33 btreemap_iter_count_small_values: measurements: - instructions: 6105654 - node_load_v2: 1641534 - stable_memory_size: 7 + instructions: 27195467 + node_load_v2: 6367125 + stable_memory_size: 32 btreemap_remove_blob_128_1024: measurements: - instructions: 1957356608 - node_load_v1: 914434789 - node_save_v1: 514074570 + instructions: 1765436627 + node_load_v1: 831238789 + node_save_v1: 435218602 stable_memory_size: 261 btreemap_remove_blob_128_1024_v2: measurements: - instructions: 2117203086 - node_load_v2: 1032337866 - node_save_v2: 556162319 + instructions: 1910258373 + node_load_v2: 925249945 + node_save_v2: 487653874 stable_memory_size: 196 btreemap_remove_blob_16_1024: measurements: - instructions: 1247951629 - node_load_v1: 371456037 - node_save_v1: 473518008 + instructions: 1070289873 + node_load_v1: 293118687 + node_save_v1: 401442409 stable_memory_size: 216 btreemap_remove_blob_16_1024_v2: measurements: - instructions: 1391842476 - node_load_v2: 479235617 - node_save_v2: 512046945 + instructions: 1203248521 + node_load_v2: 381414821 + node_save_v2: 449480819 stable_memory_size: 162 btreemap_remove_blob_256_1024: measurements: - instructions: 2573453870 - node_load_v1: 1428465620 - node_save_v1: 511120662 + instructions: 2382407241 + node_load_v1: 1344675202 + node_save_v1: 432970452 stable_memory_size: 293 btreemap_remove_blob_256_1024_v2: measurements: - instructions: 2738027553 - node_load_v2: 1548255619 - node_save_v2: 551257725 + instructions: 2530218035 + node_load_v2: 1439645617 + node_save_v2: 483420926 stable_memory_size: 220 btreemap_remove_blob_32_1024: measurements: - instructions: 1324817918 - node_load_v1: 403513191 - node_save_v1: 492234126 + instructions: 1140153781 + node_load_v1: 322843280 + node_save_v1: 417148893 stable_memory_size: 231 btreemap_remove_blob_32_1024_v2: measurements: - instructions: 1476050328 - node_load_v2: 519013227 - node_save_v2: 532132813 + instructions: 1278111352 + node_load_v2: 415907179 + node_save_v2: 466999763 stable_memory_size: 174 btreemap_remove_blob_4_1024: measurements: - instructions: 807721608 - node_load_v1: 233144442 - node_save_v1: 306452731 + instructions: 674418478 + node_load_v1: 164435030 + node_save_v1: 259959839 stable_memory_size: 124 btreemap_remove_blob_4_1024_v2: measurements: - instructions: 913517522 - node_load_v2: 314086802 - node_save_v2: 331046095 + instructions: 773931207 + node_load_v2: 233938221 + node_save_v2: 290606040 stable_memory_size: 93 btreemap_remove_blob_512_1024: measurements: - instructions: 3867652423 - node_load_v1: 2474030645 - node_save_v1: 527547819 + instructions: 3671936473 + node_load_v1: 2390036799 + node_save_v1: 446122393 stable_memory_size: 352 btreemap_remove_blob_512_1024_v2: measurements: - instructions: 4041285408 - node_load_v2: 2600718246 - node_save_v2: 569534896 + instructions: 3826090329 + node_load_v2: 2488915437 + node_save_v2: 498703262 stable_memory_size: 264 btreemap_remove_blob_64_1024: measurements: - instructions: 1639040507 - node_load_v1: 661396112 - node_save_v1: 505335855 + instructions: 1448155157 + node_load_v1: 577581483 + node_save_v1: 428020659 stable_memory_size: 246 btreemap_remove_blob_64_1024_v2: measurements: - instructions: 1795315577 - node_load_v2: 778335609 - node_save_v2: 546167574 + instructions: 1590358981 + node_load_v2: 671421671 + node_save_v2: 479097166 stable_memory_size: 184 btreemap_remove_blob_8_1024: measurements: - instructions: 1038596560 - node_load_v1: 278756927 - node_save_v1: 408063372 + instructions: 877475340 + node_load_v1: 203792348 + node_save_v1: 345768939 stable_memory_size: 184 btreemap_remove_blob_8_1024_v2: measurements: - instructions: 1150784544 - node_load_v2: 359148126 - node_save_v2: 441289916 + instructions: 986682953 + node_load_v2: 274023708 + node_save_v2: 387155036 stable_memory_size: 139 btreemap_remove_blob_8_u64: measurements: - instructions: 756190148 - node_load_v1: 271109869 - node_save_v1: 258955340 + instructions: 607672459 + node_load_v1: 202072945 + node_save_v1: 200360852 stable_memory_size: 7 btreemap_remove_blob_8_u64_v2: measurements: - instructions: 902070926 - node_load_v2: 371425008 - node_save_v2: 300237913 + instructions: 739316591 + node_load_v2: 283135159 + node_save_v2: 248529586 stable_memory_size: 5 btreemap_remove_u64_blob_8: measurements: - instructions: 846321570 - node_load_v1: 263317086 - node_save_v1: 354096302 + instructions: 669856911 + node_load_v1: 192918268 + node_save_v1: 269708119 stable_memory_size: 8 btreemap_remove_u64_blob_8_v2: measurements: - instructions: 935941971 - node_load_v2: 329460173 - node_save_v2: 373120565 + instructions: 765304028 + node_load_v2: 253212163 + node_save_v2: 302212433 stable_memory_size: 6 btreemap_remove_u64_u64: measurements: - instructions: 874256447 - node_load_v1: 264707458 - node_save_v1: 370018389 + instructions: 693077801 + node_load_v1: 193826722 + node_save_v1: 283366051 stable_memory_size: 8 btreemap_remove_u64_u64_v2: measurements: - instructions: 976419883 - node_load_v2: 337138522 - node_save_v2: 394608862 + instructions: 797832204 + node_load_v2: 258765788 + node_save_v2: 320071273 stable_memory_size: 7 memory_manager_baseline: measurements: @@ -490,65 +490,65 @@ memory_manager_baseline: stable_memory_size: 8000 memory_manager_grow: measurements: - instructions: 287018859 + instructions: 284711825 stable_memory_size: 32001 memory_manager_overhead: measurements: - instructions: 4605226 + instructions: 4523476 stable_memory_size: 8321 vec_get_blob_128: measurements: - instructions: 22055433 + instructions: 20697043 stable_memory_size: 20 vec_get_blob_16: measurements: - instructions: 11055116 + instructions: 9639316 stable_memory_size: 3 vec_get_blob_32: measurements: - instructions: 11849058 + instructions: 10445322 stable_memory_size: 6 vec_get_blob_4: measurements: - instructions: 6830217 + instructions: 5683767 stable_memory_size: 1 vec_get_blob_64: measurements: - instructions: 16495643 + instructions: 15108707 stable_memory_size: 10 vec_get_blob_8: measurements: - instructions: 8222858 + instructions: 6902502 stable_memory_size: 2 vec_get_u64: measurements: - instructions: 7450324 + instructions: 6170324 stable_memory_size: 2 vec_insert_blob_128: measurements: - instructions: 4942815 + instructions: 3682815 stable_memory_size: 20 vec_insert_blob_16: measurements: - instructions: 4880588 + instructions: 3680588 stable_memory_size: 3 vec_insert_blob_32: measurements: - instructions: 4940981 + instructions: 3680981 stable_memory_size: 6 vec_insert_blob_4: measurements: - instructions: 4940326 + instructions: 3680326 stable_memory_size: 1 vec_insert_blob_64: measurements: - instructions: 4941505 + instructions: 3681505 stable_memory_size: 10 vec_insert_blob_8: measurements: - instructions: 4940457 + instructions: 3680457 stable_memory_size: 2 vec_insert_u64: measurements: - instructions: 7750457 + instructions: 5710457 stable_memory_size: 2