Packed vs Struct comparison
FlatMessage supports two types of nested structures, each with different characteristics and compatibility behaviors: FlatMessageStruct
and FlatMessagePacked
. To test the performance of these two types, we can use the following structure:
#![allow(unused)] fn main() { pub struct InnerStruct { s1: String, s2: String, v1: u32, v2: u64, arr: Vec<u32>, } pub struct NestedStruct { field: InnerStruct, } }
with the following settings (which will be used in the benchmarks):
- For FlatMessageStruct:
#![allow(unused)] fn main() { #[derive(FlatMessageStruct)] pub struct InnerStruct { ... } #[derive(FlatMessage)] pub struct NestedStruct { #[flat_message_item(kind = struct, align = 4)] field: InnerStruct, } }
- For FlatMessagePacked:
#![allow(unused)] fn main() { #[derive(FlatMessagePacked)] pub struct InnerStruct { ... } #[derive(FlatMessage)] pub struct NestedStruct { #[flat_message_item(kind = packed, align = 4)] field: InnerStruct, } }
Test specs
- Iterations:
k = 10
- Serialization and deserialization repetitions / iteration:
n = 1000000
- Data size:
161
bytes
Results
1. Windows Execution
Algorithm | Size (b) | Ser. (ms) | Deser. (ms) | Ser+Deser.(ms) |
---|---|---|---|---|
FlatMessagePacked (⚠️) | 185 [ +14%] | 17.22 [ 16.57 - 18.34] | 129.99 [123.44 - 135.90] | 152.09 [144.31 - 159.41] |
FlatMessagePacked | 185 [ +14%] | 19.02 [ 18.28 - 21.76] | 148.50 [137.33 - 153.57] | 169.07 [157.77 - 175.84] |
FlatMessageStruct | 217 [ +34%] | 21.34 [ 20.23 - 22.37] | 155.35 [145.38 - 163.77] | 182.94 [170.53 - 189.36] |
FlatMessageStruct (⚠️) | 217 [ +34%] | 21.22 [ 19.83 - 21.58] | 158.54 [149.78 - 163.35] | 190.52 [180.28 - 194.45] |
2. MacOS Execution
Algorithm | Size (b) | Ser. (ms) | Deser. (ms) | Ser+Deser.(ms) |
---|---|---|---|---|
FlatMessagePacked (⚠️) | 185 [ +14%] | 15.75 [ 15.34 - 17.77] | 68.92 [ 68.41 - 71.38] | 86.73 [ 86.27 - 88.73] |
FlatMessagePacked | 185 [ +14%] | 15.85 [ 15.31 - 28.30] | 87.32 [ 86.91 - 87.82] | 104.72 [104.06 - 105.26] |
FlatMessageStruct (⚠️) | 217 [ +34%] | 20.39 [ 19.97 - 20.45] | 95.73 [ 95.34 - 96.00] | 116.05 [113.32 - 116.77] |
FlatMessageStruct | 217 [ +34%] | 20.34 [ 20.07 - 20.40] | 95.30 [ 94.87 - 95.82] | 116.12 [113.39 - 116.94] |
3. Linux Execution
Algorithm | Size (b) | Ser. (ms) | Deser. (ms) | Ser+Deser.(ms) |
---|---|---|---|---|
FlatMessagePacked (⚠️) | 185 [ +14%] | 13.65 [ 13.26 - 14.06] | 53.51 [ 46.85 - 62.58] | 68.61 [ 61.87 - 104.00] |
FlatMessagePacked | 185 [ +14%] | 16.54 [ 15.89 - 26.07] | 68.38 [ 63.62 - 89.71] | 84.28 [ 80.95 - 89.62] |
FlatMessageStruct | 217 [ +34%] | 18.29 [ 17.95 - 29.24] | 78.46 [ 73.16 - 82.87] | 104.51 [ 97.11 - 134.95] |
FlatMessageStruct (⚠️) | 217 [ +34%] | 21.69 [ 21.09 - 31.37] | 80.87 [ 75.30 - 85.39] | 109.66 [102.93 - 123.00] |