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
273 stars 55 forks source link

I don't really know what's going on... #171

Closed kerams closed 4 years ago

kerams commented 4 years ago

... but this incantation works and it's faaaaaaaaaaast. And it doesn't appear to allocate (disregarding output buffer resizing) during any of the serialization scenarios that are in the benchmark :O. TypeShape is fucking fantastic, you should check it out if you don't know it! I have a feeling it could be used in Remoting.Server to proxy requests to record functions in a generic way, replacing all the ugly DynamicRecord and AsyncBoxer boilerplate (with a tiny bit of a performance uplift I imagine).

Before: Type Method Job UnrollFactor Mean Error StdDev Median Gen 0 Gen 1 Gen 2 Allocated
Int64ArraySerialization Json DefaultJob 16 58.784 ms 0.4902 ms 0.4093 ms 58.751 ms 5000.0000 1000.0000 - 47.71 MB
Int64ArraySerialization MsgPack DefaultJob 16 11.663 ms 0.0909 ms 0.0806 ms 11.633 ms 359.3750 62.5000 62.5000 4.29 MB
IntMaybeMapSerialization Json DefaultJob 16 236.839 ms 0.5522 ms 0.4611 ms 236.891 ms 9000.0000 1000.0000 - 76.1 MB
IntMaybeMapSerialization MsgPack DefaultJob 16 5.771 ms 0.0694 ms 0.0649 ms 5.776 ms 609.3750 39.0625 7.8125 5.23 MB
RecursiveRecordSerialization Json DefaultJob 16 594.457 ms 11.5427 ms 11.3364 ms 591.723 ms 30000.0000 9000.0000 1000.0000 271.83 MB
RecursiveRecordSerialization MsgPack DefaultJob 16 107.279 ms 0.6508 ms 0.5769 ms 107.212 ms 6000.0000 - - 64.43 MB
After: Type Method Job UnrollFactor Mean Error StdDev Median Gen 0 Gen 1 Gen 2 Allocated
Int64ArraySerialization Json DefaultJob 16 57.073 ms 0.4752 ms 0.4212 ms 57.122 ms 5000.0000 1000.0000 - 50025496 B
Int64ArraySerialization MsgPack DefaultJob 16 4.010 ms 0.0596 ms 0.0558 ms 4.016 ms - - - 56 B
Int64ArraySerialization Manual DefaultJob 16 3.485 ms 0.0276 ms 0.0258 ms 3.485 ms - - - 136 B
IntMaybeMapSerialization Json DefaultJob 16 234.664 ms 0.6722 ms 0.5959 ms 234.765 ms 9000.0000 1000.0000 - 79804904 B
IntMaybeMapSerialization MsgPack DefaultJob 16 1.805 ms 0.0260 ms 0.0230 ms 1.804 ms - - - 40 B
IntMaybeMapSerialization Manual DefaultJob 16 1.520 ms 0.0034 ms 0.0030 ms 1.519 ms - - - 104 B
RecursiveRecordSerialization Json DefaultJob 16 566.153 ms 3.0543 ms 2.8570 ms 567.074 ms 29000.0000 8000.0000 - 285036144 B
RecursiveRecordSerialization MsgPack DefaultJob 16 66.278 ms 0.5185 ms 0.4850 ms 66.324 ms - - - -
RecursiveRecordSerialization Manual DefaultJob 16 46.976 ms 0.1122 ms 0.0937 ms 46.986 ms - - - 80 B
ArrayOfFloatArraySerialization Json DefaultJob 16 129.443 ms 5.1634 ms 15.2244 ms 123.031 ms 6000.0000 1000.0000 - 62297456 B
ArrayOfFloatArraySerialization MsgPack DefaultJob 16 8.873 ms 0.1736 ms 0.2066 ms 8.873 ms - - - -
ArrayOfFloatArraySerialization Manual DefaultJob 16 9.371 ms 0.0426 ms 0.0398 ms 9.372 ms - - - 80 B
SimpleRecordArraySerialization Json DefaultJob 16 72.185 ms 0.6621 ms 0.6193 ms 72.100 ms 4000.0000 1000.0000 - 38423792 B
SimpleRecordArraySerialization MsgPack DefaultJob 16 10.569 ms 0.0433 ms 0.0405 ms 10.562 ms - - - 56 B
SimpleRecordArraySerialization Manual DefaultJob 16 8.015 ms 0.0137 ms 0.0115 ms 8.018 ms - - - 136 B

I've also refactored the serialization API quite a bit in the process.

Zaid-Ajaj commented 4 years ago

I don't really know what's going on, but this incantation works and it's faaaaaaaaaaast

I don't either but I like what I am seeing (the insane numbers), I have seen TypeShape before but I haven't used it myself. Though the TypeInfo API in SimpleJson is somewhat inspired by how TypeShape looks like. Let's get this in and optimize Fable.Remoting.Server later :smile:

Zaid-Ajaj commented 4 years ago

Published all the goodness 🚀 🎉 Also I have sent you an invitation for collaboration, if you would accept that be really awesome :pray: (Also please let me know how I can send you nuget API keys so that you too can publish Fable.Remoting.* packages, that is if you want to of course :wink:)

kerams commented 4 years ago

I really appreciate the gesture, but I am content with the status quo. However, if you need a helping hand maintaining this repo, which would be understandable given how many projects you have and how pristine you seem to keep the issue and PR lists, then I'd be willing to step up. I'm on Fable's gitter, you could drop me a private message there.

Zaid-Ajaj commented 4 years ago

However, if you need a helping hand maintaining this repo

That was my intention with sending the invitation, having another maintainer would really really help me out, especially someone who is familiar with the codebase :wink: