-
Notifications
You must be signed in to change notification settings - Fork 16
Description
I benchmarked using serde-big-array for serializing byte arrays, but it turns out that it's quite slow (benchmark: https://github.com/hrxi/postcard/blob/998fe75309e2695b291146ee8ca02c9bc7e9c1ab/benches/byte_array.rs). I get the following violin graph on my x86_64 machine:

serialize32/own time: [4.8208 ns 4.8477 ns 4.8765 ns]
serialize32/bytes time: [12.389 ns 12.603 ns 12.870 ns]
serialize32/big_array time: [142.25 ns 144.02 ns 146.59 ns]
serialize32/fixed_size time: [15.273 ns 15.353 ns 15.449 ns]
serialize32/variable_size time: [134.84 ns 135.79 ns 136.98 ns]
own is basically just passing the byte array directly into the output, with no length prefix.
bytes uses serde's serialize_bytes which includes a length prefix and then dumps the rest of the bytes directly.
big_array uses serde-big-array, no length prefix.
fixed_size uses serde's impl Serialize for [u8; 32], no length prefix.
variable_size uses serde's impl Serialize for [u8], which includes a length prefix.
As you can see, big_array takes approximately 10x the time as the native serde impl for fixed-size arrays. This seems bad.