Fork me on GitHub
#clara
<
2022-02-28
>
Shriyans12:02:20

Maybe not an appropriate question here i really like clara rules and would love to use it in scala has anyone tried it in scala or even just through java ?

mikerod13:02:49

It should work through the java API. I've heard of people using that before

PB17:02:09

Does the ordering of constraints matter much when it comes to performance of rules?

mikerod17:02:02

@petr I think abstractly, not really. However, there are ways to write rules that perform better by reducing the set of facts needed to be tested for matches.

mikerod17:02:13

So you can logically organize rules and constraints in more performant ways.

mikerod18:02:33

Hypothetical example demo. @petr

ethanc18:02:03

I will add on to what Mike said, there are scenarios where it can be advantageous to order constraints in an order that is consistent with the performance of the check. Example:

(defrule a-rule 
 [Fact 
  (a-quick-check) 
 (a-slow-check)]
 => 
 (<do things here>))
Due to the implementation of clara, “In most cases, those not being joined to other facts”, most constraints are simply “plopped” into an if block. So, in short… i guess i would recommend ordering constraints similar to how you would if you are writing an explicit if yourself… That being, if you know one check is “cheaper” put it first in an attempt to short circuit the following logic. That all being said… i might just be being pedantic with the terminology of Condition vs. Constraint. edit: or -> if

mikerod18:02:34

I was too loose with terminology.

mikerod18:02:10

I think “Condition” is better to refer to [Fact <constraints>] Where then, “Constraint”s refer to the filter within the “Condition”.

mikerod18:02:59

Also, you can note that = checks in constraints that facilitate “joins” between multiple Conditions, are specially optimized by the compiler.

PB18:02:21

Wonderful - thank you guys so much