dfinity / canister-profiling

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

Moc inline with new meter #80

Closed chenyan-dfinity closed 1 year ago

chenyan-dfinity commented 1 year ago

base: new metering, without wasm-opt

github-actions[bot] commented 1 year 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 167_316 ($\textcolor{red}{5.22\%}$) 9_230_374_182 ($\textcolor{green}{-2.81\%}$) 61_987_732 382_826 ($\textcolor{green}{-2.55\%}$) 7_246_862_420 ($\textcolor{green}{-0.75\%}$) 411_340 ($\textcolor{green}{-2.82\%}$)
triemap 171_390 ($\textcolor{red}{6.00\%}$) 16_198_090_366 ($\textcolor{green}{-6.37\%}$) 74_216_052 309_052 ($\textcolor{green}{-10.69\%}$) 782_396 ($\textcolor{green}{-6.99\%}$) 769_026 ($\textcolor{green}{-6.79\%}$)
rbtree 171_502 ($\textcolor{red}{5.86\%}$) 7_930_546_839 ($\textcolor{green}{-6.29\%}$) 57_995_940 137_477 ($\textcolor{green}{-13.33\%}$) 357_040 ($\textcolor{green}{-7.28\%}$) 401_036 ($\textcolor{green}{-6.16\%}$)
splay 166_269 ($\textcolor{red}{5.64\%}$) 15_696_985_410 ($\textcolor{green}{-9.90\%}$) 53_995_876 752_855 ($\textcolor{green}{-10.50\%}$) 790_594 ($\textcolor{green}{-10.64\%}$) 1_106_735 ($\textcolor{green}{-10.37\%}$)
btree 243_933 ($\textcolor{red}{14.06\%}$) 11_541_962_095 ($\textcolor{green}{-13.02\%}$) 31_103_892 400_549 ($\textcolor{green}{-13.15\%}$) 543_692 ($\textcolor{green}{-13.60\%}$) 612_045 ($\textcolor{green}{-13.38\%}$)
zhenya_hashmap 184_431 ($\textcolor{red}{9.50\%}$) 3_538_128_781 ($\textcolor{green}{-8.72\%}$) 65_987_480 93_396 ($\textcolor{green}{-12.41\%}$) 112_641 ($\textcolor{green}{-14.20\%}$) 129_949 ($\textcolor{green}{-16.74\%}$)
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 158_536 ($\textcolor{red}{4.08\%}$) 6_553_514_370 ($\textcolor{green}{-10.18\%}$) 29_995_836 720_429 ($\textcolor{green}{-11.41\%}$) 265_478 ($\textcolor{green}{-10.78\%}$)
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 171_769 ($\textcolor{red}{6.40\%}$) 2_839_066 ($\textcolor{green}{-12.99\%}$) 65_508 108_809 ($\textcolor{green}{-13.18\%}$) 896_597 ($\textcolor{green}{-14.00\%}$) 186_809 ($\textcolor{green}{-11.18\%}$)
vector 172_652 ($\textcolor{red}{7.39\%}$) 2_430_538 ($\textcolor{green}{-12.11\%}$) 24_764 170_991 ($\textcolor{green}{-13.44\%}$) 232_826 ($\textcolor{green}{-11.91\%}$) 231_638 ($\textcolor{green}{-13.31\%}$)
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 230_070 ($\textcolor{red}{17.28\%}$) 326_935_518 ($\textcolor{green}{-7.34\%}$) 298_093_814 ($\textcolor{green}{-12.09\%}$) 41_503 ($\textcolor{green}{-7.39\%}$) 29_780 ($\textcolor{green}{-6.70\%}$)
Rust 528_234 82_789_387 56_794_263 50_651 53_532

Certified map

binary_size generate 10k max mem inc witness
Motoko 232_943 ($\textcolor{red}{13.59\%}$) 5_792_324_783 ($\textcolor{green}{-7.36\%}$) 3_429_924 687_589 ($\textcolor{green}{-7.39\%}$) 445_626 ($\textcolor{green}{-12.01\%}$)
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 301_252 ($\textcolor{red}{8.60\%}$) 50_427 ($\textcolor{green}{-1.68\%}$) 24_523 ($\textcolor{green}{-2.40\%}$) 20_382 ($\textcolor{green}{-2.77\%}$) 21_891 ($\textcolor{green}{-2.69\%}$)
Rust 763_017 552_075 105_203 128_753 139_539

DIP721 NFT

binary_size init mint_token transfer_token
Motoko 244_819 ($\textcolor{red}{6.43\%}$) 19_098 ($\textcolor{green}{-0.88\%}$) 31_854 ($\textcolor{green}{-1.37\%}$) 9_565 ($\textcolor{green}{-1.67\%}$)
Rust 828_238 146_257 380_260 93_763

Statistics

Heartbeat

binary_size heartbeat
Motoko 145_761 ($\textcolor{red}{2.57\%}$) 23_984 ($\textcolor{red}{19.19\%}$)
Rust 25_650 1_179

Timer

binary_size setTimer cancelTimer
Motoko 154_792 ($\textcolor{red}{3.72\%}$) 54_057 ($\textcolor{green}{-0.83\%}$) 4_942 ($\textcolor{green}{-0.72\%}$)
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 311_868 ($\textcolor{red}{4.75\%}$) 818_044 ($\textcolor{red}{4.39\%}$) 16_950 ($\textcolor{green}{-0.56\%}$) 17_406 ($\textcolor{green}{-0.71\%}$)

Statistics

Publisher & Subscriber

pub_binary_size sub_binary_size subscribe_caller subscribe_callee publish_caller publish_callee
Motoko 172_768 ($\textcolor{red}{3.59\%}$) 155_860 ($\textcolor{red}{2.61\%}$) 29_874 ($\textcolor{green}{-0.27\%}$) 12_492 ($\textcolor{green}{-0.51\%}$) 23_937 ($\textcolor{green}{-0.51\%}$) 6_816 ($\textcolor{green}{-0.81\%}$)
Rust 511_870 565_407 71_728 44_318 95_767 53_941

Statistics

github-actions[bot] commented 1 year 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 167_316 9_230_374_182 61_987_732 382_826 7_246_862_420 411_340
triemap 171_390 16_198_090_366 74_216_052 309_052 782_396 769_026
rbtree 171_502 7_930_546_839 57_995_940 137_477 357_040 401_036
splay 166_269 15_696_985_410 53_995_876 752_855 790_594 1_106_735
btree 243_933 11_541_962_095 31_103_892 400_549 543_692 612_045
zhenya_hashmap 184_431 3_538_128_781 65_987_480 93_396 112_641 129_949
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 158_536 6_553_514_370 29_995_836 720_429 265_478 686_570
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 171_769 2_839_066 65_508 108_809 896_597 186_809
vector 172_652 2_430_538 24_764 170_991 232_826 231_638
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 230_070 326_935_518 298_093_814 41_503 29_780
Rust 528_234 82_789_387 56_794_263 50_651 53_532

Certified map

binary_size generate 10k max mem inc witness
Motoko 232_943 5_792_324_783 3_429_924 687_589 445_626
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 301_252 50_427 24_523 20_382 21_891
Rust 763_017 552_075 105_203 128_753 139_539

DIP721 NFT

binary_size init mint_token transfer_token
Motoko 244_819 19_098 31_854 9_565
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 145_761 23_984
Rust 25_650 1_179

Timer

binary_size setTimer cancelTimer
Motoko 154_792 54_057 4_942
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 311_868 818_044 16_950 17_406

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 172_768 155_860 29_874 12_492 23_937 6_816
Rust 511_870 565_407 71_728 44_318 95_767 53_941