-
Notifications
You must be signed in to change notification settings - Fork 90
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
generate csharp partials #63
Comments
I think it's possible to generate c# structs as partial if it not reduce the performance. Also I'm thinking about experimenting with new c# records instead of structs, because:
But of course we need to create a POC and measure it's performance over strucs. |
One of the issues I noticed is that the type models are not thread safe. Concurrent writes can collide on the underlying buffer. The Serialization method would require passing in bufferWriter. From there I would try an inline the serialization into the generated class in order to automatically support polymorphism. ctor(ReadonlySpan<byte> buffer);
virtual void Serialize(IBufferWriter<byte> writer);
virtual void Serialize(Span<byte> buffer);
virtual int GetBufferSize(); If the types were generated as immutable then the A I do have considerable experience with Roslyn code generation and can write an analyzer to generate the c# code. I just need to find the time and knowledge that I will not be the only one using it. |
Here are the serialization benchmarks when bypassing Buffer and using Span
|
If your curious this is what the write looks like. public static Span<byte> FastWrite(this DeviceMotion value, Span<byte> span)
{
return span.Write(StructSize)
.Write(Type)
.Write(value.ts)
.Write(value.acceleration)
.Write(value.orientation)
.Write(value.rotation);
} |
|
public DeviceMotion(ReadOnlySpan<byte> buffer)
{
_ = buffer.ReadInt64(out this.ts)
.ReadSingleArray(out this.acceleration)
.ReadSingleArray(out this.orientation)
.ReadSingleArray(out this.rotation);
} |
@fuocor if you'd like some help I can find time to work on this since I have great interest in this library and in the optimizations you suggested. I don't have specific experience with code generation in C# with Roslyn but I know a good deal of C#. |
@alandemaria. I have a great deal of experience with Roslyn and would appreciate the help but would like the buy-in of |
have you thought about generating the structs as partial, so that they can be extended?
The text was updated successfully, but these errors were encountered: