Re: Optimising Variable to reduce instantiation overhead
Alex Twisleton-Wykeham-Fiennes <[email protected]> Mon, 13 Mar 2006 13:28:15 +0000
| Newsgroups | gmane.comp.java.webmacro.user |
|---|---|
| Message-ID | <[email protected]> |
On Mon 13 March 2006 12:34, Endre Stølsvik wrote: > On Sun, 12 Mar 2006, Alex Twisleton-Wykeham-Fiennes wrote: > | All, > | > | more performance tweaks, this one to the org.webmacro.engine.Variable > | class. > > Excellent performance tuneup you're into, Alex! > > | - 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. > > So? If you don't synchronize then you could potentially have two threads modifying the state of the Object simultaneously. In this situation it is not the end of the world, because the generation of the result is a) not that expensive, and b) not dependent on other mutable properties, but I find it best to apply thread-safe approaches to everything that changes state and then remove them if profiling shows it to be a problem. Much better to start safe and then remove redundant safety when required than to start unsafe and try and make things safe when a weird multi-threading bug occurs... > Is it shared across threads? I'd have to double check this one. It's a bit of a twisty turny passage of Macro inheritance and it isn't necessarily obvious... Alex ps synchronizing is really not the overhead that it used to be in older JVMs and it *really* makes your life easier to not have any multi-threading bugs... ------------------------------------------------------- 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&kid0944&bid$1720&dat1642