Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FlatSharp 8 Planning #448

Open
jamescourtney opened this issue Nov 4, 2024 · 0 comments
Open

FlatSharp 8 Planning #448

jamescourtney opened this issue Nov 4, 2024 · 0 comments

Comments

@jamescourtney
Copy link
Owner

This issue is to track progress and objectives for a future FlatSharp 8 release.

What's wrong with FlatSharp 7?

Nothing major. It works fine! Today, FlatSharp 7 supports .NET Framework, .NET Standard 2.0/2.1, .NET 6, 7, 8, and (soon) 9. This is a robust compatibility matrix. This wide compatibility comes with limitations:

  • No way to support 64 bit flatbuffers in a safe way (Span<T> is limited to the 32 bit address space)
  • APIs generally have to target the lowest common denominator of language features.
  • Adding features such as static interface members introduced compatibility problems between .NET 8 and .NET Standard.

Plans going forward

FlatSharp 8 is an upcoming release that will support .NET 9 (and above) only. FlatSharp 7 will continue to support older versions of .NET in addition to .NET 9. While I don't expect to develop tons more features for FlatSharp 7 going forward, I'm committed to:

  • Backporting some features to v7 (as appropriate)
  • Supporting security in v7 for the foreseeable future.
  • Adding new versions of .NET to FlatSharp v7 for those that don't want to update.

Plans for FlatSharp 8

The introduction of the allows ref struct anti-constraint in .NET 9 is a big deal for FlatSharp. It allows us to remove the explicit dependency on Span<byte>, which will allow supporting 64-bit buffers in turn. In place of a hard dependency on Span<byte>, we'll define something along the following lines:

public interface IFlatBufferSerializationTarget<T> where T : IFlatBufferSerializationTarget<T>
{
    long Length { get; }

    byte this[long index];

    T Slice(long start, long length);

    T Slice(long start);

    Span<byte> AsSpan(long start, int length);
    
    void WriteInt32(long offset, int value);

    void WrintUInt32(long offset, uint value);

    // etc
}

public interface ISerializer<T>
{
     ...
     int Serialize<TTarget>(T item, TTarget target) where TTarget : IFlatBufferSerializationTarget<T>, allows ref struct;
     ...
}

This change will address several structural issues in FlatSharp, such as proper 64-bit support and extensibility.

The Chopping Block

The following features are being considered for removal in FlatSharp 8:

  • Object pooling (technically this is a beta and opt-in behavior in v7). However, I've not heard of any examples of real-world use, and it adds quite a bit to my test and development matrix.

Other new features

  • In addition to .GetMaxSize(), FlatSharp 8 will expose a .GetActualSize() method, which will return the precise number of bytes necessary to serialize an object.
  • Other .NET 9 integration points
  • Support for a "optimize" flag, which allows toggling between "code size" and "raw performance" modes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant