Zaid-Ajaj / Fable.Remoting

Type-safe communication layer (RPC-style) for F# featuring Fable and .NET Apps
https://zaid-ajaj.github.io/Fable.Remoting/
MIT License
272 stars 54 forks source link

Speed up integer and float deserialization #286

Closed kerams closed 2 years ago

kerams commented 2 years ago

Deserializing an array of a million int32 is around 10x faster in JS (debug build, not optimized by terser), almost 20% on .NET. The same technique cannot be used for int64 (in JS) because the type is emulated and the operation would end up slower.

cc @juselius

juselius commented 2 years ago

@kerams I finally got around to test the changes. I'm not seeing any significant speedups for JS, unfortunately. I'm on currently on dotnet 6.0.100 and fable 3.6.3. I have not yet tested the .NET performance yet, but I will do it soon.

kerams commented 2 years ago

@juselius, paste https://gist.github.com/kerams/eb03fdf1b918b8bee9c90c900b3e36cf to the Fable REPL and check the second number printed. Then find ReadUInt32 and switch the commented out lines. For me the difference is ~186 vs ~21.

If you see similar results, something else is the bottleneck, because even when I change the generated data range for floats to 300_000 (which should correspond to your original sample - 1 million int32, 300k float32 - but it's also worth mentioning that the serialized array is around 7MB, which is a lot less than your 60MB for some reason), the reported deserialization time is around 80ms.

juselius commented 2 years ago

@kerams I see what you mean. I need to investigate a bit more why I'm not seeing speedups in production. The error is probably behind the keyboard.

juselius commented 2 years ago

@kerams sorry my bad, the error was behind the keyboard. I was timing the wrong functions...

I'm really happy to say that I now get around 30% faster total transfers, compared to my previous fastest version. This includes serialization, sending over the wire and deserialization. For my largest grids, timing is down from 3.6 to 2.6 seconds, and that has a very real impact on the UX.

I have not updated the .NET server side yet, so I suspect I will gain a few more percent there. Great work, thank you!

Zaid-Ajaj commented 2 years ago

Great stuff @kerams and sorry for the delay! Merged and published a new batch of packages 🚀