Trie impl is slower on JRuby than other Rubies #426

Closed
headius opened this Issue Dec 4, 2012 · 5 comments

4 participants

@headius
JRuby Team member

The code, by @Sirupsen, is here: https://gist.github.com/7f2fa662a36638e717d8

We run it slower then either 1.9.3 or Rubinius, so something's broken:

system ~/projects/jruby $ ruby-1.9.3 trie.rb 
Trie it: 2.592618
Stress: 0.22932
Trie it: 1.102871
Stress: 0.231971
Trie it: 1.064968
Stress: 0.223817
Trie it: 1.049926
Stress: 0.409452
Trie it: 0.874368
Stress: 0.223402

system ~/projects/jruby $ ../rubinius/bin/rbx -X19 trie.rb 
Trie it: 18.016276
Stress: 0.26924500000000007
Trie it: 3.670808
Stress: 0.21206699999999998
Trie it: 2.890892
Stress: 0.21263200000000004
Trie it: 1.454035
Stress: 0.210246
Trie it: 2.12137
Stress: 0.21095700000000006

system ~/projects/jruby $ jruby trie.rb 
Trie it: 3.196
Stress: 0.997
Trie it: 2.422
Stress: 0.55
Trie it: 2.503
Stress: 0.493
Trie it: 2.513
Stress: 0.489
Trie it: 2.222
Stress: 0.501
@Sirupsen

Haha!

Charles, you might also want to check out the more stressing previous, naive implementation where the used letters are passed as arguments rather than set in a fixed instance variable to receive from during the recursion. JRuby has some strange behavior here, where it runs the first test slower than MRI and then for the next tests, it's much faster. Try running it a couple of times with different tests and different order of tests, and you'll see this in effect.

@nahi
JRuby Team member
@headius
JRuby Team member

each_char definitely shows up in a sampled profile, and I doubt we've optimized it much.

@headius
JRuby Team member

Grrr... something WAS broken: me.

It turns out the benchmark uses enough memory on JRuby that it hits our 500MB cap. As a result, it starts doing full GC runs, skewing results badly.

With 1000MB heap cap, we're easily the fastest:

system ~/projects/jruby $ jruby -J-Xmx1000m trie.rb 
Trie it: 2.573
Stress: 0.484
Trie it: 1.159
Stress: 0.117
Trie it: 1.071
Stress: 0.126
Trie it: 0.427
Stress: 0.158
Trie it: 0.464
Stress: 0.162

system ~/projects/jruby $ ruby-2.0.0 trie.rb 
Trie it: 2.334162
Stress: 0.173841
Trie it: 0.938182
Stress: 0.171032
Trie it: 0.844675
Stress: 0.324269
Trie it: 0.852679
Stress: 0.333097
Trie it: 0.663904
Stress: 0.323758

system ~/projects/jruby $ ruby-1.9.3 trie.rb 
Trie it: 2.603188
Stress: 0.223811
Trie it: 1.094034
Stress: 0.224787
Trie it: 1.045311
Stress: 0.21717
Trie it: 1.025384
Stress: 0.407294
Trie it: 0.884189
Stress: 0.218549

system ~/projects/jruby $ ../rubinius/bin/rbx -X19 trie.rb 
Trie it: 17.480193
Stress: 0.278873
Trie it: 2.855302
Stress: 0.200004
Trie it: 2.8492290000000002
Stress: 0.203145
Trie it: 2.118341
Stress: 0.20124
Trie it: 2.093159
Stress: 0.20088000000000006

I also ran the original more object and GC-heavy version. We're the fastest there too (by an even greater margin).

Long live JRuby!

@headius headius closed this Dec 5, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment