(no title)
trissylegs | 6 months ago
The main cost of compile times is Generics. Rust generics use "Monomorphization" which generate different binary code for every use of a generic type.
serde leverages generics everywhere and it generates the serialization code for every type you make serializable. So when you use `serde_json::to_string(MyType::new())` it follows calls a code path just for serializing MyType to a json string.
The upshot: It's incredibly fast, there's a lot of inlining and other compiler optimisations that can used because of it. No runtime reflection (Which is how Go does a lot of it).
The downsides: Takes a long time to compile cause of all the extra it's generating. Also can inflate binary sizes at bit.
Other languages like Go mostly use run time reflection for Json. Rust doesn't have much runtime reflection so doing it here wouldn't be possible
No comments yet.