Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Which compiler optimizes more?  RSS feed

 
Alex Teslin
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I would like to ask this question as i can not make my mind.

I have applied the simple optimization in the loop. ie taking out the method call of the collection in the loop and instead storing it in the variable before to the loop entry, thus using the variable to campare the size.

With dynamic compiler on:

with manually optimized: 17
with non-optimized: 75

With compiler Off:

with optimized: 345
with non-optim: 780

Now the difference when compiler is ON: over 4 times.
when compiler is OFF: just over 2 times faster.

It is obvious that dynamic compiler does not optimizes this nor static does.
But there is a difference in them. 4 times and 2 times.

Is this means that static compiler performance some optimization, which i doubt?

Any suggestions please?

Thank you
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What dynamic compiler are you talking about? How do you turn it on/off?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If those numbers are times measured in milliseconds, then I think there's a good chance the code has not really run long enough for dynamic compilation to have its full effect. I would recommend making these loops run ten or a hundred times as many times, if possible, to more accurately measure these effects. And I'd echo Ilja's question - exactly what command options are you using here?

[Alex]: It is obvious that dynamic compiler does not optimizes this nor static does.

I'm not sure I understand what you're saying. It's obvious that the times with dynamic compilation enabled are considerably faster than the times with it disabled, so it clearly does optimize the code. In this case it doesn't seem to optimize quite as well as you might want, but it's also clearly better than the results with no dynamic compilation. So I'm not sure what you're trying to say here. It looks like

    dynamic compilation plus hand optimization

is better than

    dynamic compilation, no hand optimization

which is better than

    hand optimization, no dynamic compilation

which is better than

    no dynamic compilation or optimization

It might also be helpful to see examples of the code, and what sort of manual optimization you have performed.
 
Alex Teslin
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By dynamic compiler i meant JIT compiler using -Xint flag to switch it off.

The code is trivial, just taking the collection.size() method out of the loop.
That's all.

So i am comparing
1) for(int i=0; i<collection.size(); i++)

with
2) int size = collection.size();
for(int i=0; i<size; i++)

Running both with JIT on,
code 2 performs faster 4 times than code 1.

Running both with -Xint
code 2 performs faster 2 times than code 1.

This is probably a trivial question but i just want to know why when is running with -Xint performs 2 times faster but with JIT on 4 times.

Thanks
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that what you've done is not an optimization any compiler is allowed to do; the compiler doesn't know that "size()" will return a constant.

What you've really shown is that method calls are relatively more expensive in JIT mode than in interpreted mode. That makes sense, right?
 
Alex Teslin
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is correct. Is there a simple explanation to that?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!