Code Monkey home page Code Monkey logo

Comments (9)

mjaniko avatar mjaniko commented on May 28, 2024

@jyothis-qb Any solution for speeding up Performance ?

from json-rules-engine.

chris-pardy avatar chris-pardy commented on May 28, 2024

@mjaniko @jyothis-qb I would need to see the actual rules to get a sense for exactly the cause. However I can say that if you're using JSON path expressions to turn an array of 80,000 objects into an array of 80,000 values then it's going to be slow.

Generally you may be better off trying to flatten/ normalize the data so there are no path expressions to evaluate.

from json-rules-engine.

JeffrinCh avatar JeffrinCh commented on May 28, 2024

I'm also facing the same issue but mine is a simple object, but array of object is huge. but the object itself doesn't have a nested path.

was there any resolution on this?

from json-rules-engine.

chris-pardy avatar chris-pardy commented on May 28, 2024

@JeffrinCh Again I would need to see a specific example to understand exactly but if you're using the path attribute you're going to experience some drop in performance as the results of the facts after applying the path transformation are not cached. @CacheControl there may be an opportunity to do some caching of the job path I can look into.
@JeffrinCh for now one option would be to create dynamic facts instead of using paths. These would benefit from caching and remove the need to parse JSON path expressions.

from json-rules-engine.

chris-pardy avatar chris-pardy commented on May 28, 2024

@jyothis-qb @JeffrinCh I did some digging and here's my suggestions:
Screenshot 2023-10-12 at 10 03 35 AM
This shows a comparison of runtime across 10,000 executions of calling Almanac.factValue on a fresh Almanac instance so no caching is enabled.
The big take-away is that if you involve the path parameter it will cause a slowdown, that will add up.

In order to speed up your access you could create dynamic facts:

engine.addFact(
  new Fact('factCol1', async (_, almanac) => {
      const f = await almanac.factValue('fact');
      return f.col1;
  });
)

If you're doing lots of path access you could simplify this by creating single facts and using parameters

engine.addFact(
   new Fact('factCol', async ({ col }, almanac => {
     const f = await almanac.factValue('fact');
     return f[`col${col}`];
  })
);

// access your fact with
{
   "fact": "factCol",
   "params": { col: 1 }
   ...
}

This provides a slightly improved performance over using the path value but not quite the same performance benefit of having a specific dynamic fact.

from json-rules-engine.

CacheControl avatar CacheControl commented on May 28, 2024

json-path requires a decent amount of overhead; it's a relatively complex spec. I'm not surprised that using the path feature on a large number of items is causing significant impact.

Its my belief that the underlying json-path library we use (jsonpath-plus) is well optimized for performance, however if there is a performance improvement to be made, it will reside in that library.

I agree with the workaround above of using dynamic facts in place of json-path.

from json-rules-engine.

chris-pardy avatar chris-pardy commented on May 28, 2024

@CacheControl I also did some digging / profiling of jsonpath-plus and it does seem to be very very optimized. It already caches the results of compiling a path into a function so repeated uses of the same path will not cause re-compilation. The performance is so optimized that even without the caching the behavior is only slightly abnormal.

Suggesting this could probably be closed with Dynamic Facts being the solution.

from json-rules-engine.

JeffrinCh avatar JeffrinCh commented on May 28, 2024

@CacheControl I also did some digging / profiling of jsonpath-plus and it does seem to be very very optimized. It already caches the results of compiling a path into a function so repeated uses of the same path will not cause re-compilation. The performance is so optimized that even without the caching the behavior is only slightly abnormal.

Suggesting this could probably be closed with Dynamic Facts being the solution.

Will try these and check

from json-rules-engine.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.