diff --git a/benchmarks/Cargo.toml b/benchmarks/Cargo.toml index 753b1972..a2b6e6e5 100644 --- a/benchmarks/Cargo.toml +++ b/benchmarks/Cargo.toml @@ -11,6 +11,7 @@ candid.workspace = true ic-cdk-macros.workspace = true ic-cdk.workspace = true ic-stable-structures = { path = "../", features = [] } +#ic-stable-structures = { path = "../", features = ["bench_scope"] } maplit.workspace = true serde.workspace = true tiny-rng.workspace = true diff --git a/benchmarks/btreemap/canbench_results.yml b/benchmarks/btreemap/canbench_results.yml index 7d2d237a..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: 142211173 + instructions: 142211043 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob8_u64: total: calls: 1 - instructions: 284729276 + instructions: 284589786 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_1024_128: total: calls: 1 - instructions: 4287195962 + instructions: 4287068465 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_128_128: total: calls: 1 - instructions: 833911660 + instructions: 833784184 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_16_128: total: calls: 1 - instructions: 301679312 + instructions: 301551729 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_256_128: total: calls: 1 - instructions: 1319638527 + instructions: 1319511032 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_1024: total: calls: 1 - instructions: 335467579 + instructions: 335340051 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_128: total: calls: 1 - instructions: 335857875 + instructions: 335730320 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_16: total: calls: 1 - instructions: 328808633 + instructions: 328681132 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_256: total: calls: 1 - instructions: 334434277 + instructions: 334306724 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_32: total: calls: 1 - instructions: 339847402 + instructions: 339719884 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_4: total: calls: 1 - instructions: 332340488 + instructions: 332212967 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_512: total: calls: 1 - instructions: 331695205 + instructions: 331567691 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_64: total: calls: 1 - instructions: 334858994 + instructions: 334731486 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_32_8: total: calls: 1 - instructions: 334584158 + instructions: 334456608 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_4_128: total: calls: 1 - instructions: 253347390 + instructions: 253230618 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_512_128: total: calls: 1 - instructions: 2290838029 + instructions: 2290710550 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_64_128: total: calls: 1 - instructions: 414363928 + instructions: 414236409 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_blob_8_128: total: calls: 1 - instructions: 275816922 + instructions: 275689469 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_u64_blob8: total: calls: 1 - instructions: 227932672 + instructions: 227988492 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_u64_u64: total: calls: 1 - instructions: 233050993 + instructions: 233100051 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_u64_vec8: total: calls: 1 - instructions: 227932672 + instructions: 227988492 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec8_u64: total: calls: 1 - instructions: 380704254 + instructions: 381896109 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_1024_128: total: calls: 1 - instructions: 1824658598 + instructions: 1825765218 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_128_128: total: calls: 1 - instructions: 574277483 + instructions: 575403799 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_16_128: total: calls: 1 - instructions: 448376101 + instructions: 449528879 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_256_128: total: calls: 1 - instructions: 902317934 + instructions: 903444395 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_1024: total: calls: 1 - instructions: 514204302 + instructions: 515311243 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_128: total: calls: 1 - instructions: 428712852 + instructions: 429852442 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_16: total: calls: 1 - instructions: 375067406 + instructions: 376261507 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_256: total: calls: 1 - instructions: 441718228 + instructions: 442845574 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_32: total: calls: 1 - instructions: 363350869 + instructions: 364544986 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_4: total: calls: 1 - instructions: 368447206 + instructions: 369641376 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_512: total: calls: 1 - instructions: 460605845 + instructions: 461732663 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_64: total: calls: 1 - instructions: 407446580 + instructions: 408623694 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_32_8: total: calls: 1 - instructions: 360599985 + instructions: 361794590 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_4_128: total: calls: 1 - instructions: 412997571 + instructions: 413937091 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_512_128: total: calls: 1 - instructions: 1252406681 + instructions: 1253533021 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_64_128: total: calls: 1 - instructions: 506200295 + instructions: 507328031 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_contains_vec_8_128: total: calls: 1 - instructions: 402314964 + instructions: 403472521 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_10mib_values: total: calls: 1 - instructions: 388591796 + instructions: 388593444 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob8_u64: total: calls: 1 - instructions: 305721002 + instructions: 306985951 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_1024_128: total: calls: 1 - instructions: 4425292179 + instructions: 4468917732 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_128_128: total: calls: 1 - instructions: 866438615 + instructions: 874885878 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_16_128: total: calls: 1 - instructions: 314408609 + instructions: 317946651 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_256_128: total: calls: 1 - instructions: 1364965202 + instructions: 1377831075 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_1024: total: calls: 1 - instructions: 354108428 + instructions: 358820632 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_128: total: calls: 1 - instructions: 349135019 + instructions: 353395480 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_16: total: calls: 1 - instructions: 338382931 + instructions: 341465501 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_256: total: calls: 1 - instructions: 348736208 + instructions: 353215571 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_32: total: calls: 1 - instructions: 350096818 + instructions: 353560413 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_4: total: calls: 1 - instructions: 340412926 + instructions: 343423643 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_512: total: calls: 1 - instructions: 347642364 + instructions: 352284128 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_64: total: calls: 1 - instructions: 346801708 + instructions: 350593383 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_32_8: total: calls: 1 - instructions: 343068558 + instructions: 346117255 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_4_128: total: calls: 1 - instructions: 264255336 + instructions: 264595013 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_512_128: total: calls: 1 - instructions: 2367049394 + instructions: 2390162752 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_64_128: total: calls: 1 - instructions: 436964612 + instructions: 442751803 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_blob_8_128: total: calls: 1 - instructions: 287796661 + instructions: 288637500 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_u64_blob8: total: calls: 1 - instructions: 237235807 + instructions: 236902495 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_u64_u64: total: calls: 1 - instructions: 243863619 + instructions: 244070893 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_u64_vec8: total: calls: 1 - instructions: 237991852 + instructions: 237695355 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec8_u64: total: calls: 1 - instructions: 388751746 + instructions: 387372198 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_1024_128: total: calls: 1 - instructions: 1841512514 + instructions: 1840901847 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_128_128: total: calls: 1 - instructions: 583901094 + instructions: 584411524 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_16_128: total: calls: 1 - instructions: 456729377 + instructions: 456289282 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_256_128: total: calls: 1 - instructions: 912188247 + instructions: 912705843 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_1024: total: calls: 1 - instructions: 552829330 + instructions: 539669193 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_128: total: calls: 1 - instructions: 437331840 + instructions: 437496159 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_16: total: calls: 1 - instructions: 381657975 + instructions: 382104186 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_256: total: calls: 1 - instructions: 457027782 + instructions: 456882291 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_32: total: calls: 1 - instructions: 370072283 + instructions: 370530527 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_4: total: calls: 1 - instructions: 374915812 + instructions: 375360033 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_512: total: calls: 1 - instructions: 480046387 + instructions: 479727856 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_64: total: calls: 1 - instructions: 414392801 + instructions: 414929747 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_32_8: total: calls: 1 - instructions: 367113865 + instructions: 367555913 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_4_128: total: calls: 1 - instructions: 421113110 + instructions: 420987616 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_512_128: total: calls: 1 - instructions: 1262553242 + instructions: 1262785802 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_64_128: total: calls: 1 - instructions: 514950921 + instructions: 515572988 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_get_vec_8_128: total: calls: 1 - instructions: 410396741 + 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: 2376508246 + instructions: 2376380756 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_contains_u64_blob512: total: calls: 1 - instructions: 304790871 + instructions: 304846623 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_contains_u64_u64: total: calls: 1 - instructions: 309491909 + instructions: 309540968 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_contains_u64_vec512: total: calls: 1 - instructions: 393000497 + instructions: 393028966 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_contains_vec512_u64: total: calls: 1 - instructions: 1228107785 + instructions: 1229234276 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_get_blob512_u64: total: calls: 1 - instructions: 2461116382 + instructions: 2485080720 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_get_u64_blob512: total: calls: 1 - instructions: 320423967 + instructions: 321510059 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_get_u64_u64: total: calls: 1 - instructions: 320421253 + instructions: 320180896 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_get_u64_vec512: total: calls: 1 - instructions: 416742620 + instructions: 418668529 heap_increase: 0 stable_memory_increase: 0 scopes: {} btreemap_v2_mem_manager_get_vec512_u64: total: calls: 1 - instructions: 1268826315 + 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 4c9ef89e..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: 148723640 + instructions: 148723587 heap_increase: 1601 stable_memory_increase: 0 scopes: {} read_chunks_btreemap_1k: total: calls: 1 - instructions: 499445396 + instructions: 499369650 heap_increase: 0 stable_memory_increase: 0 scopes: {} read_chunks_btreemap_1m: total: calls: 1 - instructions: 43947440627 + 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 40debbd4..28d49770 100644 --- a/src/btreemap.rs +++ b/src/btreemap.rs @@ -498,8 +498,10 @@ 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 { - let value = value.into_bytes_checked(); + #[cfg(feature = "bench_scope")] + let _p = canbench_rs::bench_scope("insert"); // May add significant overhead. + let value = value.into_bytes_checked(); let root = if self.root_addr == NULL { // No root present. Allocate one. let node = self.allocate_node(NodeType::Leaf); @@ -653,8 +655,8 @@ where if self.root_addr == NULL { return None; } - self.traverse(self.root_addr, key, |node, idx| { - node.into_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) @@ -663,23 +665,38 @@ 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. - 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(Node, usize) -> R + Clone, + F: Fn(&mut Node, usize, &M) -> R, { - let node = self.load_node(node_addr); + let mut 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`. + 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, f), // Continue search in child. + 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. diff --git a/src/btreemap/node.rs b/src/btreemap/node.rs index d0d75233..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 into_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), diff --git a/src/btreemap/node/v2.rs b/src/btreemap/node/v2.rs index da24e1f5..4573052c 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,51 @@ impl Node { let mut entries = 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, key_size) - }; - - offset += Bytes::from(key_size); - entries.push((key, LazyValue::by_ref(Bytes::from(0_u64), 0))); + { + #[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, key_size) + }; + + offset += Bytes::from(key_size); + entries.push((key, LazyValue::by_ref(Bytes::from(0_u64), 0))); + } } // Load the values - for (_key, value) in entries.iter_mut() { - // Load the values lazily. - let value_size = read_u32(&reader, offset); - *value = LazyValue::by_ref(Bytes::from(offset.get()), value_size); - 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. + // Load the values + for (_key, value) in entries.iter_mut() { + // Load the values lazily. + let value_size = read_u32(&reader, offset); + *value = LazyValue::by_ref(Bytes::from(offset.get()), value_size); + offset += U32_SIZE + Bytes::from(value_size as u64); + } } Self { @@ -209,10 +222,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.entries.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.entries.len() { + self.entry(i, allocator.memory()); + } } // Initialize a NodeWriter. The NodeWriter takes care of allocating/deallocating @@ -250,32 +268,42 @@ impl Node { offset += Address::size(); } - // Write the keys. - for i in 0..self.entries.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.entries.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.entries.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.entries.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();