clockworklabs / SpacetimeDB

Multiplayer at the speed of light
https://spacetimedb.com
Other
4.41k stars 110 forks source link

Proposal for C# SDK performance #1934

Open bfops opened 2 weeks ago

bfops commented 2 weeks ago

The BSATN codegen for c# often generates pattern like new(new()) to emulate rust's variant types, and wraps certain value types into reference classes, such as Timestamp and EnergyQuota.

Similarly, many allocations for encoding and decoding of messages can be made once and reused, or at least pooled to avoid allocations.

A great deal of GC overhead and pressure can be removed by refactoring codegen to emit high-performance C#.

One benefit of this is to gain support for Burst compilation and ECS in Unity, as they do not allow reference types to be used at all.

Proposal should also look at the way updates are processed by SDK clients and look at a way to send the matching memory layouts directly from rust. Right now an intermediate client-side processing pass using a temporary hashmap is required to combine matching inserts/deletes into updates.