31 messages in org.codehaus.groovy.devRe: [groovy-dev] as usual on performa...
FromSent OnAttachments
Alex TkachmanFeb 27, 2008 5:38 am 
Guillaume LaforgeFeb 27, 2008 5:47 am 
Alex TkachmanFeb 27, 2008 6:01 am 
Chanwit KaewkasiFeb 27, 2008 6:21 am 
Martin C. MartinFeb 27, 2008 6:27 am 
Jochen TheodorouFeb 27, 2008 6:32 am 
Jochen TheodorouFeb 27, 2008 6:33 am 
tugwilsonFeb 27, 2008 6:55 am 
Chanwit KaewkasiFeb 27, 2008 7:15 am 
Chanwit KaewkasiFeb 27, 2008 8:01 am 
Jochen TheodorouFeb 27, 2008 8:28 am 
tugwilsonFeb 27, 2008 9:00 am 
tugwilsonFeb 27, 2008 9:55 am 
Chanwit KaewkasiFeb 27, 2008 11:27 am 
Chanwit KaewkasiFeb 27, 2008 11:31 am 
Jochen TheodorouFeb 27, 2008 11:36 am 
Alex TkachmanFeb 27, 2008 11:58 am 
Martin C. MartinFeb 27, 2008 12:18 pm 
Jochen TheodorouFeb 27, 2008 12:37 pm 
Jochen TheodorouFeb 27, 2008 12:45 pm 
tugwilsonFeb 27, 2008 12:48 pm 
tugwilsonFeb 27, 2008 12:51 pm 
Martin C. MartinFeb 27, 2008 1:27 pm 
Alex TkachmanFeb 27, 2008 1:48 pm 
tugwilsonFeb 27, 2008 2:14 pm 
Jochen TheodorouFeb 27, 2008 5:09 pm 
Alexandru Popescu ☀Feb 27, 2008 5:38 pm 
Charles Oliver NutterFeb 28, 2008 12:20 am 
Jochen TheodorouFeb 28, 2008 1:33 am 
Alexandru Popescu ☀Feb 28, 2008 2:56 am 
tugwilsonFeb 28, 2008 3:29 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [groovy-dev] as usual on performance - operations on primitivesActions...
From:tugwilson (tu@wilson.co.uk)
Date:Feb 27, 2008 9:55:40 am
List:org.codehaus.groovy.dev

Jochen Theodorou wrote:

[snip]

For example,

def myMethod() { def b = 10 def a = b + 2 }

[snip]

this means you have either to change the code the method uses, or you have to generate code and plug that in here. But ignoring this.. The question could for example if we need a JIT here at all? we could also generate static code and add a check. Something like (pseudocode):

Object a,b; if (Integer#plus(Integer) is default) { int b' = 10 int a' = b'+2 b = new Integer(b') a = new Integer(a') } else { Class class1 = org.codehaus.groovy.trace.Demo.class; b = new Integer(10); a = ScriptBytecodeAdapter.invokeMethodN(class1, b, "plus", new Object[] { new Integer(2) }); }

If I wanted to JIT then I would probably try to inline the bytecode of the called method and eliminate unneeded boxing action and transformations. For example I could find, that the call is ultimatively only:

return new Integer(left.intValue() + right.intValue());

which means I could reduce the code to:

Class class1 = org.codehaus.groovy.trace.Demo.class; Object b = new Integer(10); Object a = new Integer(b.intValue()+new Integer(2).intValue())

and then:

int b' = 10; Object b = new Integer(b'); Object a = new Integer(b'+2);

which of course would be much faster, than what we currently have.But I am not sure there is a way for a JIT we write to get all these informations... like what method will be called in the end.. for 2.0I plan to let the MetaClass return the method it will call instead of calling the method directly. In that a case JIT would have an much more easy job here.

The Ng equivalent would be

Object b = tc.wrap(10) Object a = tc.add().apply(b, 2)

tc is an instance of the ThreadContext object which would be passes as a parameter to the method.

Because the Ng runtime system has a very rich API we don't have to wrap and unwrap the integer constant.

The main execution cost is fetching the MetaClass for b (Ng wraps ints in NgInt which has a getMetaClass method rather than Integer which requires a registry lookup), a check to see if a Category has changed the plus operation on int and a check that the plus operation on int has not been monkey patched. These costs are exactly equivalent to your "Integer#plus(Integer) is default" check, except the cost of getting the MetaClass for Integer is higher in Groovy.

Your approach above would seem to be on the right lines.

John Wilson

-- View this message in context:
http://www.nabble.com/as-usual-on-performance---operations-on-primitives-tp15713441p15718960.html Sent from the groovy - dev mailing list archive at Nabble.com.

--------------------------------------------------------------------- To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email