• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Interesting server vs client vm result

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...and never used.
Perhaps it optimized the calls away.
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)...
 
We don't have time to be charming! Quick, read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic