Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: JRuby 1.1.6
-
Fix Version/s: JRuby 1.2
-
Component/s: Core Classes/Modules
-
Labels:None
-
Number of attachments :
Description
Based on really poor assumptions about garbage collection, the default (MRI) implementation of tempfile.rb is really bad in JRuby (and not so hot in MRI to tell the truth). Here is a simple run of bench/bench_tempfile.rb to show how well we do just creating tempfile objects:
ruby bench/bench_tempfile.rb 10k Tempfile.open(file) 0.460000 0.440000 0.900000 ( 0.940749) 0.460000 0.440000 0.900000 ( 0.950805) 0.470000 0.440000 0.910000 ( 0.941242) 0.460000 0.430000 0.890000 ( 0.922238) 0.470000 0.440000 0.910000 ( 0.931321) 0.460000 0.440000 0.900000 ( 0.921005) 0.460000 0.430000 0.890000 ( 0.924353) 0.470000 0.440000 0.910000 ( 0.938983) 0.460000 0.440000 0.900000 ( 0.931108) 0.480000 0.470000 0.950000 ( 1.027533) jr --server bench/bench_tempfile.rb 10k Tempfile.open(file) 9.422000 0.000000 9.422000 ( 9.421392) 54.812000 0.000000 54.812000 ( 54.812113) 157.798000 0.000000 157.798000 (157.798209) 329.697000 0.000000 329.697000 (329.697295) ...
The critical section which determines the next name to use in initialize does a linear walk through entire list of not yet cleaned or active list of temp file pathnames to try and determine a new one. In MRI this list in temp_benchmark levels out at about 73 and in JRuby it grows without bounds (JVM is cleaning up objects consistently, but the benchmark is easily able to outstrip the pace of cleanup).
It seems like rather than try and mangle jruby to work with a poorly though implementation we should just create our own taking advantage of the Java platform.
Fixed in commit 8804. This is a Java reimplementation of tempfile. Here is the final results: