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

Wolfgang Laun wolfgang.laun at gmail.com
Mon May 13 00:44:44 EDT 2013


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
>


More information about the rules-users mailing list