invertedtomato / packing

Library for encoding integers in the minimal number of bits. Includes VLQ and Elias Omega encoding.
MIT License
76 stars 6 forks source link

{Readonly}Span/Memory usage in API? #3

Closed dzmitry-lahoda closed 5 years ago

invertedtomato commented 5 years ago

I've had a look into Span/Memory. In this particular case, they offer no performance advantage over a Byte array - actually the opposite - a slight performance decrease.

dzmitry-lahoda commented 5 years ago

.NET Core 3 has optimization for Spans. Specifically, it can inline ReadOnlySpans.

dzmitry-lahoda commented 5 years ago

I have replaced uint array with custom wrapper and it works well (kind of less than 1% or less perf degradation)[1]

But I guess for byte array backed storage it may appear up to 5%.[2]

[1] https://github.com/dzmitry-lahoda/NetStack/blob/4b750853edb6e4fa28d2d23b7fc22fe55bc2f702/Assets/Scripts/src/NetStack.Serialization/BitBuffer.cs#L49

[2] https://github.com/dotnet/coreclr/issues/23620#issuecomment-486982204