AdrianStrugala / AvroConvert

Rapid Avro serializer for C# .NET
Other
102 stars 27 forks source link

Changing Uuid to be written as underlying bytes #122

Closed gmanvel closed 11 months ago

gmanvel commented 11 months ago

Changing Uuid to be stored as Guid's underlying bytes which would remove overhead of serializing to UTF8 string. As a result serialized byte length shrinks from 36 bytes to 16 bytes as well as speeding up serialization of Uuid fields.

CoreBenchmarks project is meant to house benchmarks for core pieces of library. Running Uuid benchmark dotnet run -c Release --filter "*WriterBenchmarksUuid*" produces the following output

Method Mean Error StdDev Median Ratio Gen0 Allocated Alloc Ratio
WriteUuid_Old 57.9692 ns 1.3138 ns 3.7269 ns 57.9127 ns 1.00 0.0382 160 B 1.00
WriteUuid_Bytes 4.7714 ns 0.1217 ns 0.1895 ns 4.7659 ns 0.09 0.0096 40 B 0.25
WriteUuid_New 0.9664 ns 0.0449 ns 0.0977 ns 0.9309 ns 0.02 - - 0.00

PR is introducing overloads of WriteBytes and WriteBytesRaw methods to work with Span based APIs.

AdrianStrugala commented 11 months ago

Hello @gmanvel, Thank you a lot for your PRs! The performance gain is really impressive. I will play with Span APIs for sure. Unfortunately, as for the Uuid base representation, it would have to remain as strings. That's according to the official Avro specification: https://avro.apache.org/docs/1.11.1/specification/#uuid As for the rest of the changes, they look perferctly