What about the first could be optimized out - just the size() accessor? 
Most List implementations have a size field (see 
http://code.google.com/p/google-web-toolkit/source/browse/trunk/user/super/com/google/gwt/emul/java/util/ArrayList.java?r=6609#77
 
for the actual ArrayList used in compiled GWT code) that will be accessed 
instead of running a method. But if the loop modifies the list, rechecking 
the actual size is important. Again, in the case of ArrayList, any change 
made to the size of the list will itself change that same field.

For the second: it depends. If the compiler detects that there is a 
subclass of the current presenter that overrides getView(), then it will 
need to leave that method in so that it can call the right version. But if 
there is only one possible implementation at that point (current class is 
final, only one real impl ever, or various type/method tightening 
optimizations that already occur as part of the compilation process), then 
yes, it will almost certainly compile out to this._view.doAction() (the 
'this' keyword is not implicit in JavaScript as it is in Java).

So the short answer is that it will probably do the sane thing. If it 
doesn't, it is either a more complex optimization than you think it is 
(for-each loop to for loop for example), or some specific Java semantics 
must be preserved (static initializers are a big one), or the compiler 
noticed something you forgot (another subclass of your Presenter that 
overrides getView()). I try compiling my app out in style PRETTY every few 
weeks/months and page through briefly to look for anything that surprises 
me, and it usually ends up that the surprises are what it *can* do than 
what it cannot.

On Friday, February 1, 2013 12:27:43 PM UTC-6, Joel Cairney wrote:
>
> Dear forum,
>
> I've searched as hard as I can, but I haven't found any information on 
> what specific developer practices GWTs compiler optimizations might 
> optimize out.  For instance:
>
> for(int i = 0; i < myList.size(); i++) {...}
>
> or in the presenter:
>
> getView().doAction();
>
> for every action, instead of:
>
> _view.doAction();
>
>
> Note that I'm not suggesting I plan to go through my code base and fix 
> these, so please, please spare me the discussion on whether premature 
> optimization is the root of all evil.  I would just like my curiousity 
> satisfied.  Does GWT compiler change these code imperfections?
>
> -Joel
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to