NatLabs / serde

Serialization and Deserialization library for motoko
MIT License
16 stars 3 forks source link

One shot Encoding and Decoding #29

Closed tomijaga closed 2 months ago

tomijaga commented 2 months ago

Encodes the type and value as it scans the candid variant looking only once

performance benchmarks

Instructions

decode() encode()
Motoko (to_candid(), from_candid()) 21_778_910 7_236_572
Serde 'mo:motoko_candid' lib 1_054_078_235 2_000_977_097
Serde: One Shot 298_167_258 864_784_948
Serde: One Shot sans type inference 343_730_830 654_138_729

Heap

decode() encode()
Motoko (to_candid(), from_candid()) 433_756 376_168
Serde 'mo:motoko_candid' lib 10_441_244 -1_598_868
Serde: One Shot 18_078_612 -11_697_036
Serde: One Shot sans type inference 19_894_612 -4_651_180

Instructions are reduced at the cost of more heap allocations