Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: JRuby 1.6.3
-
Fix Version/s: JRuby 1.6.4
-
Component/s: Ruby 1.9.2
-
Labels:None
-
Number of attachments :
Description
In 1.9 mode Enumerator.new spins up a new Generator instance along with a thread...
I discovered this bug when evaluating lazy list options in Ruby. The `Denumerable` class from the facets gem provided an option so I was benchmarking the performance of it. Here are the benchmarks revlaling how slow 1.9 mode is in dealing with Enumerator.new and Enumerator#next: https://gist.github.com/1145736
In 1.8 mode JRuby performs well since it is using the monkeypatched version of Enumerator that facets provides: https://github.com/rubyworks/facets/blob/master/lib/core/facets/enumerator.rb#L37-44
See the IRC log discussion with headius and mabes: http://logs.jruby.org/jruby/2011-08-15.html#T18-44-37
The problem here was that the Enumerator.new { } form automatically created a Generator to pump the block. Our Generator by default uses a Thread to pump the block it has been given, and so performance took a hit.
I have a patch locally that appears to fix the problem; essentially, it introduces the "Yielder" class we were missing and uses that for Generator#each rather than the "next" logic which requires a native thread. So far it's passing specs, so it might get into 1.6.4.