Re: Optimising Variable to reduce instantiation overhead

"Lane Sharman" <[email protected]> Sun, 12 Mar 2006 13:14:46 -0800 (PST)
Newsgroups gmane.comp.java.webmacro.user
Message-ID <[email protected]>
alex,

thanks for this improvement and catch. Are there any issues or concerns you have with this proposed update?

Lane

--- [email protected] wrote:

From: Alex Twisleton-Wykeham-Fiennes <[email protected]>
To: [email protected]
Subject: [WebMacro-user] Optimising Variable to reduce instantiation overhead
Date: Sun, 12 Mar 2006 18:50:17 +0000

All,

more performance tweaks, this one to the org.webmacro.engine.Variable class.

performance sampling showed a large proportion of CPU time being allocated to 
the makeName(Object[] names) class that is invoked in the constructor to 
create the human-readable version of the Object[] that stores the names, 
which is then stored in _vname.

However, _vname is only ever used in situations when you generating 
PropertyException Objects to provide sensible error messages, and for all 
"correctly functioning" instances, this is completely redundant.

What I've done is:-

- disabled the call to makeName(names) in the constructor
- made the getVariableName() method check to see if _vname has been 
initialised, and if not then build the name before returning it.  This is now 
synchronized as it changes the state of the object.
- made all previous references to _vname in the Variable class invoke 
getVariableName() rather than accessing the variable directly.
- made _vname private rather than protected thereby forcing sub-classes to 
access it via getVariableName() 

The resulting class (attached) passes all the unit tests and completely 
removes this overhead for all normal usage patterns.

Alex



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642