Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for pre-decoded rules #88

Open
beeme1mr opened this issue Nov 20, 2024 · 2 comments
Open

Support for pre-decoded rules #88

beeme1mr opened this issue Nov 20, 2024 · 2 comments

Comments

@beeme1mr
Copy link

beeme1mr commented Nov 20, 2024

Hey @diegoholiveira, thanks for the great library. We're using it as part of our flag evaluation engine in flagd. I was wondering if we could add support for pre-decoding the rules so that it doesn't need to happen on every call to Apply. JSON Logic engine, a JavaScript version of Json Logic, supports this, and the performance benefits are impressive. This approach would work well for use because changes to feature flag configuration happen relatively infrequently, while evaluations can happen extremely frequently.

If you're open to the idea, someone from the flagd community or I can work on a PR. Thanks!

@diegoholiveira
Copy link
Owner

@beeme1mr I'm super open to this idea. It would be super good if you or anyone from flagd could do this change because at the moment I'm kind of unavailable but I'll be able to implement this next year case you don't mind waiting.

@eltonjr this may benefit your services at Mercado Libre.

@TotalTechGeek
Copy link

TotalTechGeek commented Dec 3, 2024

@beeme1mr 😅 Heya, just a small heads up, because y'all are using engine.run in an older version of JSON Logic Engine, you're actually not currently getting those performance benefits.

engine.run uses an interpreter; which allows folks with strict Content Security Policies to use the engine.

Relevant Issue w/ an Experiment: handlebars-lang/handlebars.js#1934 (comment)

However, in v2 of JSON Logic Engine (and y'all should be able to seamlessly upgrade to the latest, which is like 3.0.5 right now) I added a closure "compiler" to engine.run that uses a WeakMap against your logic to cache the execution plan & optimize performance.

So as long as the object isn't being changed out / cloned, it can optimize it. If y'all want to get the full performance benefits, y'all will need to switch to precompiling the logic with engine.build

Also: I need to update that darned website 😅; I've been on a performance kick and trying to trim the codebase a bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants