Details
-
Type:
Improvement
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: JRuby 1.3.1, JRuby 1.4
-
Fix Version/s: JRuby 1.4
-
Component/s: Performance
-
Labels:None
-
Environment:MacOSX 10.5.8
java version "1.6.0_13"
Java(TM) SE Runtime Environment (build 1.6.0_13-b03-211)
Java HotSpot(TM) 64-Bit Server VM (build 11.3-b02-83, mixed mode)
-
Testcase included:yes
-
Number of attachments :
Description
On both jRuby 1.3.1 and jRuby 1.4 (edge), I found that converting Java Lists to Ruby Array actually performs worse than converting the Java List to a Java Array to a Ruby Array. Performance of the 2-step conversion is up to 50% faster.
Here are the results
$ jruby -v
jruby 1.4.0dev (ruby 1.8.7p174) (2009-08-23 6f772bf) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_13) [x86_64-java]
$ jruby --server ./bench.rb
Rehearsal -----------------------------------------------------
list.to_a 2.996000 0.000000 2.996000 ( 2.841000)
list.toArray.to_a 1.821000 0.000000 1.821000 ( 1.821000)
array.to_a 0.772000 0.000000 0.772000 ( 0.772000)
-------------------------------------------- total: 5.589000sec
user system total real
list.to_a 1.875000 0.000000 1.875000 ( 1.875000)
list.toArray.to_a 0.916000 0.000000 0.916000 ( 0.916000)
array.to_a 0.760000 0.000000 0.760000 ( 0.760000)
Knowing this was really helpful in getting my Google App Engine application to stop hitting the request time limit when loading arrays from the Datastore
Thanks for the find and the suggestion. I committed a fix in c915adf, please have a look.