fasteval icon indicating copy to clipboard operation
fasteval copied to clipboard

Serialize compiled instructions with serde

Open adamsky opened this issue 4 years ago • 4 comments

For some use cases it may be useful to be able to serialize and deserialize compiled Instructions, along with Slabs. Perhaps this could become an optional feature?

adamsky avatar Sep 23 '20 20:09 adamsky

I've actually had a test case where I wanted to send already compiled instructions over the network and ended up implementing this, pulling in serde and placing a few derives here and there. It's not much but worked fine for me.

adamsky avatar Sep 23 '20 20:09 adamsky

Hmm, that's really interesting. I guess I assumed that it would be more performant to just save/transfer the original String expression, and then re-parse it on the other side. As you have already figured out, the instructions are tied to the slab, and it takes quite a bit of memory copies and I/O to serialize all those things and save them to a file or send them across a network. Sending the expression string would be way easier, and fasteval parsing is so fast, I had assumed that for most use cases, it would be the right choice.

I'll definitely think about this more, and I'll run some tests. If it's really more performant to serialize compiled expressions, I can definitely support that. Your code will be a great foundation. Thanks!

likebike avatar Sep 23 '20 21:09 likebike

From what I've seen in terms of performance, doing some very preliminary benchmarks, deserializing a compiled Instruction + Slab on the receiver side appears to be faster. Of course this largely depends on the format, and so with bincode it's faster, but using something more compact like msgpack ends up being slower. It also varies based on the actual content of the expression, with compiled serialization taking advantage of expression simplification and whatnot. I guess I'll need to investigate this more.

adamsky avatar Sep 24 '20 20:09 adamsky

Of course by saying it's faster I only mean the receiver side, not the combined sender and receiver. Main idea here being that a sender only has to serialize once, which can maybe save some processing time spend by the whole system if there were more than 1 receivers.

adamsky avatar Sep 24 '20 20:09 adamsky