[rules-users] Room to optimize or bug? Unnecessary calls to unused method

Davide Sottara dsotty at gmail.com
Mon May 13 01:14:30 EDT 2013


@Sonata,
I almost had a fit when I read your email, but I tried to reproduce your
bug using 5.6.x
and I didn't experience multiple getter calls. However, I didn't try
eclipse.. I wonder if
the environment is set up correctly...

@Wolfgang: "Declarations" in drools are not variables in the sense that
they "store" the
value extracted from the bean, but they use internal accessors to read
it from the bean
itself. So, in your example, two calls are expected: one when the value
is read for the != null
comparison, one when the value is displayed in the RHS.

I'm not sure that this optimization would be easy or even feasible,
especially considering that
the performance "penalty" would hardly be noticeable. Unless one has
stateful getters (ouch..),
getter with side effects (ugh..) or getters that do expensive internal
computations on the fly (argh..).

Davide




On 05/12/2013 09:44 PM, Wolfgang Laun wrote:
> OP states that
>    rule test1
>    when
>         $m: Message( myMessage : message != null )
>    then
>    end
> with
>     public String getMessage(){
>         System.out.println("Called getMessage()");
>         return message;
>     }
> displays "Called getMessage()" more than once, which (using 5.5.0) I
> cannot confirm. However
>    rule test2
>    when
>         $m: Message( myMessage : message != null )
>    then
> 	System.out.println( "test2: " );
>   	System.out.println( "message(1): " + myMessage );
>    end
> produces
>   Called getMessage()
>   inserted
>   Called getMessage()
>   test2:
>   message(1): Hello
> which confirms OP's claim that there are redundant calls to getters.
>
> -W
>
>
> On 12/05/2013, Mark Proctor <mproctor at codehaus.org> wrote:
>> The code examples of what you are proposing did not make it to the list.
>>
>> Mark
>> On 12 May 2013, at 12:29, Sonata <plz.write.to at gmail.com> wrote:
>>
>>> Hi, I am using 5.5.0.final on jdk7(64bit). To repeat the test, simply
>>> create
>>> a new Drools project in Eclipse. Tick the option to create a default
>>> Hello
>>> World project. Go to the DroolsTest.java file, edit main() to
>>>
>>>
>>> and edit getMessage() to
>>>
>>>
>>> Next, remove the two rules in Sample.drl, use this simple rule instead
>>>
>>>
>>> Then you can see the output
>>>
>>>
>>> Which means, getMessage() is called 4 times in this simple rule. I really
>>> wonder why. Is this a bug? Some non-optimized routine? An edge case?
>>>
>>> Now try this
>>>
>>> and the output is
>>>
>>>
>>> Just once. It seems all good. Because getMessage() is needed to call once
>>> to
>>> check with null, which is very fair to me.
>>>
>>> Now something really funny
>>>
>>>
>>> and the output
>>>
>>>
>>>
>>> An extra call to getMessage() at the end, total 5 times!
>>>
>>> TBH, I really only expect calling getMessage() once in all these tests.
>>> Please put it to my face and tell me my test is so flawed.
>>>
>>>
>>>
>>> --
>>> View this message in context:
>>> http://drools.46999.n3.nabble.com/Room-to-optimize-or-bug-Unnecessary-calls-to-unused-method-tp4023790.html
>>> Sent from the Drools: User forum mailing list archive at Nabble.com.
>>> _______________________________________________
>>> rules-users mailing list
>>> rules-users at lists.jboss.org
>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>



More information about the rules-users mailing list