[FEATURE] Improve evaluation performance
Overview
The flag evaluation engine in flagd leverages JsonLogic to provide a powerful and flexible rule-based serializable logic. The flagd binary and in-process Go flagd provider use this library. To improve flag evaluation performance and reduce computational overhead, the ruleset should be pre-decoded when a flag set is loaded (or updated). This removes the need to parse the JsonLogic structure for each evaluation.
### Tasks
- [ ] [Add support for pre-decoded rules in the Go JsonLogic SDK](https://github.com/diegoholiveira/jsonlogic/issues/88).
- [ ] Update flagd to use the pre-decoded rules.
- [ ] 🥇 Bonus points for running a performance test to measure the improvements
This should be a non-breaking change in the Go JsonLogic SDK.
I'd like to work on this one @beeme1mr ! Could you please assign it to me?
@beeme1mr To confirm, should this change be made in the repository at https://github.com/diegoholiveira/jsonlogic?
@beeme1mr To confirm, should this change be made in the repository at https://github.com/diegoholiveira/jsonlogic?
No, what @beeme1mr was getting at is that we parse and compile the JSON rules every time we evaluate (here). We can instead only do this when the rules are first retrieved.
@beeme1mr please correct if I'm wrong
Assigning you, @aasifkhan7
@aasifkhan7 is correct that the JSON Logic implementation in Go must be updated to support this feature first. Once that's in place, we need to update flagd to leverage it.
@beeme1mr @toddbaert Should it be the responsibility of the jsonlogic library to cache and store the decoded rule for subsequent evaluations? Or should the responsibility for caching and storing the decoded rule lie with the third-party application, such as flagd?
What are your thoughts on the best approach for handling this?
Hey @aasifkhan7, I propose that the JSON Logic library support a built step similar to what you see here. This would allow you to "hydrate" the JSON Logic engine during initiation instead of at evaluation time.
Hey @beeme1mr, based on this comment, it seems we’re expected to handle caching of all predecoded rules on our side. Does that approach work for you?
@aasifkhan7 sure, let's give it a shot.