Knetic / govaluate

Arbitrary expression evaluation for golang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Marshal/Unmarshal functions for the `EvaluableExpression` struct

rigelrozanski opened this issue · comments

For more performant situations where large numbers of evaluable expressions are needing to processed, A large performance boost would be to allow for the EvaluationExpression type to be marshalled into bytes which could then be stored in a db and unmarshalled at a later point as opposed to having to be re-evaluated from the string at some later point.

Looking at some of the rough benchmarks evaluation nearly all take >10000 ns/op whereas protobuf marshalling/unmarshalling nearly all take <1000 ns/op (running on a "laptop" see https://medium.com/@akresling/go-benchmark-json-v-protobuf-4ec3c62ec8d4) -> that's an order of magnitude difference - worth some investigation

Unfortunately, marshalling of interfaces... as well as nested function variables with interfaces seems totally bananas to me and I actually have no idea how this would occur. Things like the ExpressionToken struct are not actually that big of a deal to work with - a new interface would need to be created for ExpressionToken (say ExpressionTokenI) which has its own marshal function... but because ExpressionToken.Value has a limited number of types, it would be simple to define a unique marshal function for them all... so that's not so bad, however I have no idea as to how a function variable could be marshalled... I think a fundemental restructuring of everything subordinate of the evaluationStage struct would need to take place... or maybe some clever strategy to marshal the bytes of a function variable based on its location in memory could take place - I'm really not sure.

Upon further reflection this is no small task, and settling for the string value of the formula is totally reasonable... But it would be a huge potential performance boost if this was somehow possible, so maybe its worth continuing to discuss here? - Just an idea!