top | item 45023823

(no title)

trissylegs | 6 months ago

It doesn't have very large standard library. It's just running on a different philosophy on not making the Standard Library "Batteries included". But I find you get less dependencies than npm. Not so many tiny left-pad like microlibraries.

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

discuss

order

No comments yet.