dfinity / canister-profiling

Collection of canister performance benchmarks
Apache License 2.0
21 stars 8 forks source link

experiment: perf run with tagging disabled #110

Open crusso opened 6 months ago

crusso commented 6 months ago

Using code from https://github.com/dfinity/motoko/pull/4400 which incorporates but disables tagging, wideing scalars to their original width.

To see ramifications of checking the tagging feature in, but gated off, until future use.

github-actions[bot] commented 6 months ago

Note Diffing the performance result against the published result from main branch. Unchanged benchmarks are omitted.

Map

binary_size generate 1m max mem batch_get 50 batch_put 50 batch_remove 50 upgrade
hashmap 189_916 ($\textcolor{red}{0.16\%}$) 8_184_618_025 ($\textcolor{green}{-2.22\%}$) 56_000_256 ($\textcolor{green}{-9.66\%}$) 342_784 ($\textcolor{green}{-0.62\%}$) 6_462_528_122 ($\textcolor{green}{-1.98\%}$) 368_420 ($\textcolor{green}{-0.76\%}$) 10_728_193_099 ($\textcolor{green}{-2.71\%}$)
triemap 195_458 ($\textcolor{green}{-0.03\%}$) 13_661_315_924 ($\textcolor{green}{-1.40\%}$) 68_228_576 ($\textcolor{green}{-8.07\%}$) 252_649 ($\textcolor{green}{-0.76\%}$) 657_794 ($\textcolor{green}{-0.56\%}$) 648_084 ($\textcolor{green}{-0.42\%}$) 15_499_470_884 ($\textcolor{green}{-2.01\%}$)
rbtree 185_901 ($\textcolor{green}{-0.35\%}$) 7_009_043_570 ($\textcolor{green}{-1.66\%}$) 52_000_464 ($\textcolor{green}{-10.34\%}$) 116_348 ($\textcolor{red}{1.79\%}$) 318_320 ($\textcolor{green}{-0.01\%}$) 330_226 ($\textcolor{red}{0.59\%}$) 6_870_900_152 ($\textcolor{green}{-4.16\%}$)
splay 190_447 ($\textcolor{green}{-0.04\%}$) 13_157_617_583 ($\textcolor{green}{-0.68\%}$) 48_000_400 ($\textcolor{green}{-11.10\%}$) 631_329 ($\textcolor{red}{0.42\%}$) 662_998 ($\textcolor{red}{0.21\%}$) 928_144 ($\textcolor{red}{0.67\%}$) 4_308_925_798 ($\textcolor{green}{-5.67\%}$)
btree 230_305 ($\textcolor{red}{0.19\%}$) 10_223_929_607 ($\textcolor{green}{-0.41\%}$) 25_108_416 ($\textcolor{green}{-19.28\%}$) 357_912 ($\textcolor{red}{1.21\%}$) 485_794 ($\textcolor{red}{0.76\%}$) 539_490 ($\textcolor{red}{1.04\%}$) 2_861_974_825 ($\textcolor{green}{-8.68\%}$)
zhenya_hashmap 188_888 ($\textcolor{green}{-0.21\%}$) 2_360_638_679 ($\textcolor{green}{-8.17\%}$) 16_777_504 ($\textcolor{green}{-26.33\%}$) 58_204 ($\textcolor{green}{-3.31\%}$) 66_552 ($\textcolor{green}{-5.11\%}$) 79_675 ($\textcolor{green}{-3.37\%}$) 3_018_208_083 ($\textcolor{green}{-8.69\%}$)
btreemap_rs 537_393 1_793_333_047 27_590_656 75_328 125_166 86_260 2_937_041_107
imrc_hashmap_rs 542_882 2_584_501_850 244_973_568 37_762 178_926 115_385 5_796_587_958
hashmap_rs 529_458 439_248_112 73_138_176 21_501 26_711 25_024 1_298_646_667

Priority queue

binary_size heapify 1m max mem pop_min 50 put 50 pop_min 50.1 upgrade
heap 166_898 ($\textcolor{green}{-0.36\%}$) 5_554_617_018 ($\textcolor{green}{-2.51\%}$) 24_000_360 ($\textcolor{green}{-19.99\%}$) 621_690 ($\textcolor{red}{0.06\%}$) 227_224 ($\textcolor{green}{-0.63\%}$) 592_588 ($\textcolor{red}{0.07\%}$) 3_189_831_485 ($\textcolor{green}{-3.62\%}$)
heap_rs 525_853 139_669_830 18_284_544 57_419 23_051 57_545 510_960_192

Growable array

binary_size generate 5k max mem batch_get 500 batch_put 500 batch_remove 500 upgrade
buffer 173_895 ($\textcolor{green}{-0.01\%}$) 2_601_059 ($\textcolor{red}{1.17\%}$) 65_644 95_506 ($\textcolor{red}{0.02\%}$) 803_474 ($\textcolor{red}{0.38\%}$) 173_506 ($\textcolor{red}{1.77\%}$) 3_091_310 ($\textcolor{red}{0.98\%}$)
vector 171_927 ($\textcolor{green}{-0.19\%}$) 1_952_689 ($\textcolor{red}{1.65\%}$) 24_580 126_130 ($\textcolor{red}{0.01\%}$) 186_485 ($\textcolor{red}{1.69\%}$) 176_123 ($\textcolor{red}{0.08\%}$) 4_675_192 ($\textcolor{green}{-0.43\%}$)
vec_rs 520_881 289_040 1_376_256 17_251 30_571 23_331 3_161_017

Stable structures

Note Same as main branch, skipping.

Statistics

SHA-2

binary_size SHA-256 SHA-512 account_id neuron_id
Motoko 193_678 ($\textcolor{green}{-1.43\%}$) 267_743_355 ($\textcolor{green}{-1.94\%}$) 247_834_501 ($\textcolor{green}{-4.62\%}$) 33_636 ($\textcolor{green}{-2.14\%}$) 24_532 ($\textcolor{green}{-1.47\%}$)
Rust 537_397 82_787_911 56_792_991 47_914 50_388

Certified map

binary_size generate 10k max mem inc witness upgrade
Motoko 243_625 ($\textcolor{green}{-0.64\%}$) 4_666_119_661 ($\textcolor{green}{-2.04\%}$) 3_430_044 553_629 ($\textcolor{green}{-2.03\%}$) 407_936 ($\textcolor{red}{1.46\%}$) 274_434_719 ($\textcolor{red}{0.06\%}$)
Rust 565_792 6_409_147_805 2_228_224 1_019_959 303_897 6_019_483_730

Statistics

Basic DAO

binary_size init transfer_token submit_proposal vote_proposal upgrade
Motoko 273_924 ($\textcolor{green}{-0.56\%}$) 510_825 ($\textcolor{red}{0.03\%}$) 22_316 ($\textcolor{red}{0.24\%}$) 18_599 ($\textcolor{green}{-0.07\%}$) 19_665 ($\textcolor{red}{0.15\%}$) 157_946 ($\textcolor{red}{0.22\%}$)
Rust 849_921 599_916 ($\textcolor{green}{-0.01\%}$) 99_156 123_702 136_655 1_799_828 ($\textcolor{green}{-0.00\%}$)

DIP721 NFT

binary_size init mint_token transfer_token upgrade
Motoko 220_392 ($\textcolor{green}{-1.00\%}$) 481_158 30_204 ($\textcolor{red}{1.32\%}$) 8_764 ($\textcolor{green}{-0.14\%}$) 89_833 ($\textcolor{red}{0.42\%}$)
Rust 869_104 236_542 368_044 91_941 1_999_207 ($\textcolor{green}{-0.00\%}$)

Statistics

Heartbeat

binary_size heartbeat
Motoko 137_178 ($\textcolor{green}{-0.52\%}$) 19_507 ($\textcolor{green}{-0.02\%}$)
Rust 23_637 1_112

Timer

binary_size setTimer cancelTimer
Motoko 145_613 ($\textcolor{green}{-0.46\%}$) 51_778 ($\textcolor{red}{0.24\%}$) 4_626 ($\textcolor{red}{0.35\%}$)
Rust 487_585 68_173 11_184

Statistics

Garbage Collection

generate 700k max mem batch_get 50 batch_put 50 batch_remove 50
default 1_068_192_695 ($\textcolor{green}{-8.81\%}$) 47_793_792 ($\textcolor{green}{-8.07\%}$) 119 119 119
copying 1_068_192_577 ($\textcolor{green}{-8.81\%}$) 47_793_792 ($\textcolor{green}{-8.07\%}$) 1_067_924_316 ($\textcolor{green}{-8.81\%}$) 1_068_004_203 ($\textcolor{green}{-8.81\%}$) 1_067_925_853 ($\textcolor{green}{-8.81\%}$)
compacting 1_545_586_176 ($\textcolor{green}{-7.57\%}$) 47_793_792 ($\textcolor{green}{-8.07\%}$) 1_192_139_528 ($\textcolor{green}{-7.59\%}$) 1_415_425_189 ($\textcolor{green}{-7.69\%}$) 1_439_317_325 ($\textcolor{green}{-8.00\%}$)
generational 2_304_140_531 ($\textcolor{green}{-8.89\%}$) 47_802_256 ($\textcolor{green}{-8.07\%}$) 882_208_645 ($\textcolor{green}{-11.74\%}$) 1_211_144 ($\textcolor{green}{-1.75\%}$) 1_103_549 ($\textcolor{green}{-0.03\%}$)
incremental 29_503_170 976_097_188 ($\textcolor{green}{-0.99\%}$) 471_911_803 ($\textcolor{green}{-1.27\%}$) 497_465_467 ($\textcolor{red}{0.78\%}$) 1_221_308_722 ($\textcolor{red}{11.81\%}$)

Actor class

binary size put new bucket put existing bucket get
Map 299_202 ($\textcolor{green}{-0.33\%}$) 813_521 ($\textcolor{green}{-0.31\%}$) 16_115 ($\textcolor{red}{0.10\%}$) 16_660 ($\textcolor{red}{0.10\%}$)

Statistics

Publisher & Subscriber

pub_binary_size sub_binary_size subscribe_caller subscribe_callee publish_caller publish_callee
Motoko 161_274 ($\textcolor{green}{-0.41\%}$) 145_736 ($\textcolor{green}{-0.33\%}$) 28_593 11_963 22_854 ($\textcolor{green}{-0.04\%}$) 6_446 ($\textcolor{red}{0.25\%}$)
Rust 519_866 570_028 68_903 42_634 92_131 51_818

Statistics

github-actions[bot] commented 6 months ago

Note The flamegraph link only works after you merge. Unchanged benchmarks are omitted.

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

  • The Candid interface of the benchmark is minimal, therefore the serialization cost is negligible in this measurement.
  • Due to the instrumentation overhead and cycle limit, we cannot profile computations with very large collections.
  • The upgrade column uses Candid for serializing stable data. In Rust, you may get better cycle cost by using a different serialization format. Another slowdown in Rust is that ic-stable-structures tends to be slower than the region memory in Motoko.
  • Different library has different ways for persisting data during upgrades, there are mainly three categories:
    • Use stable variable directly in Motoko: zhenya_hashmap, btree, vector
    • Expose and serialize external state (share/unshare in Motoko, candid::Encode in Rust): rbtree, heap, btreemap_rs, hashmap_rs, heap_rs, vector_rs
    • Use pre/post-upgrade hooks to convert data into an array: hashmap, splay, triemap, buffer, imrc_hashmap_rs
  • The stable benchmarks are much more expensive than their non-stable counterpart, because the stable memory API is much more expensive. The benefit is that they get fast upgrade. The upgrade still needs to parse the metadata when initializing the upgraded Wasm module.
  • hashmap uses amortized data structure. When the initial capacity is reached, it has to copy the whole array, thus the cost of batch_put 50 is much higher than other data structures.
  • btree comes from mops.one/stableheapbtreemap.
  • zhenya_hashmap comes from mops.one/map.
  • vector comes from mops.one/vector. Compare with buffer, put has better worst case time and space complexity ($O(\sqrt{n})$ vs $O(n)$); get has a slightly larger constant overhead.
  • hashmap_rs uses the fxhash crate, which is the same as std::collections::HashMap, but with a deterministic hasher. This ensures reproducible result.
  • imrc_hashmap_rs uses the im-rc crate, which is the immutable version hashmap in Rust.

Map

binary_size generate 1m max mem batch_get 50 batch_put 50 batch_remove 50 upgrade
hashmap 189_916 8_184_618_025 56_000_256 342_784 6_462_528_122 368_420 10_728_193_099
triemap 195_458 13_661_315_924 68_228_576 252_649 657_794 648_084 15_499_470_884
rbtree 185_901 7_009_043_570 52_000_464 116_348 318_320 330_226 6_870_900_152
splay 190_447 13_157_617_583 48_000_400 631_329 662_998 928_144 4_308_925_798
btree 230_305 10_223_929_607 25_108_416 357_912 485_794 539_490 2_861_974_825
zhenya_hashmap 188_888 2_360_638_679 16_777_504 58_204 66_552 79_675 3_018_208_083
btreemap_rs 537_393 1_793_333_047 27_590_656 75_328 125_166 86_260 2_937_041_107
imrc_hashmap_rs 542_882 2_584_501_850 244_973_568 37_762 178_926 115_385 5_796_587_958
hashmap_rs 529_458 439_248_112 73_138_176 21_501 26_711 25_024 1_298_646_667

Priority queue

binary_size heapify 1m max mem pop_min 50 put 50 pop_min 50 upgrade
heap 166_898 5_554_617_018 24_000_360 621_690 227_224 592_588 3_189_831_485
heap_rs 525_853 139_669_830 18_284_544 57_419 23_051 57_545 510_960_192

Growable array

binary_size generate 5k max mem batch_get 500 batch_put 500 batch_remove 500 upgrade
buffer 173_895 2_601_059 65_644 95_506 803_474 173_506 3_091_310
vector 171_927 1_952_689 24_580 126_130 186_485 176_123 4_675_192
vec_rs 520_881 289_040 1_376_256 17_251 30_571 23_331 3_161_017

Stable structures

binary_size generate 50k max mem batch_get 50 batch_put 50 batch_remove 50 upgrade
btreemap_rs 537_393 76_200_333 2_555_904 64_886 97_044 85_272 126_265_270
btreemap_stable_rs 543_609 4_561_985_735 2_031_616 2_707_064 5_026_642 8_594_683 729_311
heap_rs 525_853 7_051_730 2_293_760 49_928 23_299 49_894 26_768_703
heap_stable_rs 506_559 271_553_517 458_752 2_294_851 238_596 2_277_771 729_317
vec_rs 520_881 3_079_382 2_293_760 17_251 18_421 17_719 24_671_551
vec_stable_rs 503_829 63_394_912 458_752 62_491 79_685 81_633 729_320

Environment

  • dfx 0.16.1
  • Motoko compiler 0.10.4 (source kfk8w3jy-5b63clja-3y6iac6j-vqw16jlw)
  • rustc 1.75.0 (82e1608df 2023-12-21)
  • ic-repl 0.6.2
  • ic-wasm 0.7.0

    Cryptographic libraries

Measure different cryptographic libraries written in both Motoko and Rust.

SHA-2

binary_size SHA-256 SHA-512 account_id neuron_id
Motoko 193_678 267_743_355 247_834_501 33_636 24_532
Rust 537_397 82_787_911 56_792_991 47_914 50_388

Certified map

binary_size generate 10k max mem inc witness upgrade
Motoko 243_625 4_666_119_661 3_430_044 553_629 407_936 274_434_719
Rust 565_792 6_409_147_805 2_228_224 1_019_959 303_897 6_019_483_730

Environment

  • dfx 0.16.1
  • Motoko compiler 0.10.4 (source kfk8w3jy-5b63clja-3y6iac6j-vqw16jlw)
  • rustc 1.75.0 (82e1608df 2023-12-21)
  • ic-repl 0.6.2
  • ic-wasm 0.7.0

    Sample Dapps

Measure the performance of some typical dapps:

Note

  • The cost difference is mainly due to the Candid serialization cost.
  • Motoko statically compiles/specializes the serialization code for each method, whereas in Rust, we use serde to dynamically deserialize data based on data on the wire.
  • We could improve the performance on the Rust side by using parser combinators. But it is a challenge to maintain the ergonomics provided by serde.
  • For real-world applications, we tend to send small data for each endpoint, which makes the Candid overhead in Rust tolerable.

Basic DAO

binary_size init transfer_token submit_proposal vote_proposal upgrade
Motoko 273_924 510_825 22_316 18_599 19_665 157_946
Rust 849_921 599_916 99_156 123_702 136_655 1_799_828

DIP721 NFT

binary_size init mint_token transfer_token upgrade
Motoko 220_392 481_158 30_204 8_764 89_833
Rust 869_104 236_542 368_044 91_941 1_999_207

Environment

  • dfx 0.16.1
  • Motoko compiler 0.10.4 (source kfk8w3jy-5b63clja-3y6iac6j-vqw16jlw)
  • rustc 1.75.0 (82e1608df 2023-12-21)
  • ic-repl 0.6.2
  • ic-wasm 0.7.0

    Heartbeat / Timer

Measure the cost of empty heartbeat and timer job.

Heartbeat

binary_size heartbeat
Motoko 137_178 19_507
Rust 23_637 1_112

Timer

binary_size setTimer cancelTimer
Motoko 145_613 51_778 4_626
Rust 487_585 68_173 11_184

Environment

  • dfx 0.16.1
  • Motoko compiler 0.10.4 (source kfk8w3jy-5b63clja-3y6iac6j-vqw16jlw)
  • rustc 1.75.0 (82e1608df 2023-12-21)
  • ic-repl 0.6.2
  • ic-wasm 0.7.0

    Motoko Specific Benchmarks

Measure various features only available in Motoko.

Garbage Collection

generate 700k max mem batch_get 50 batch_put 50 batch_remove 50
default 1_068_192_695 47_793_792 119 119 119
copying 1_068_192_577 47_793_792 1_067_924_316 1_068_004_203 1_067_925_853
compacting 1_545_586_176 47_793_792 1_192_139_528 1_415_425_189 1_439_317_325
generational 2_304_140_531 47_802_256 882_208_645 1_211_144 1_103_549
incremental 29_503_170 976_097_188 471_911_803 497_465_467 1_221_308_722

Actor class

binary size put new bucket put existing bucket get
Map 299_202 813_521 16_115 16_660

Environment

  • dfx 0.16.1
  • Motoko compiler 0.10.4 (source kfk8w3jy-5b63clja-3y6iac6j-vqw16jlw)
  • rustc 1.75.0 (82e1608df 2023-12-21)
  • ic-repl 0.6.2
  • ic-wasm 0.7.0

    Publisher & Subscriber

Measure the cost of inter-canister calls from the Publisher & Subscriber example.

pub_binary_size sub_binary_size subscribe_caller subscribe_callee publish_caller publish_callee
Motoko 161_274 145_736 28_593 11_963 22_854 6_446
Rust 519_866 570_028 68_903 42_634 92_131 51_818

Environment

  • dfx 0.16.1
  • Motoko compiler 0.10.4 (source kfk8w3jy-5b63clja-3y6iac6j-vqw16jlw)
  • rustc 1.75.0 (82e1608df 2023-12-21)
  • ic-repl 0.6.2
  • ic-wasm 0.7.0