[stringtemplate-interest] it's 60% of time in ObjectModelAdaptor.getProperty()
Sam Harwell
sharwell at pixelminegames.com
Fri Feb 4 13:50:46 PST 2011
In the CLR, it's particularly expensive to invoke a method through
MethodInfo.Invoke or access a field through FieldInfo.GetValue. Most of the
cost is due to various security/permission/binding checks associated with
dynamic invocation. To save time, I dynamically generate stub methods and
call them through delegates. This way, the binding only occurs once per
method involved in the process. I don't have a large enough test available
for real-world ST4 testing, but I'm working on porting over one of my ST3
templates (produces several MB of output text). In ST3, GetProperty was less
than 5% of the inclusive rendering time, and I don't expect that to change
much for ST4. I'll let you know.
Sam
-----Original Message-----
From: Terence Parr [mailto:parrt at cs.usfca.edu]
Sent: Friday, February 04, 2011 2:44 PM
To: stringtemplate-interest List
Cc: Sam Harwell
Subject: it's 60% of time in ObjectModelAdaptor.getProperty()
and NOT the part that does reflection lookup.
public Object getProperty(ST self, Object o, Object property, String
propertyName)
throws STNoSuchPropertyException
{
Object value = null;
Class c = o.getClass();
if ( property==null ) {
return throwNoSuchProperty(c.getName() + "." +
propertyName);
}
// Look in cache for Member first
Member member = classAndPropertyToMemberCache.get(c,
propertyName);
if ( member!=null ) {
try {
if ( member.getClass() == Method.class )
return ((Method)member).invoke(o);
if ( member.getClass() == Field.class )
return ((Field)member).get(o);
}
catch (Exception e) {
throwNoSuchProperty(c.getName() + "." +
propertyName);
}
}
return lookupMethod(o, propertyName, value, c);
}
lookupMethod doesn't even show up of course. The double hashmap
classAndPropertyToMemberCache could be an issue but it calls this method A
LOT. can't see how to remove w/o static types. any ideas?
Ter=
More information about the stringtemplate-interest
mailing list