flagd icon indicating copy to clipboard operation
flagd copied to clipboard

[FEATURE] Improve evaluation performance

Open beeme1mr opened this issue 1 year ago • 8 comments

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.

beeme1mr avatar Nov 20 '24 21:11 beeme1mr

I'd like to work on this one @beeme1mr ! Could you please assign it to me?

aasifkhan7 avatar Dec 17 '24 05:12 aasifkhan7

@beeme1mr To confirm, should this change be made in the repository at https://github.com/diegoholiveira/jsonlogic?

aasifkhan7 avatar Dec 17 '24 11:12 aasifkhan7

@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

toddbaert avatar Dec 17 '24 16:12 toddbaert

@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 avatar Dec 17 '24 16:12 beeme1mr

@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?

aasifkhan7 avatar Dec 20 '24 10:12 aasifkhan7

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.

beeme1mr avatar Dec 20 '24 19:12 beeme1mr

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 avatar Jan 03 '25 04:01 aasifkhan7

@aasifkhan7 sure, let's give it a shot.

beeme1mr avatar Jan 03 '25 13:01 beeme1mr