lucasteles/Backdash

Reduce size of the `InputMessage`

lucasteles opened this issue · 0 comments

Today we are using union structs and inline arrays to compose the network input message InputMessage.

This is because, in the first version, the library would use marshaling for message serialization. This approach was dropped in favor of using our custom serialization API, but the type was kept as a union type using one single non-generic serializer.

The problem is that each ProtocolMessage message instance will have the larger union member size, being the input body of at least 512 bytes, this is a waste of stack memory and performance (on copy).

Also, this broke the Microsoft guideline for struct size, which should be of the maximum size of 16 bytes.

We could use an ArrayPool<byte> instead. But this will break the union-type rules.