dfinity / canister-profiling

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

Moc inline with new meter alloc o3 #86

Closed crusso closed 11 months ago

crusso commented 11 months ago

base: new meter; no wasm-opt against selective inlining including allocation + wasm-op 03

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 148_740 ($\textcolor{green}{-6.46\%}$) 8_341_274_314 ($\textcolor{green}{-12.17\%}$) 61_987_732 343_814 ($\textcolor{green}{-12.48\%}$) 6_578_732_491 ($\textcolor{green}{-9.90\%}$) 370_088 ($\textcolor{green}{-12.56\%}$)
triemap 152_665 ($\textcolor{green}{-5.58\%}$) 13_751_819_242 ($\textcolor{green}{-20.51\%}$) 74_216_052 253_688 ($\textcolor{green}{-26.69\%}$) 655_809 ($\textcolor{green}{-22.04\%}$) 646_250 ($\textcolor{green}{-21.67\%}$)
rbtree 156_021 ($\textcolor{green}{-3.70\%}$) 7_083_625_905 ($\textcolor{green}{-16.30\%}$) 57_995_940 113_092 ($\textcolor{green}{-28.71\%}$) 316_065 ($\textcolor{green}{-17.92\%}$) 325_269 ($\textcolor{green}{-23.89\%}$)
splay 148_292 ($\textcolor{green}{-5.78\%}$) 13_216_992_673 ($\textcolor{green}{-24.14\%}$) 53_995_876 626_740 ($\textcolor{green}{-25.49\%}$) 659_612 ($\textcolor{green}{-25.44\%}$) 919_398 ($\textcolor{green}{-25.54\%}$)
btree 212_512 ($\textcolor{green}{-0.63\%}$) 10_257_934_163 ($\textcolor{green}{-22.70\%}$) 31_103_892 352_463 ($\textcolor{green}{-23.58\%}$) 481_276 ($\textcolor{green}{-23.52\%}$) 532_764 ($\textcolor{green}{-24.60\%}$)
zhenya_hashmap 158_758 ($\textcolor{green}{-5.75\%}$) 3_095_567_422 ($\textcolor{green}{-20.14\%}$) 65_987_480 78_897 ($\textcolor{green}{-26.01\%}$) 90_670 ($\textcolor{green}{-30.94\%}$) 91_012 ($\textcolor{green}{-41.69\%}$)
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 139_700 ($\textcolor{green}{-8.29\%}$) 5_684_588_471 ($\textcolor{green}{-22.09\%}$) 29_995_836 619_848 ($\textcolor{green}{-23.77\%}$) 228_031 ($\textcolor{green}{-23.37\%}$)
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 150_916 ($\textcolor{green}{-6.51\%}$) 2_560_913 ($\textcolor{green}{-21.51\%}$) 65_508 94_485 ($\textcolor{green}{-24.61\%}$) 799_435 ($\textcolor{green}{-23.32\%}$) 169_485 ($\textcolor{green}{-19.42\%}$)
vector 152_122 ($\textcolor{green}{-5.38\%}$) 2_152_008 ($\textcolor{green}{-22.18\%}$) 24_764 149_645 ($\textcolor{green}{-24.24\%}$) 206_427 ($\textcolor{green}{-21.90\%}$) 196_488 ($\textcolor{green}{-26.47\%}$)
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 186_405 ($\textcolor{green}{-4.98\%}$) 271_004_746 ($\textcolor{green}{-23.19\%}$) 257_809_157 ($\textcolor{green}{-23.97\%}$) 34_239 ($\textcolor{green}{-23.60\%}$) 24_795 ($\textcolor{green}{-22.31\%}$)
Rust 528_234 82_789_387 56_794_263 50_651 53_532

Certified map

binary_size generate 10k max mem inc witness
Motoko 202_262 ($\textcolor{green}{-1.37\%}$) 4_739_032_190 ($\textcolor{green}{-24.21\%}$) 3_429_924 562_235 ($\textcolor{green}{-24.27\%}$) 400_298 ($\textcolor{green}{-20.96\%}$)
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 257_901 ($\textcolor{green}{-7.03\%}$) 47_151 ($\textcolor{green}{-8.07\%}$) 22_255 ($\textcolor{green}{-11.74\%}$) 18_557 ($\textcolor{green}{-11.46\%}$) 19_609 ($\textcolor{green}{-13.00\%}$)
Rust 763_017 552_075 105_203 128_753 139_539

DIP721 NFT

binary_size init mint_token transfer_token
Motoko 204_979 ($\textcolor{green}{-10.89\%}$) 17_690 ($\textcolor{green}{-8.18\%}$) 29_708 ($\textcolor{green}{-8.02\%}$) 8_778 ($\textcolor{green}{-9.76\%}$)
Rust 828_238 146_257 380_260 93_763

Statistics

Heartbeat

binary_size heartbeat
Motoko 127_807 ($\textcolor{green}{-10.06\%}$) 19_236 ($\textcolor{green}{-4.40\%}$)
Rust 25_650 549 ($\textcolor{green}{-53.44\%}$)

Timer

binary_size setTimer cancelTimer
Motoko 136_166 ($\textcolor{green}{-8.76\%}$) 51_395 ($\textcolor{green}{-5.71\%}$) 4_605 ($\textcolor{green}{-7.49\%}$)
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 282_051 ($\textcolor{green}{-5.26\%}$) 770_378 ($\textcolor{green}{-1.69\%}$) 16_464 ($\textcolor{green}{-3.41\%}$) 16_608 ($\textcolor{green}{-5.26\%}$)

Statistics

Publisher & Subscriber

pub_binary_size sub_binary_size subscribe_caller subscribe_callee publish_caller publish_callee
Motoko 151_854 ($\textcolor{green}{-8.95\%}$) 136_083 ($\textcolor{green}{-10.41\%}$) 28_563 ($\textcolor{green}{-4.65\%}$) 11_918 ($\textcolor{green}{-5.08\%}$) 22_822 ($\textcolor{green}{-5.14\%}$) 6_412 ($\textcolor{green}{-6.69\%}$)
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 148_740 8_341_274_314 61_987_732 343_814 6_578_732_491 370_088
triemap 152_665 13_751_819_242 74_216_052 253_688 655_809 646_250
rbtree 156_021 7_083_625_905 57_995_940 113_092 316_065 325_269
splay 148_292 13_216_992_673 53_995_876 626_740 659_612 919_398
btree 212_512 10_257_934_163 31_103_892 352_463 481_276 532_764
zhenya_hashmap 158_758 3_095_567_422 65_987_480 78_897 90_670 91_012
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 139_700 5_684_588_471 29_995_836 619_848 228_031 590_771
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 150_916 2_560_913 65_508 94_485 799_435 169_485
vector 152_122 2_152_008 24_764 149_645 206_427 196_488
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 186_405 271_004_746 257_809_157 34_239 24_795
Rust 528_234 82_789_387 56_794_263 50_651 53_532

Certified map

binary_size generate 10k max mem inc witness
Motoko 202_262 4_739_032_190 3_429_924 562_235 400_298
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 257_901 47_151 22_255 18_557 19_609
Rust 763_017 552_075 105_203 128_753 139_539

DIP721 NFT

binary_size init mint_token transfer_token
Motoko 204_979 17_690 29_708 8_778
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 127_807 19_236
Rust 25_650 549

Timer

binary_size setTimer cancelTimer
Motoko 136_166 51_395 4_605
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 282_051 770_378 16_464 16_608

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 151_854 136_083 28_563 11_918 22_822 6_412
Rust 511_870 565_407 71_728 44_318 95_767 53_941