eiriktsarpalis / PolyType

Practical generic programming for C#
https://eiriktsarpalis.github.io/PolyType/
MIT License
145 stars 6 forks source link

Add a reference to MessagePack implementation #14

Closed AArnott closed 1 week ago

AArnott commented 3 weeks ago

This pull request includes updates to the README.md file, enhancements to the SpanDictionary class, and improvements to the equality members of the BaseClass and DerivedClass in the test types.

Documentation Updates:

Code Enhancements:

Test Improvements:

AArnott commented 3 weeks ago

Incidentally, upgrading the baseline from MessagePack v2 to v3 produces this:

Serialization

Method Mean Error StdDev Ratio Allocated Alloc Ratio
Serialize_TypeShape 130.9 ns 0.37 ns 0.33 ns 0.95 - NA
Serialize_Library 137.6 ns 0.23 ns 0.21 ns 1.00 - NA

This improves serialization slightly, making TypeShape fair slightly worse by comparison.

Deserialization

Method Mean Error StdDev Ratio Allocated Alloc Ratio
Deserialize_TypeShape 148.1 ns 0.63 ns 0.56 ns 1.21 32 B 1.00
Deserialize_Library 122.2 ns 0.74 ns 0.61 ns 1.00 32 B 1.00

Deserialization improves significantly, making TypeShape look quite a bit worse. This is due to using a dictionary to look up property names, which the AOT formatter avoids.

AArnott commented 2 weeks ago

Serialization is somehow faster than the Ref.Emit specialized code produced by the MessagePack library. I don't know how that's possible.

I suspect it's because in this version, we call MessagePackWriter.Write(string) directly rather than including a level of indirection that allows for some other serializer to hijack that operation at runtime to serialize something else (e.g. so that a string is only serialized once).

AArnott commented 2 weeks ago

@neuecc this should interest you.