Port compatible optimizations from new Memory package to Syroot.BinaryData
Several optimizations compatible with the
Syroot.BinaryData package were found when writing the new Memory package. They should be ported for the 6.0.0 release (it will focus support only newer .NET versions which have proper support for
Span functionality) and maybe put into the new
Syroot.BinaryData.Core package if the logic can be reused (without any performance cost):
Enum parsing can use Unsafe.SizeOf() and MemoryMarshal to prevent type switching on the underlying type.Cannot be ported, optimization needs generic method, but library requires type passed as parameter.
byte*overloads should be used were possible to prevent buffer copies.
String decoding can use the
Decoder.Convertmethod. This method also supports
- Probably a few more. Check remaining parts of the library.
The following changes would be incompatible with the current API and cause big breaking changes, so they're currently not part of this issue:
ByteConvertercould make use of
System.Buffers.Binary.BinaryPrimitivesfunctionality to convert bytes to primitive values and vice versa, but this depends if it the methods provided by this class can fulfill the needs of a
ByteConverter, which would probably need backwards-incompatible changes (if not being removed completely). It should be checked if the converters can be optimized with
- Using only an
Endianenum value instead of a
ByteConverterinstance to determine endianness (again), together with the above mentioned
ByteConverterredesign / removal.