serdedotnet / serde

Serde.NET is a C# port of the popular Serde serialization library for Rust
https://serdedotnet.github.io/
BSD 3-Clause "New" or "Revised" License
142 stars 5 forks source link

Implement zero-alloc support for reading field names #123

Closed agocke closed 1 year ago

agocke commented 1 year ago

Currently the custom type visitor just deserializes field names as strings, which allocates a new System.String for each field. However, the API supports passing through a ReadOnlySpan for UTF8 strings. This change should provide support using the ROS in the normal path and avoid allocation.

Before:

Method Mean Error StdDev Gen0 Gen1 Allocated
SerdeJson 1,983.3 ns 24.13 ns 22.57 ns 0.2708 - 1712 B

After:

Method Mean Error StdDev Gen0 Gen1 Allocated
SerdeJson 1,729.5 ns 16.44 ns 15.38 ns 0.1831 - 1152 B