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

Batched propagation of linked facts #241

Closed
snikolayev opened this issue Oct 25, 2020 · 0 comments
Closed

Batched propagation of linked facts #241

snikolayev opened this issue Oct 25, 2020 · 0 comments
Assignees
Milestone

Comments

@snikolayev
Copy link
Member

There is a performance benefit of propagating facts through the rete graph in bulk. This is possible through the use of batch methods exposed by the ISession - InsertAll, UpdateAll, RetractAll.
However, when rules yield linked facts, they are propagated one by one, without any mechanism to achieve a similar performance benefit by batching fact propagation. Consider the following:

RuleA
    Match Fact1
    Yield Fact2

RuleB
    Match Fact2

It is possible to insert a 1000 instances of Fact1 in bulk, but RuleA will fire for each instance of Fact1 and will yield a new instance of Fact2. Those instances of Fact2 will get propagated through the rete graph one by one.

This feature will allow queuing of linked facts, instead of propagating them immediately, allowing the client application to initiate the propagation of queued linked facts in bulk.
By default NRules will continue to automatically propagate linked facts after the execution of each rule's actions, so there is no change in behavior for existing applications, unless they explicitly enable this feature.
For example:

session.AutoPropagateLinkedFacts = false; //Default is true
session.InsertAll(factsOfTypeFact1); //Fact1 facts propagate in bulk, and RuleA activates
session.Fire(); //RuleA fires
session.PropagateLinked(); //Linked facts Fact2 are propagated in bulk and RuleB activates
session.Fire(); //RuleB fires

Note:
Explicit insertion, update or retraction of facts through the session will also flush the linked facts queue and propagate those linked facts.

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

No branches or pull requests

1 participant