jastrachan | 29 Mar 21:30 2004
Picon

Re: RE: [groovy-user] benchmarks

Thanks for more great analysis Brian!

I've just patched the bytecode generator so that we call 
GroovyObject.get/setProperty methods directly in the bytecode which 
speeds things up quite a bit.

On 20 Mar 2004, at 04:07, LARSON, BRIAN (SBCSI) wrote:
> Very good "wild guess". :)
> Below is the disassembled java code from the two scripts.
> Most of the time is being spent in MetaClass.setProperty().
>
> Commenting out the following line in that method, reduces
> the time from 15 seconds to less than 1 second:
>             //invokeMethod(object, method, new Object[] { newValue });
> It seems to just be calling set on the inner class closure.
> Why can't set() just be called directly via byte code?
>
> Of course, the most obvious performance enhancement would be to remove
> the x from the groovy source.  This results in the script running
> in 8.9 seconds instead of 15 seconds (for 100,000 iterations).
>
> ---inner closure class from test case version
> for(Iterator iterator =
> 	InvokerHelper.asIterator(
> 		InvokerHelper.createRange(new Integer(1), obj, true));
> 	iterator.hasNext();)
> {
>  Object obj2 = iterator.next();
>  Object obj3 =
> InvokerHelper.invokeNoArgumentsConstructorOf(java.lang.Object.class);
> }
>
> ---inner closer class from non-test case version
> for (Iterator iterator = InvokerHelper.asIterator(InvokerHelper
> 		.createRange(new Integer(1), obj, true));
> 		iterator.hasNext();
> 		InvokerHelper.setProperty2(InvokerHelper
> 	
> .invokeNoArgumentsConstructorOf(java.lang.Object.class),
> 			this, "x"))
> 	InvokerHelper.setProperty2(iterator.next(), this, "i");
>
> ---------------------------------
> Non-test case groovy source:
> { n |
>   for (i in 1..n){
>     x = new Object()
>   }
> }.call(100000)
>
> Thanks,
> Brian Larson
>
>
>> -----Original Message-----
>> From: Thomas Heller [mailto:th.heller@...]
>> LARSON, BRIAN (SBCSI) wrote:
>>> Do you know why it is so much slower to run this test using
>> GroovyShell than
>>> in a GroovyTestCase?
>>>
>>
>> Wild guess, but I think the GroovyTestCase compiles to a usual java
>> class where "x" of "x = new Object()" is on the stack just like every
>> other usual java variable (dunno how exactly that looks in
>> bytecode tho)
>>
>> However for Scripts that doesn't count because x will always
>> be resolved
>> via at minimum "binding.variables.get('x')/put("x", new Object())"
>> usually by my observation this involves at least a couple of
>> reflection/metaclass invocations. Thats definitly slower than pop'
>> something of the stack. Script files are true scripts while TestCases
>> are just normal bytecode as java classes are [with some added magic
>> reflection tho :]
>>
>> /thomas
>> _______________________________________________
>> groovy-dev mailing list
>> groovy-dev@...
>> http://lists.codehaus.org/mailman/listinfo/groovy-dev
>>
> _______________________________________________
> groovy-dev mailing list
> groovy-dev@...
> http://lists.codehaus.org/mailman/listinfo/groovy-dev
>
>

James
-------
http://radio.weblogs.com/0112098/

Gmane