dfinity / canister-profiling

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

new metering wasm-opt O4 #84

Closed crusso closed 11 months ago

github-actions[bot] commented 11 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
hashmap 136_674 ($\textcolor{green}{-14.05\%}$) 8_608_696_480 ($\textcolor{green}{-9.35\%}$) 61_987_732 352_319 ($\textcolor{green}{-10.32\%}$) 6_688_149_059 ($\textcolor{green}{-8.40\%}$) 380_480 ($\textcolor{green}{-10.11\%}$)
triemap 137_423 ($\textcolor{green}{-15.01\%}$) 14_635_117_716 ($\textcolor{green}{-15.40\%}$) 74_216_052 287_719 ($\textcolor{green}{-16.85\%}$) 702_751 ($\textcolor{green}{-16.46\%}$) 687_522 ($\textcolor{green}{-16.67\%}$)
rbtree 137_984 ($\textcolor{green}{-14.83\%}$) 7_173_338_280 ($\textcolor{green}{-15.24\%}$) 57_995_940 100_835 ($\textcolor{green}{-36.43\%}$) 319_607 ($\textcolor{green}{-17.00\%}$) 350_056 ($\textcolor{green}{-18.09\%}$)
splay 134_108 ($\textcolor{green}{-14.79\%}$) 14_444_672_641 ($\textcolor{green}{-17.09\%}$) 53_995_876 688_885 ($\textcolor{green}{-18.10\%}$) 725_442 ($\textcolor{green}{-18.00\%}$) 998_352 ($\textcolor{green}{-19.15\%}$)
btree 177_329 ($\textcolor{green}{-17.08\%}$) 10_991_847_496 ($\textcolor{green}{-17.17\%}$) 31_103_892 367_465 ($\textcolor{green}{-20.32\%}$) 515_286 ($\textcolor{green}{-18.11\%}$) 573_932 ($\textcolor{green}{-18.78\%}$)
zhenya_hashmap 145_419 ($\textcolor{green}{-13.67\%}$) 3_378_997_121 ($\textcolor{green}{-12.83\%}$) 65_987_480 86_454 ($\textcolor{green}{-18.92\%}$) 107_552 ($\textcolor{green}{-18.08\%}$) 128_794 ($\textcolor{green}{-17.48\%}$)
btreemap_rs 446_267 1_797_752_179 13_762_560 74_544 126_136 92_839
imrc_hashmap_rs 446_166 2_571_892_333 122_454_016 38_956 179_095 115_561
hashmap_rs 439_346 447_664_894 36_536_320 22_228 27_664 25_290

Priority queue

binary_size heapify 1m max mem pop_min 50 put 50
heap 130_848 ($\textcolor{green}{-14.10\%}$) 6_220_330_310 ($\textcolor{green}{-14.74\%}$) 29_995_836 675_652 ($\textcolor{green}{-16.91\%}$) 251_392 ($\textcolor{green}{-15.52\%}$)
heap_rs 437_278 142_914_793 9_109_504 59_850 23_726

Growable array

binary_size generate 5k max mem batch_get 500 batch_put 500 batch_remove 500
buffer 138_384 ($\textcolor{green}{-14.28\%}$) 2_906_293 ($\textcolor{green}{-10.93\%}$) 65_508 116_018 ($\textcolor{green}{-7.43\%}$) 920_351 ($\textcolor{green}{-11.73\%}$) 182_018 ($\textcolor{green}{-13.46\%}$)
vector 137_157 ($\textcolor{green}{-14.69\%}$) 2_493_696 ($\textcolor{green}{-9.83\%}$) 24_764 179_705 ($\textcolor{green}{-9.03\%}$) 238_501 ($\textcolor{green}{-9.76\%}$) 230_000 ($\textcolor{green}{-13.93\%}$)
vec_rs 435_834 290_143 655_360 17_605 31_014 25_400

Statistics

SHA-2

binary_size SHA-256 SHA-512 account_id neuron_id
Motoko 171_816 ($\textcolor{green}{-12.42\%}$) 306_043_778 ($\textcolor{green}{-13.26\%}$) 290_622_723 ($\textcolor{green}{-14.29\%}$) 38_508 ($\textcolor{green}{-14.08\%}$) 27_563 ($\textcolor{green}{-13.64\%}$)
Rust 528_234 82_789_387 56_794_263 50_651 53_532

Certified map

binary_size generate 10k max mem inc witness
Motoko 172_585 ($\textcolor{green}{-15.84\%}$) 5_366_164_469 ($\textcolor{green}{-14.18\%}$) 3_429_924 636_930 ($\textcolor{green}{-14.21\%}$) 452_577 ($\textcolor{green}{-10.64\%}$)
Rust 469_955 6_359_442_714 1_081_344 1_012_174 305_119

Statistics

Basic DAO

binary_size init transfer_token submit_proposal vote_proposal
Motoko 227_168 ($\textcolor{green}{-18.10\%}$) 47_700 ($\textcolor{green}{-7.00\%}$) 22_751 ($\textcolor{green}{-10.10\%}$) 18_939 ($\textcolor{green}{-9.26\%}$) 20_074 ($\textcolor{green}{-10.39\%}$)
Rust 763_017 552_075 105_203 128_753 139_539

DIP721 NFT

binary_size init mint_token transfer_token
Motoko 186_953 ($\textcolor{green}{-18.72\%}$) 17_772 ($\textcolor{green}{-7.76\%}$) 29_817 ($\textcolor{green}{-7.68\%}$) 8_883 ($\textcolor{green}{-8.68\%}$)
Rust 828_238 146_257 380_260 93_763

Statistics

Heartbeat

binary_size heartbeat
Motoko 122_666 ($\textcolor{green}{-13.68\%}$) 23_292 ($\textcolor{red}{15.75\%}$)
Rust 25_650 549

Timer

binary_size setTimer cancelTimer
Motoko 128_683 ($\textcolor{green}{-13.78\%}$) 52_049 ($\textcolor{green}{-4.51\%}$) 4_647 ($\textcolor{green}{-6.65\%}$)
Rust 470_693 69_727 11_405

Statistics

Garbage Collection

Note Same as main branch, skipping.

Actor class

binary size put new bucket put existing bucket get
Map 259_478 ($\textcolor{green}{-12.85\%}$) 711_028 ($\textcolor{green}{-9.26\%}$) 16_268 ($\textcolor{green}{-4.56\%}$) 16_784 ($\textcolor{green}{-4.26\%}$)

Statistics

Publisher & Subscriber

pub_binary_size sub_binary_size subscribe_caller subscribe_callee publish_caller publish_callee
Motoko 143_511 ($\textcolor{green}{-13.95\%}$) 130_619 ($\textcolor{green}{-14.01\%}$) 28_763 ($\textcolor{green}{-3.98\%}$) 11_964 ($\textcolor{green}{-4.71\%}$) 23_039 ($\textcolor{green}{-4.24\%}$) 6_432 ($\textcolor{green}{-6.40\%}$)
Rust 511_870 565_407 71_728 44_318 95_767 53_941

Statistics

github-actions[bot] commented 11 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.

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 large collections. Hopefully, when deterministic time slicing is ready, we can measure the performance on larger memory footprint.
  • 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
hashmap 136_674 8_608_696_480 61_987_732 352_319 6_688_149_059 380_480
triemap 137_423 14_635_117_716 74_216_052 287_719 702_751 687_522
rbtree 137_984 7_173_338_280 57_995_940 100_835 319_607 350_056
splay 134_108 14_444_672_641 53_995_876 688_885 725_442 998_352
btree 177_329 10_991_847_496 31_103_892 367_465 515_286 573_932
zhenya_hashmap 145_419 3_378_997_121 65_987_480 86_454 107_552 128_794
btreemap_rs 446_267 1_797_752_179 13_762_560 74_544 126_136 92_839
imrc_hashmap_rs 446_166 2_571_892_333 122_454_016 38_956 179_095 115_561
hashmap_rs 439_346 447_664_894 36_536_320 22_228 27_664 25_290

Priority queue

binary_size heapify 1m max mem pop_min 50 put 50
heap 130_848 6_220_330_310 29_995_836 675_652 251_392 643_610
heap_rs 437_278 142_914_793 9_109_504 59_850 23_726 60_072

Growable array

binary_size generate 5k max mem batch_get 500 batch_put 500 batch_remove 500
buffer 138_384 2_906_293 65_508 116_018 920_351 182_018
vector 137_157 2_493_696 24_764 179_705 238_501 230_000
vec_rs 435_834 290_143 655_360 17_605 31_014 25_400

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 171_816 306_043_778 290_622_723 38_508 27_563
Rust 528_234 82_789_387 56_794_263 50_651 53_532

Certified map

binary_size generate 10k max mem inc witness
Motoko 172_585 5_366_164_469 3_429_924 636_930 452_577
Rust 469_955 6_359_442_714 1_081_344 1_012_174 305_119

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
Motoko 227_168 47_700 22_751 18_939 20_074
Rust 763_017 552_075 105_203 128_753 139_539

DIP721 NFT

binary_size init mint_token transfer_token
Motoko 186_953 17_772 29_817 8_883
Rust 828_238 146_257 380_260 93_763

Heartbeat / Timer

Measure the cost of empty heartbeat and timer job.

Heartbeat

binary_size heartbeat
Motoko 122_666 23_292
Rust 25_650 549

Timer

binary_size setTimer cancelTimer
Motoko 128_683 52_049 4_647
Rust 470_693 69_727 11_405

Motoko Specific Benchmarks

Measure various features only available in Motoko.

Garbage Collection

generate 800k max mem batch_get 50 batch_put 50 batch_remove 50
default 1_338_231_405 59_396_776 118 118 118
copying 1_338_231_287 59_396_776 1_337_913_569 1_338_002_371 1_337_919_144
compacting 1_911_420_608 59_396_776 1_473_824_186 1_756_485_066 1_787_369_954
generational 2_891_818_643 59_405_240 1_141_865_993 1_217_376 1_117_840
incremental 33_436_719 1_136_155_048 333_734_166 336_829_512 336_860_690

Actor class

binary size put new bucket put existing bucket get
Map 259_478 711_028 16_268 16_784

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 143_511 130_619 28_763 11_964 23_039 6_432
Rust 511_870 565_407 71_728 44_318 95_767 53_941