I had an issue with crate performance in IDE. My Rust crate, ~12000 SLOC, was very slow in VS Code. I figured out some measures against slowdown: split the crate, use less generic-heavy structs.
But I also found out that Serde derive macros were seriously slowing things down. So I wrote my own traits, that were calling Zerocopy's methods to save data.
Now I wanted to test honestly, how slower Serde will be given the same structs.
I made this crate that generates random structures and some stub code to prevent code optimizations. There's a chart with the results on different sizes, and also an example of generated code.
I found that bincode has derive macros now too, and added them. There was packbytes crate, but couldn't write test code for it.
Here's the result table. Please post your comments.
I'm not sure if this will help you or not, but cargo allows you to configure separate opt-level for proc macro crates :
# Cargo.toml
# Set the settings for build scripts and proc-macros.
[profile.dev.build-override]
opt-level = 3
Maybe compiling proc macros with release optimizations will make them run fast enough.
Tested on the 10..600 quantities, performance is slightly worse.
| count |
bincode |
serde |
traits |
| 10 |
0.14 |
0.17 |
0.08 |
| 15 |
0.17 |
0.37 |
0.14 |
| 20 |
0.14 |
0.27 |
0.12 |
| 30 |
0.20 |
0.43 |
0.20 |
| 50 |
0.34 |
0.83 |
0.21 |
| 75 |
0.43 |
1.00 |
0.28 |
| 100 |
0.52 |
1.11 |
0.33 |
| 150 |
0.75 |
1.63 |
0.44 |
| 200 |
0.99 |
2.38 |
0.53 |
| 300 |
1.45 |
3.10 |
0.72 |
| 400 |
1.61 |
3.47 |
0.93 |
| 600 |
2.60 |
6.21 |
1.45 |
Added rkyv, and fixed a bug where a generated struct or enum would be empty.
| Structs |
bincode |
serde |
rkyv |
My traits |
| 10 |
0,07 |
0,12 |
0,15 |
0,06 |
| 15 |
0,09 |
0,17 |
0,24 |
0,07 |
| 20 |
0,10 |
0,17 |
0,20 |
0,08 |
| 30 |
0,19 |
0,44 |
0,50 |
0,11 |
| 50 |
0,25 |
0,61 |
0,72 |
0,14 |
| 75 |
0,39 |
0,90 |
1,17 |
0,20 |
| 100 |
0,43 |
0,98 |
1,26 |
0,22 |
| 150 |
0,67 |
1,47 |
1,89 |
0,33 |
| 200 |
0,93 |
2,10 |
2,88 |
0,45 |
| 300 |
1,30 |
2,96 |
3,99 |
0,66 |
| 400 |
1,81 |
4,15 |
5,96 |
0,92 |
| 600 |
2,66 |
6,06 |
9,73 |
1,37 |
And another crate: musli. Must say, it's one specific of its formats, YMMV, but I couldn't make it compile with the densest and fastest one.
musli-zerocopy won't work with non-fixed-size structs.
| Structs |
bincode |
serde |
rkyv |
musli |
My traits |
| 10 |
0.11 |
0.18 |
0.21 |
0.83 |
0.12 |
| 15 |
0.16 |
0.34 |
0.39 |
1.86 |
0.11 |
| 20 |
0.20 |
0.45 |
0.51 |
2.17 |
0.13 |
| 30 |
0.27 |
0.60 |
0.78 |
3.25 |
0.15 |
| 50 |
0.35 |
0.81 |
1.00 |
3.97 |
0.24 |
| 75 |
0.71 |
1.22 |
1.62 |
5.90 |
0.28 |
| 100 |
0.67 |
1.79 |
1.94 |
7.53 |
0.36 |
| 150 |
1.33 |
2.46 |
4.12 |
13.99 |
0.58 |
| 200 |
1.39 |
3.16 |
4.10 |
15.71 |
0.70 |
| 300 |
2.05 |
4.66 |
6.73 |
28.31 |
1.19 |
| 400 |
3.21 |
7.07 |
9.87 |
35.12 |
1.37 |
| 600 |
3.89 |
9.70 |
15.45 |
47.44 |
2.01 |
Wincode, a compatible replacement for bincode, which is unmaintained since 2025.