dfinity / canister-profiling

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

Moc inline with new meter alloc #85

Closed crusso closed 11 months ago

crusso commented 11 months ago

base: new meter; no wasm-opt; selective inlining including allocation cf. #80

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 171_958 ($\textcolor{red}{8.14\%}$) 9_161_393_058 ($\textcolor{green}{-3.53\%}$) 61_987_732 381_086 ($\textcolor{green}{-3.00\%}$) 7_234_859_066 ($\textcolor{green}{-0.91\%}$) 408_538 ($\textcolor{green}{-3.48\%}$)
triemap 177_729 ($\textcolor{red}{9.92\%}$) 15_789_996_466 ($\textcolor{green}{-8.73\%}$) 74_216_052 307_168 ($\textcolor{green}{-11.23\%}$) 760_538 ($\textcolor{green}{-9.59\%}$) 746_976 ($\textcolor{green}{-9.46\%}$)
rbtree 180_851 ($\textcolor{red}{11.63\%}$) 7_554_129_903 ($\textcolor{green}{-10.74\%}$) 57_995_940 137_297 ($\textcolor{green}{-13.45\%}$) 337_114 ($\textcolor{green}{-12.45\%}$) 372_722 ($\textcolor{green}{-12.79\%}$)
splay 172_261 ($\textcolor{red}{9.45\%}$) 14_726_306_490 ($\textcolor{green}{-15.48\%}$) 53_995_876 702_455 ($\textcolor{green}{-16.49\%}$) 737_680 ($\textcolor{green}{-16.62\%}$) 1_034_297 ($\textcolor{green}{-16.24\%}$)
btree 254_044 ($\textcolor{red}{18.79\%}$) 11_474_733_247 ($\textcolor{green}{-13.53\%}$) 31_103_892 398_713 ($\textcolor{green}{-13.55\%}$) 540_188 ($\textcolor{green}{-14.16\%}$) 605_703 ($\textcolor{green}{-14.28\%}$)
zhenya_hashmap 189_062 ($\textcolor{red}{12.25\%}$) 3_502_145_539 ($\textcolor{green}{-9.65\%}$) 65_987_480 92_586 ($\textcolor{green}{-13.17\%}$) 110_925 ($\textcolor{green}{-15.51\%}$) 129_031 ($\textcolor{green}{-17.33\%}$)
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 161_848 ($\textcolor{red}{6.25\%}$) 6_404_054_262 ($\textcolor{green}{-12.23\%}$) 29_995_836 703_629 ($\textcolor{green}{-13.47\%}$) 258_830 ($\textcolor{green}{-13.02\%}$)
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 175_392 ($\textcolor{red}{8.65\%}$) 2_839_042 ($\textcolor{green}{-12.99\%}$) 65_508 108_785 ($\textcolor{green}{-13.20\%}$) 896_573 ($\textcolor{green}{-14.01\%}$) 186_785 ($\textcolor{green}{-11.19\%}$)
vector 177_651 ($\textcolor{red}{10.50\%}$) 2_430_418 ($\textcolor{green}{-12.12\%}$) 24_764 170_967 ($\textcolor{green}{-13.45\%}$) 232_802 ($\textcolor{green}{-11.92\%}$) 231_608 ($\textcolor{green}{-13.33\%}$)
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 235_173 ($\textcolor{red}{19.88\%}$) 326_935_296 ($\textcolor{green}{-7.34\%}$) 294_476_504 ($\textcolor{green}{-13.15\%}$) 41_239 ($\textcolor{green}{-7.98\%}$) 29_492 ($\textcolor{green}{-7.60\%}$)
Rust 528_234 82_789_387 56_794_263 50_651 53_532

Certified map

binary_size generate 10k max mem inc witness
Motoko 243_154 ($\textcolor{red}{18.57\%}$) 5_753_778_755 ($\textcolor{green}{-7.98\%}$) 3_429_924 683_053 ($\textcolor{green}{-8.00\%}$) 445_158 ($\textcolor{green}{-12.10\%}$)
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 311_829 ($\textcolor{red}{12.42\%}$) 49_955 ($\textcolor{green}{-2.69\%}$) 24_257 ($\textcolor{green}{-4.13\%}$) 20_114 ($\textcolor{green}{-3.62\%}$) 21_530 ($\textcolor{green}{-4.08\%}$)
Rust 763_017 552_075 105_203 128_753 139_539

DIP721 NFT

binary_size init mint_token transfer_token
Motoko 250_746 ($\textcolor{red}{9.01\%}$) 19_068 ($\textcolor{green}{-1.03\%}$) 31_752 ($\textcolor{green}{-1.69\%}$) 9_523 ($\textcolor{green}{-2.10\%}$)
Rust 828_238 146_257 380_260 93_763

Statistics

Heartbeat

binary_size heartbeat
Motoko 147_880 ($\textcolor{red}{4.06\%}$) 23_906 ($\textcolor{green}{-0.68\%}$)
Rust 25_650 1_179 ($\textcolor{red}{114.75\%}$)

Timer

binary_size setTimer cancelTimer
Motoko 157_829 ($\textcolor{red}{5.75\%}$) 53_655 ($\textcolor{green}{-1.56\%}$) 4_918 ($\textcolor{green}{-1.21\%}$)
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 323_539 ($\textcolor{red}{8.67\%}$) 853_878 ($\textcolor{red}{8.97\%}$) 16_824 ($\textcolor{green}{-1.30\%}$) 17_316 ($\textcolor{green}{-1.23\%}$)

Statistics

Publisher & Subscriber

pub_binary_size sub_binary_size subscribe_caller subscribe_callee publish_caller publish_callee
Motoko 175_981 ($\textcolor{red}{5.52\%}$) 158_295 ($\textcolor{red}{4.22\%}$) 29_754 ($\textcolor{green}{-0.67\%}$) 12_468 ($\textcolor{green}{-0.70\%}$) 23_775 ($\textcolor{green}{-1.18\%}$) 6_804 ($\textcolor{green}{-0.99\%}$)
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 171_958 9_161_393_058 61_987_732 381_086 7_234_859_066 408_538
triemap 177_729 15_789_996_466 74_216_052 307_168 760_538 746_976
rbtree 180_851 7_554_129_903 57_995_940 137_297 337_114 372_722
splay 172_261 14_726_306_490 53_995_876 702_455 737_680 1_034_297
btree 254_044 11_474_733_247 31_103_892 398_713 540_188 605_703
zhenya_hashmap 189_062 3_502_145_539 65_987_480 92_586 110_925 129_031
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 161_848 6_404_054_262 29_995_836 703_629 258_830 670_526
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 175_392 2_839_042 65_508 108_785 896_573 186_785
vector 177_651 2_430_418 24_764 170_967 232_802 231_608
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 235_173 326_935_296 294_476_504 41_239 29_492
Rust 528_234 82_789_387 56_794_263 50_651 53_532

Certified map

binary_size generate 10k max mem inc witness
Motoko 243_154 5_753_778_755 3_429_924 683_053 445_158
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 311_829 49_955 24_257 20_114 21_530
Rust 763_017 552_075 105_203 128_753 139_539

DIP721 NFT

binary_size init mint_token transfer_token
Motoko 250_746 19_068 31_752 9_523
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 147_880 23_906
Rust 25_650 1_179

Timer

binary_size setTimer cancelTimer
Motoko 157_829 53_655 4_918
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 323_539 853_878 16_824 17_316

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 175_981 158_295 29_754 12_468 23_775 6_804
Rust 511_870 565_407 71_728 44_318 95_767 53_941