Page 1 of 1
Using app. within an Application class
Posted: Tue May 10, 2011 4:54 pm
by Stokes
I have found that if you use:
app.
Within an application class it slows it down unnecessarily. You don't need to have app. within an application class so if you have code using this delete it out for a speed improvement. I found a 30% gain by getting rid of it.
Hope this is useful for someone.
Re: Using app. within an Application class
Posted: Wed May 11, 2011 9:49 am
by JohnP
Yes, this can save some time. Of course the percentage saved depends on what you are doing. The same goes for any class - it pays to avoid a lot of unnecessary dereferencing.
A few years ago, my team found a 3% savings in the application overall by changing this.
One downside is when you copy lines of code around - you may have to add or subtract "app." when you copy a line.
Re: Using app. within an Application class
Posted: Fri May 27, 2011 10:04 am
by Callum
The same goes for any class - it pays to avoid a lot of unnecessary dereferencing.
Does calling
self.xxx cause unnecessary dereferencing?
Re: Using app. within an Application class
Posted: Fri May 27, 2011 10:20 am
by BeeJay
It depends on how many times you're referencing self.xxx in your method and whether or not self.xxx will ever change during the execution of that method.
For example, if self.xxx never changes during your method execution and you're dereferencing it multiple times, then it can be considerably more efficient to copy self.xxx into a local variable and use the local variable elsewhere in the method instead of self.xxx. This is especially the case if the dereferencing of self.xxx is inside a "large" while or foreach loop.
Cheers,
BeeJay.
Re: Using app. within an Application class
Posted: Tue Jun 14, 2011 9:02 am
by allistar
I would have liked to think that the JADE compiler or interpreter would have this efficiency built in.
Re: Using app. within an Application class
Posted: Wed Jun 15, 2011 4:12 pm
by JohnP
Using "self." does not cause unnecessary dereferencing, if that's what you were asking, Callum. For example, these two lines will have equivalent speed:
if myName = "Smith" then
if self.myName = "Smith" then
However, using "app." within an Application subclass does cause extra overhead. The last of these three lines will be more expensive than the first two (the method is on an Application subclass):
if myName = "Smith" then
if self.myName = "Smith" then
if app.myName = "Smith" then