Conversation
- using the ByteUtils library for binary conversions - created a new TypedSerializer that stores the candid type data so it eliminates the need to decode and encode the types each time.
Benchmark Results2025-11-22 22:17:48.329376093 UTC: [Canister l62sy-yx777-77777-aaabq-cai] Generating test data for all types... bench/serde.bench.mo
|
| decode() | encode() | |
|---|---|---|
| Serde: One Shot | 580_619_814 |
1_582_835_012 |
| Serde: One Shot sans type inference | 347_644_069 |
1_122_751_224 |
| Motoko (to_candid(), from_candid()) | 33_973_873 |
9_652_826 |
| Serde: Single Type Serializer | 155_992_543 |
257_774_568 |
Heap
| decode() | encode() | |
|---|---|---|
| Serde: One Shot | 3.36 MiB |
-11.43 MiB |
| Serde: One Shot sans type inference | 21.36 MiB |
-19.38 MiB |
| Motoko (to_candid(), from_candid()) | 644.78 KiB |
603.04 KiB |
| Serde: Single Type Serializer | 7.87 MiB |
9.29 MiB |
Garbage Collection
| decode() | encode() | |
|---|---|---|
| Serde: One Shot | 28.57 MiB |
91.78 MiB |
| Serde: One Shot sans type inference | 0 B |
59.78 MiB |
| Motoko (to_candid(), from_candid()) | 0 B |
0 B |
| Serde: Single Type Serializer | 0 B |
0 B |
bench/types.bench.mo $({\color{green}-3.35\%})$
Benchmarking Serde by Data Types
Performance comparison across all supported Candid data types with 10k operations
Instructions:
Heap:
Stable Memory:
Garbage Collection:
Instructions
| encode() | encode(sans inference) | decode() | decode(sans inference) | |
|---|---|---|---|---|
| Nat | 67_124 |
61_228 |
15_086 |
30_234 |
| Nat8 | 66_554 |
60_957 |
15_066 |
30_531 |
| Nat16 | 67_835 |
62_535 |
15_876 |
31_658 |
| Nat32 | 69_469 |
64_467 |
16_981 |
33_080 |
| Nat64 | 72_153 |
67_449 |
18_651 |
35_067 |
| Int | 69_741 |
65_465 |
17_700 |
34_433 |
| Int8 | 69_009 |
65_032 |
17_541 |
34_591 |
| Int16 | 70_290 |
66_610 |
18_351 |
35_718 |
| Int32 | 72_072 |
68_690 |
19_610 |
37_294 |
| Int64 | 74_758 |
71_674 |
21_281 |
39_282 |
| Float | 97_334 |
94_470 |
48_905 |
67_223 |
| Bool | 71_590 |
69_051 |
19_896 |
38_591 |
| Text | 75_910 |
73_645 |
23_251 |
42_208 |
| Null | 71_484 |
69_740 |
83_611 |
81_292 |
| Empty | 71_898 |
70_452 |
84_111 |
82_015 |
| Principal | 92_117 |
90_776 |
31_330 |
51_248 |
| Blob | 235_498 |
202_694 |
86_017 |
104_240 |
| Option(Nat) | 107_868 |
85_360 |
27_137 |
45_687 |
| Option(Text) | 111_744 |
89_324 |
30_184 |
49_001 |
| Array(Nat8) | 134_174 |
88_266 |
29_632 |
48_821 |
| Array(Text) | 187_222 |
121_442 |
52_806 |
72_267 |
| Array(Record) | 294_518 |
205_847 |
83_171 |
83_490 |
| Record(Nested) | 766_477 |
545_208 |
407_131 |
139_591 |
| Variant(Simple) | 149_994 |
136_283 |
69_627 |
54_459 |
| Variant(Complex) | 966_596 |
819_798 |
572_853 |
118_460 |
| Large Text | 5_680_884 |
5_683_770 |
1_426_848 |
1_450_957 |
| Large Array | 7_009_823 |
2_700_668 |
962_246 |
984_660 |
| Deep Nesting | 616_404 |
442_699 |
138_618 |
118_081 |
| Wide Record | 801_688 |
483_081 |
516_796 |
309_985 |
Heap
| encode() | encode(sans inference) | decode() | decode(sans inference) | |
|---|---|---|---|---|
| Nat | 19.73 KiB |
16.88 KiB |
10.43 KiB |
10.37 KiB |
| Nat8 | 19.72 KiB |
16.86 KiB |
10.43 KiB |
10.37 KiB |
| Nat16 | 19.75 KiB |
16.89 KiB |
10.43 KiB |
10.37 KiB |
| Nat32 | 19.76 KiB |
16.91 KiB |
10.43 KiB |
10.37 KiB |
| Nat64 | 19.8 KiB |
16.94 KiB |
10.44 KiB |
10.38 KiB |
| Int | 19.73 KiB |
16.88 KiB |
10.43 KiB |
10.37 KiB |
| Int8 | 19.72 KiB |
16.86 KiB |
10.43 KiB |
10.37 KiB |
| Int16 | 19.75 KiB |
16.89 KiB |
10.43 KiB |
10.37 KiB |
| Int32 | 19.77 KiB |
16.92 KiB |
10.44 KiB |
10.38 KiB |
| Int64 | 19.81 KiB |
16.96 KiB |
10.46 KiB |
10.4 KiB |
| Float | 20.48 KiB |
17.63 KiB |
11.24 KiB |
11.18 KiB |
| Bool | 19.72 KiB |
16.86 KiB |
10.43 KiB |
10.37 KiB |
| Text | 19.75 KiB |
16.89 KiB |
10.52 KiB |
10.46 KiB |
| Null | 19.68 KiB |
16.83 KiB |
20.26 KiB |
17.32 KiB |
| Empty | 19.68 KiB |
16.83 KiB |
20.26 KiB |
17.32 KiB |
| Principal | 19.91 KiB |
17.05 KiB |
10.66 KiB |
10.6 KiB |
| Blob | 28.84 KiB |
22.04 KiB |
14.21 KiB |
13.93 KiB |
| Option(Nat) | 22.75 KiB |
17.29 KiB |
10.74 KiB |
10.46 KiB |
| Option(Text) | 22.77 KiB |
17.32 KiB |
10.84 KiB |
10.55 KiB |
| Array(Nat8) | 25.22 KiB |
17.39 KiB |
10.89 KiB |
10.61 KiB |
| Array(Text) | 26.36 KiB |
17.77 KiB |
11.68 KiB |
11.39 KiB |
| Array(Record) | 33.5 KiB |
21.23 KiB |
14.2 KiB |
12.96 KiB |
| Record(Nested) | 55.37 KiB |
32.36 KiB |
26.23 KiB |
16.11 KiB |
| Variant(Simple) | 25.58 KiB |
18.38 KiB |
12.48 KiB |
10.62 KiB |
| Variant(Complex) | 66.8 KiB |
42.62 KiB |
31.35 KiB |
14.52 KiB |
| Large Text | 123.98 KiB |
121.13 KiB |
39.23 KiB |
39.18 KiB |
| Large Array | 273.89 KiB |
90.6 KiB |
38.51 KiB |
38.23 KiB |
| Deep Nesting | 54.22 KiB |
30.07 KiB |
18.3 KiB |
15.09 KiB |
| Wide Record | 45.81 KiB |
27.46 KiB |
36.48 KiB |
27.13 KiB |
Garbage Collection
| encode() | encode(sans inference) | decode() | decode(sans inference) | |
|---|---|---|---|---|
| Nat | 0 B |
0 B |
0 B |
0 B |
| Nat8 | 0 B |
0 B |
0 B |
0 B |
| Nat16 | 0 B |
0 B |
0 B |
0 B |
| Nat32 | 0 B |
0 B |
0 B |
0 B |
| Nat64 | 0 B |
0 B |
0 B |
0 B |
| Int | 0 B |
0 B |
0 B |
0 B |
| Int8 | 0 B |
0 B |
0 B |
0 B |
| Int16 | 0 B |
0 B |
0 B |
0 B |
| Int32 | 0 B |
0 B |
0 B |
0 B |
| Int64 | 0 B |
0 B |
0 B |
0 B |
| Float | 0 B |
0 B |
0 B |
0 B |
| Bool | 0 B |
0 B |
0 B |
0 B |
| Text | 0 B |
0 B |
0 B |
0 B |
| Null | 0 B |
0 B |
0 B |
0 B |
| Empty | 0 B |
0 B |
0 B |
0 B |
| Principal | 0 B |
0 B |
0 B |
0 B |
| Blob | 0 B |
0 B |
0 B |
0 B |
| Option(Nat) | 0 B |
0 B |
0 B |
0 B |
| Option(Text) | 0 B |
0 B |
0 B |
0 B |
| Array(Nat8) | 0 B |
0 B |
0 B |
0 B |
| Array(Text) | 0 B |
0 B |
0 B |
0 B |
| Array(Record) | 0 B |
0 B |
0 B |
0 B |
| Record(Nested) | 0 B |
0 B |
0 B |
0 B |
| Variant(Simple) | 0 B |
0 B |
0 B |
0 B |
| Variant(Complex) | 0 B |
0 B |
0 B |
0 B |
| Large Text | 0 B |
0 B |
0 B |
0 B |
| Large Array | 0 B |
0 B |
0 B |
0 B |
| Deep Nesting | 0 B |
0 B |
0 B |
0 B |
| Wide Record | 0 B |
0 B |
0 B |
0 B |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Updaets
mentation
entry