[rules-users] Optimization Problem - fat expressions vs ceating additional objects

Arjun Dhar dhar_ar at yahoo.com
Wed Aug 15 04:52:24 EDT 2007


I have a rule:

SOLUTION 1
===========
when
	cntct: Contact(initialized==true)
	rel: Relation(contact==cntct, active:active == $1) 

	then
	…
end

For this to run, it requires the "Relation" object asserted into working memory;
so I'd have to forcefully assert (Relation object with active = false), even if
no relation exists.

An alternative solution is to write the rule like this:

SOLUTION 2
==========
when
	cntct: Contact(initialized==true)
	rel: Relation(contact==cntct, active:active == $1
	     or  (eval(false==false) and not relation())

	then
	…
end

#Note: The eval is for decision table since the same cell can be true or false,
and this part of condition should be active only when the cell = false.

Now, Soltuion 2 is a better way to represent the functionlaity and also saved
creation of addtional/redundant objects but introduces an eval() and a not.

>From a perfromance perspective, which solution is more optimized?
If it helps, imagine this used for millions of facts.

At a more granular level, does a Java New() cost more than an eval(false==false)
<-- trivial comparion, but uses the forbidden eval() and then a 'not'

please let me know your views!

Thanks,
Arjun






More information about the rules-users mailing list