Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trie impl is slower on JRuby than other Rubies #426

headius opened this Issue Dec 4, 2012 · 5 comments


None yet
4 participants
Copy link

headius commented Dec 4, 2012

The code, by @sirupsen, is here:

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

This comment has been minimized.

Copy link

sirupsen commented Dec 4, 2012


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.


This comment has been minimized.

Copy link

nahi commented Dec 5, 2012

Wild guess: each_char?


This comment has been minimized.

Copy link
Member Author

headius commented Dec 5, 2012

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


This comment has been minimized.

Copy link
Member Author

headius commented Dec 5, 2012

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


This comment has been minimized.

Copy link

inossidabile commented Dec 5, 2012


eregon added a commit that referenced this issue Apr 28, 2017

Squashed 'spec/ruby/' changes from 2e2057a..0db663b
0db663b Fixed Math.log2 for huge Bignums.
bc52723 Added {Bignum, Fixnum}.bit_length.
aad92e8 Numeric timezone may not be bad
1eb3d2f Add specs for rb_define_module
8e8b5fd Fix SHELL env var passing
f7ec5b7 Hide $IGNORECASE warnings
344bd8d Use ruby_exe to reliably spawn a subprocess
946abd5 Remove spec which only works before MRI 2.4.0
e6665ae Add a spec for syntax errors in the script file and -e
497931b Add new method spec with mixed parameter types.
4042b46 Add large number example to String#% binary number format
61acec4 Add String#% %p example with string argument
9a8fd6d Add library specs for the English module
ed5046a Updated incomplete String#encoding spec.
279d4e0 Add instance_variable_defined? example testing various types where variable is not defined
b89895d Fix typo in spec description
4fefa64 Specs for true and false values being truthy and falsey in C
1d8bcf0 Add another Time#zone bad zone example
6af9b04 Add Module#alias_method spec to assert that aliased methods are == to eachother
b2c2eeb Add Kernel#eval negative line number spec
5c0bd7b Add BasicObject#instance_eval example with negative line number
26d35a1 Spec that a splatted Array received in a rest argument is copied
4a8d694 Only use literal values in the expected value
4af8050 Add splat example where splatted array is modified by another argument
1274e6a Add spec to update backtrace array in place
11db149 It starts to look like something to unescape but it ends prematurely.  Do not expand (nor crash)
c9e7f56 Allow .jar as extension of provided features
c1f379e Reduce sleep time in Process.daemon specs
24282dc Method#curry_spec: Be more explicit with simpler syntax
ec31710 Move methods used only once closer to their usage
1f537ff Move fixture closer to its only usage
ca345d3 Revert "Kerenel#warn no longer splats an array in 2.5 (#382)" (#429)
7beafc0 Handle warnings in MOdule#attr spec
b79cf54 Concurrent requires show erroneous circular warnings
acb27a7 Expect warnings for circular require
c3256dc Fix commented warning net/http specs
897e9b4 No need to save/restore $VERBOSE when using the complain matcher
416ab81 2.5 no longer rescue exceptions of Integer#step to rethrow them as TypeError
f125a5d Numeric comparison operators no longer rescue exceptions
14bd5a4 Fix a few issues detected with $VERBOSE = true warnings
b53aa1b internal methods are not specs
7190a66 Remove duplicate specs
4753368 Fix some variables which were not availble for specdocs
bd885a6 Fix version-dependent warnings
26d13c0 Use the argv helper in getoptlong specs
3ba4551 Fix warnings in IO spec
a799f55 Remove continuation specs, continuation is obsolete since 2.2
328c7d8 Fix all warnings
8a491a9 Fix warnings in C-API specs
6227caa Fix remaining warnings in language specs
729a0ec Fix a few warnings in language
ee5b6a0 fix warning
863c8ac Expect circular argument warnings
eeef0e7 Fix class variable warnings in langauge specs
ccaf342 Fix remaining warnings in core
388adda Fix Kernel#=== spec
1ac4d2a Expect warnings from top-level class vars
f327217 Add expectations for argument + block warnings
1a42389 Add expectations for Ignoring encoding parameter warnings
dc2fd40 Fix a few more constant redefined warnings
4756e8d Avoid 2 already initialized constant warnings
faaf5ab Use local variables instead of constants in define_method spec
8341bb2 Catch warning in deprecate_constant spec
3940632 Remove unused constant
4280c78 Use Dir.chdir directly instead of relying on ruby_exe
4b9a0f3 Wrap a few warnings as complain matchers
50357ca Replace deprecated with obj.to_enum
b416c79 Remove deprecated usage of $KCODE in specs
b37650b Inline MSpec helper used only twice in the same file
579055b Avoid be_computed_by_function
8fea4ed Simply perform the action over using weird MSpec helpers
735ee77 Unshare Process#spawn and Process#exec specs
0a56f79 Avoid running #exec-related specs 3 times
5ca04db Avoid running #spawn-related specs 3 times
fd91fee Use the full bug version Range as AppVeyor uses an older 2.3.3 Ruby
7b0bf1a Reintroduce bug guard as 2.4.1 is not available on Travis OS X yet
7bbadd1 Update versions
5bb0536 The bug has been fixed in all latest 2.x releases
8ca440d Add spec for identity of String literals in a compare_by_identity Hash
c6704df Opal strings are always frozen, avoid dup & clone
556a6db Also exclude AIX from log specs as it was before
9266dc7 Exclude Solaris from Syslog specs as it was before
fead51e Fix platform guard
44c0278 Simplify platform_is os: VALUE to just platform_is VALUE as they are the same now
5a17f65 platform guard requires OS name list, not an array
cd7e2f7 Fix platform guard in Float#round spec
c698d12 Merge pull request #426 from ruby/removed-deprecated-mathn
49cdead Ignored mathn examples
27080f0 Move TTY checks inside the example
c766f34 Remove unneeded guard
bc9272e Remove the last not_supported_on :jruby
f119ab6 Remove not_supported_on which can be replaced by tags
1f72098 Remove unneeded not_supported_on guard
f73cc7e Remove bad not_supported_on guards
ab97f67 Remove bad not_supported_on guards
f5764a5 Fix references to removed guards and use generic text instead
7279501 Remove unused require
f1e34eb Remove useless requires to mspec helpers already loaded
39a43e9 Remove useless require
47d5757 Inline the single usage of the home_directory helper
c8bb8f0 Remove useless before/after in Dir.home spec
9d8e406 Simplify expectation as it only tests on non-Windows
1bdfcd5 Use Dir.home in File.expand_path spec
6b1764b Just use `hostname` to get the hostname
ce16689 Use standard File::NULL over mspec helper
196d2bf Remove process_is_foreground guards
a22149f Merge pull request #425 from ruby/ignored-deprecated-extensions
5397086 Ignored mathn/{complex,rational} examples. These are deprecated from Ruby 2.5
520200a Revert "Avoid using #fork in Process#wait specs"
6fe19cb Add specs for Hash#dig with default
a12d209 Require date (#423)
cdbc5f0 String#crypt with NUL (#420)
aee1fad Merge branch 'nobu-bug/psych-update'
6357533 Picked YAML.load_stream example from #418
83bbd45 Merge pull request #417 from hsbt/fixed-spec-fail-for-psych
1a952f5 Follow psych-3.0.0.beta1
18efd61 Ignored deprecated methods of psych-3.0.0.beta1 with Ruby 2.5.0
a488ce5 TypedData_Get_Struct unwraps data for a parent type
4bbfa0c Refactor httpgenericrequest/exec_spec to use an actual Net::BufferedIO
72273d3 Remove old guards testing for Ruby < 2.2
1a28138 Remove old 2.1 or < 2.2 guards in C-API specs
e4763d5 Remove Logger::Application specs which no longer exist in Ruby 2.2+
60ccbba Drop support for Ruby 2.1
6686326 An invalid timezone has a non-zero offset on AIX
96ba5d5 Add 2.2 guard for Etc.nprocessors, 2.1 is not yet removed from CI
3b8d553 Add spec for Etc.nprocessors
8fd7a69 Remove files with no specs
2829346 rb_ary_store raises an error if array is frozen
e1fb7b4 Fix typo
42c1320 Add a spec for rb_ary_new_from_values
9ba7adb Add specs for rb_ary_new_capa
825c0a0 Add a spec for rb_struct_members
89f4e62 Use have_constant matcher rather than #const_defined?
320b4fb remove #sort since Struct.members guarantees the order
ca6957b Add specs for rb_struct_define_under
5b0d3f8 Fix typo in spec method being tested
cb1b38e rb_struct_aset raises an error if struct is frozen
cab4987 rb_struct_aset raises an error if index is out of range
64f8bcc rb_struct_aref raises an error if index is out of range
e4db1d3 Add specs for rb_struct_define
af5412d Add specs for rb_struct_s_members
ecc868d Update to 2.3.4
4207e0e Symbol#hash was fixed in 2.3.4
d6ade33 Fix inaccurate description of a spec in string_times
4aed560 Revert "Use fixnum_max+1 to mean "not fitting into a Fixnum""
a4e6958 Use fixnum_max+1 to mean "not fitting into a Fixnum"
a5e707a Use fixnum_max helper
582eed5 Share tests between String#* and rb_str_times
fa4e6b2 Add specs for rb_str_times
9c73e8b Specs for three initial vulnerabilities
25aa763 Add a spec for rb_String (#395)
0adc519 Add specs for rb_ary_rotate
03e3fba Add specs for rb_ary_cat
9078f37 Add a spec for rb_Hash
7847fa8 Update ruby_bug guards

git-subtree-dir: spec/ruby
git-subtree-split: 0db663be26db58348eb1cf2b2c4af6a2eca005f4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.