jwadhams / json-logic-js

Build complex rules, serialize them as JSON, and execute them in JavaScript
MIT License
1.27k stars 139 forks source link

JIT version #107

Open darky opened 3 years ago

darky commented 3 years ago

Hello @jwadhams! Thanks you very much for this awesome library! 🎸

I inspired and create JIT version of json-logic-js -> https://github.com/darky/json-logic-js-jit json-logic-js-jit precompile JSON schemas and then you deal with high performance JS functions 🚀

Maybe it's not silver bullet and can't be used in cases, when need "infinite" count of JSON rules, which are generated chaotically by a third party (althrough json-logic-js-jit can be used here as LRU cache). But for my project is ok, supposed ~100-200 predefined JSON rules.

Benchmark results on local machine 👇

Initial compile included in benchmark:

json-logic-js-jit x 174,811,960 ops/sec ±0.50% (93 runs sampled) // x163 faster
json-logic-js x 1,072,400 ops/sec ±0.55% (95 runs sampled)

Initial compile not included in benchmark:

json-logic-js-jit x 759,229,202 ops/sec ±1.45% (88 runs sampled) // x712 faster
json-logic-js x 1,064,846 ops/sec ±0.61% (96 runs sampled) 

@jwadhams, feel free to inspire and port JIT into json-logic-js too (I can deprecate json-logic-js-jit in this case). Also, you can specify json-logic-js-jit in documentation as JIT alternative (my appreciation in this case 🙌 )

fasiha commented 2 years ago

For completeness, here's another more heavyweight tool with a similar goal: https://github.com/TotalTechGeek/json-logic-engine