u/AnnoyingMemer

▲ 23 r/fsharp

I've recently started learning F# and the entire paradigm of functional programming. I'm doing this because I want to research the applications of both the language and the approach it requires in gamedev, particularly in systems like finite state machines and ECS. Are there any, and could you point me to any good sources?

reddit.com
u/AnnoyingMemer — 9 days ago
▲ 14 r/csharp+1 crossposts

I have spent some time recently reimplementing Mojang's DataFixerUpper library (which handles serialization and data transformation through the lifetime of a project) in C# with a few of my own takes on it. It uses literally zero reflection and rivals the built-in System.Text.Json library in allocations, sometimes even beating it (although latency is a bit of a problem right now because I'm not batching operations together), as evidenced by the benchmarks:

| Method                     | Mean     | Error    | StdDev    | Median   | Gen0   | Allocated |
|----------------------------|---------:|---------:|----------:|---------:|-------:|----------:|
| STJ_Serialize              | 237.9 ns | 24.37 ns |  71.86 ns | 194.4 ns | 0.0343 |      72 B |
| STJ_Serialize_IntArray     | 186.2 ns | 20.36 ns |  60.02 ns | 142.0 ns | 0.0191 |      40 B |
| STJ_Deserialize            | 321.7 ns |  5.65 ns |  10.19 ns | 318.4 ns | 0.0801 |     168 B |
| STJ_Deserialize_IntArray   | 198.2 ns |  2.63 ns |   2.46 ns | 197.5 ns | 0.0534 |     112 B |
| Codec_Serialize            | 546.0 ns | 59.11 ns | 174.29 ns | 418.2 ns | 0.0534 |     112 B |
| Codec_Serialize_IntArray   | 393.4 ns |  2.92 ns |   2.28 ns | 392.7 ns | 0.0610 |     128 B |
| Codec_Deserialize          | 524.7 ns |  5.14 ns |   4.29 ns | 524.2 ns | 0.0305 |      64 B |
| Codec_Deserialize_IntArray | 475.7 ns |  4.07 ns |   3.40 ns | 475.0 ns | 0.0343 |      72 B |

The library is designed in such a way that you can create tiny codecs for structs/classes and compose them together to serialize even complex/nested DTOs seamlessly. You can also define "timelines" for your objects and pass their serialized versions through transformation pipelines to add/remove/rename keys.

The library also happens to be format-agnostic by design, so the exact same APIs would work with a backend for cbor, custom binary, yaml, burping into the mic vocoded into gangsta's paradise or any other format you might think of.

u/AnnoyingMemer — 10 days ago