FlatSharp v4.1.0 Release Notes
Release Date: 2020-10-17 // almost 4 years ago-
๐ Version 4.1.0 is a minor release and builds on the performance improvements in 4.0.0.
๐ง The main improvement in version 4.1.0 is support for new configurations for properties:
- ๐ Non-virtual properties now supported (setters are required). Non-Virtual properties are always deserialized greedily.
๐ Protected and Protected Internal setters now supported
[FlatBufferTable]public class MyTable{ [FlatBufferItem(0)] public virtual int VirtualInt { get; protected set; } [FlatBufferItem(1)] public string NonVirtualString { get; protected internal set; } [FlatBufferItem(2)] public virtual int ReadOnlyInt { get; } }
๐ FBS files also support these:
table MyTable // nonVirtual is supported at the table level to set a default for all properties. { VirtualInt:int (setter:"protected"); NonVirtualString:string (setter:"protectedinternal", nonVirtual); ReadOnlyVirtualInt:int (setter:"none"); }
โ Additionally, the FlatSharp compiler now supports the
ObsoleteDefaultConstructor
attribute on tables and structs to apply a [Obsolete] attribute to the generated default constructor. This can help create immutable objects.
Previous changes from v4.0.0
-
๐ Version 4 is a significant milestone for FlatSharp, and represents the culmination of a lot of work. Hope you enjoy it, to the extent that it's possible to enjoy a serialization library!
What's new?
Glad you asked!
- ๐ Support for optional/nullable scalars (tables only) (google/flatbuffers#6014)
- ๐ Support for "indexed vectors", which are Vectors that look and act like Dictionaries. Under the hood, these are sorted vectors that expose a simpler programming model, so it's no longer necessary to worry about whether a vector is sorted or not. Check out the indexed vectors sample!
- ๐ Shared strings are now supported in sorted vectors
- ๐ New method of publishing benchmark data, benchmarks extended to include .NET 5.0
Internal stuff
๐ Lots of work went into optimizing how the CLR JIT treats FlatSharp's code. Performance is increased anywhere from 10 - 30% relative to version 3.3.1.
- Much of this improvement was changes to allow the JIT to elide virtual function calls when invoking methods on SpanReader and InputBuffer. More background is available here: dotnet/runtime#32815
- Other changes involved removing some unnecessary branches and function calls on hot paths
๐ FlatSharp's backend was completely rewritten to be more modular, so that future types can be supported more easily. It is now possible (though not advised) to write your own plugins. This amounted to a rewrite of a large part of the code.
๐ฅ Breaking Changes
FlatSharp adheres to semantic versioning, and there are breaking public API changes in version 4:
SpanWriter
has been changed from aclass
to astruct
. It is no longer inheritable. A newISpanWriter
interface has been introduced should you wish to provide your own.UnsafeSpanWriter
remains a class, but is sealed.- ๐ The base class
InputBuffer
has been removed. It has been replaced withIInputBuffer
ArrayInputBuffer
,MemoryInputBuffer
,ReadOnlyMemoryInputBuffer
, and the unsafe variants remain the same.
- ๐ Support for memory vectors has been dropped for all types but
byte
. This was to address a design oversight where precompiled serializers would produce incorrect results when running on big-endian platforms.Memory<byte>
andReadOnlyMemory<byte>
remain supported.