Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Interesting server vs client vm result  RSS feed

 
Cormac Blackwell
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A little while ago Larry Osterman (http://blogs.msdn.com/larryosterman/) wrote a post about optimisation tricks for counting the number of set bits in an int. I decided to try a few just out of curiosity of what java would do. the first one was the naive implementation:


This takes about 11 secs for 500,000,000 runs.

The most interesting result was with a lookup table based solution


This seemed to be horribly slow; around 34 secs for the same number of iterations.
But then I tried using the server VM. With that one the first 500,000,000 took around 12ms and from then on 0ms for the same number!!
So the client VM in this case is over 24,000 times slower!!!

Anyone have any idea what is going on?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The server VM is much more aggressive with inlining method calls, as far as I know.

Can you show us the loop you used?
 
Cormac Blackwell
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It was pretty simple



I had this inside an infinite loop so I could see any effects of jit compilation. Maybe the server VM is figuring out the results are always the same.
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...and never used.
Perhaps it optimized the calls away.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stefan Wagner:
...and never used.
Perhaps it optimized the calls away.


That sounds more reasonable - recognizing that a method has no side effect sounds still like a little bit of magic, but not as much magic as recognizing that its result is constant for a specific call (in fact, the former is a necessary condition for the latter)...
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!