canister-profiling

Collection libraries

Measure different collection libraries written in both Motoko and Rust. The library names with _rs suffix are written in Rust; the rest are written in Motoko. The _stable and _stable_rs suffix represents that the library directly writes the state to stable memory using Region in Motoko and ic-stable-stuctures in Rust.

We use the same random number generator with fixed seed to ensure that all collections contain the same elements, and the queries are exactly the same. Below we explain the measurements of each column in the table:

💎 Takeaways

Note

Map

  binary_size generate 1m max mem batch_get 50 batch_put 50 batch_remove 50 upgrade
hashmap 194_129 8_193_819_060 56_000_256 342_788 6_469_781_020 368_431 10_766_389_949
triemap 199_671 13_670_187_584 68_228_576 252_704 657_887 648_184 15_537_338_607
orderedmap 198_472 5_918_271_186 36_000_524 120_106 287_536 326_469 4_583_353_795
rbtree 190_190 6_993_676_959 52_000_464 116_417 317_299 330_296 6_988_883_792
splay 194_749 13_052_525_320 48_000_400 625_852 657_023 920_272 4_321_904_232
btree 234_430 10_220_059_976 25_108_416 357_581 485_463 539_509 2_906_462_612
zhenya_hashmap 192_961 2_361_649_032 16_777_504 58_299 66_594 79_776 3_084_236_540
btreemap_rs 611_851 1_809_789_841 27_590_656 74_098 124_626 85_214 3_208_130_200
imrc_hashmap_rs 613_202 2_634_915_707 244_908_032 35_894 198_252 96_520 6_383_840_797
hashmap_rs 601_477 438_103_157 73_138_176 20_788 25_678 23_645 1_545_701_419

Priority queue

  binary_size heapify 1m max mem pop_min 50 put 50 pop_min 50 upgrade
heap 171_060 5_557_564_409 24_000_360 621_758 227_293 592_698 3_240_817_647
heap_rs 596_953 143_262_451 18_284_544 58_563 21_622 58_466 647_923_463

Growable array

  binary_size generate 5k max mem batch_get 500 batch_put 500 batch_remove 500 upgrade
buffer 178_117 2_601_290 65_652 95_575 803_545 173_575 3_146_728
vector 175_919 1_952_750 24_588 126_199 186_554 176_192 4_780_320
vec_rs 588_969 287_516 1_376_256 16_494 30_089 22_346 3_806_788

Stable structures

  binary_size generate 50k max mem batch_get 50 batch_put 50 batch_remove 50 upgrade
btreemap_rs 611_851 77_021_026 2_555_904 63_656 96_504 84_265 139_792_280
btreemap_stable_rs 616_876 4_773_834_814 2_031_616 2_893_685 5_266_123 8_870_300 729_405
heap_rs 596_953 7_230_201 2_293_760 50_652 21_870 50_383 33_581_842
heap_stable_rs 576_040 283_742_492 458_752 2_526_262 246_537 2_506_863 729_375
vec_rs 588_969 3_077_883 2_293_760 16_494 17_489 16_734 31_302_411
vec_stable_rs 572_835 63_993_021 458_752 66_549 80_266 85_639 729_377

Environment