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 189_929 8_184_618_025 56_000_256 342_784 6_462_528_122 368_420 10_728_193_099
triemap 195_472 13_661_315_924 68_228_576 252_649 657_794 648_084 15_499_470_884
rbtree 185_907 7_009_043_570 52_000_464 116_348 318_320 330_226 6_870_900_152
splay 190_457 13_157_617_583 48_000_400 631_329 662_998 928_144 4_308_925_798
btree 230_321 10_223_929_607 25_108_416 357_912 485_794 539_490 2_861_974_825
zhenya_hashmap 188_894 2_360_638_679 16_777_504 58_204 66_552 79_675 3_018_208_083
btreemap_rs 555_925 1_792_610_876 27_590_656 73_295 123_191 85_043 3_204_151_479
imrc_hashmap_rs 556_123 2_584_010_729 244_908_032 35_545 194_927 93_154 6_272_274_871
hashmap_rs 544_570 439_245_801 73_138_176 20_008 24_930 23_243 1_565_611_027

Priority queue

  binary_size heapify 1m max mem pop_min 50 put 50 pop_min 50 upgrade
heap 166_903 5_554_617_018 24_000_360 621_690 227_224 592_588 3_189_831_485
heap_rs 540_668 139_667_629 18_284_544 55_880 21_271 55_765 648_921_342

Growable array

  binary_size generate 5k max mem batch_get 500 batch_put 500 batch_remove 500 upgrade
buffer 173_903 2_601_059 65_644 95_506 803_474 173_506 3_091_310
vector 171_932 1_952_689 24_580 126_130 186_485 176_123 4_675_192
vec_rs 538_516 286_776 1_376_256 15_714 28_793 21_553 3_805_750

Stable structures

  binary_size generate 50k max mem batch_get 50 batch_put 50 batch_remove 50 upgrade
btreemap_rs 555_925 76_161_521 2_555_904 62_853 95_118 84_048 139_592_121
btreemap_stable_rs 558_089 4_564_070_850 2_031_616 2_709_647 5_031_627 8_581_114 729_344
heap_rs 540_668 7_049_481 2_293_760 48_389 21_519 48_114 33_629_765
heap_stable_rs 521_160 277_865_060 458_752 2_405_453 242_829 2_387_316 729_349
vec_rs 538_516 3_077_152 2_293_760 15_714 16_643 15_941 31_301_345
vec_stable_rs 521_344 63_342_333 458_752 64_876 78_806 84_168 729_349

Environment