Skip to content

Instantly share code, notes, and snippets.

@bbrowning
Created December 7, 2012 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbrowning/15d8f04c1dbf06528867 to your computer and use it in GitHub Desktop.
Save bbrowning/15d8f04c1dbf06528867 to your computer and use it in GitHub Desktop.
JRuby in 1.9 mode does way too much work every time I require a
file that's previously been required. Here's the output of a
simple script to test this - the first argument is the number of
times to require the same file and the second argument is the
number of entries we put on the load path before requiring that
file.
Current JRuby master:
bbrowning@bbrowning-mbp:~/src/jruby(master)$ bin/jruby ~/tmp/duplicate_requires.rb 1000 1
1.740000 0.080000 1.820000 ( 0.614000)
bbrowning@bbrowning-mbp:~/src/jruby(master)$ bin/jruby ~/tmp/duplicate_requires.rb 1000 10
3.220000 0.230000 3.450000 ( 1.159000)
bbrowning@bbrowning-mbp:~/src/jruby(master)$ bin/jruby ~/tmp/duplicate_requires.rb 1000 100
4.090000 0.680000 4.770000 ( 2.171000)
bbrowning@bbrowning-mbp:~/src/jruby(master)$ bin/jruby ~/tmp/duplicate_requires.rb 1000 1000
11.390000 5.860000 17.250000 ( 13.474000)
JRuby master with a one-line patch included below:
bbrowning@bbrowning-mbp:~/src/jruby(master)$ bin/jruby ~/tmp/duplicate_requires.rb 1000 1
0.550000 0.020000 0.570000 ( 0.194000)
bbrowning@bbrowning-mbp:~/src/jruby(master)$ bin/jruby ~/tmp/duplicate_requires.rb 1000 10
0.500000 0.020000 0.520000 ( 0.160000)
bbrowning@bbrowning-mbp:~/src/jruby(master)$ bin/jruby ~/tmp/duplicate_requires.rb 1000 100
0.510000 0.020000 0.530000 ( 0.172000)
bbrowning@bbrowning-mbp:~/src/jruby(master)$ bin/jruby ~/tmp/duplicate_requires.rb 1000 1000
1.150000 0.040000 1.190000 ( 0.392000)
So, with a load path size of 100 entries (not uncommon for Rails
apps using Bundler), it takes 3.58 seconds longer to require the
same thing 1000 times. That's 3.58 milliseconds of extra time per
require statement.
require 'benchmark'
iterations = ARGV[0].to_i
load_path_size = ARGV[1].to_i
load_path_size.times do |i|
$:.unshift "/tmp/foo#{i}"
end
puts Benchmark.measure {
iterations.times do
require 'erb'
end
}
diff --git a/src/org/jruby/runtime/load/LoadService.java b/src/org/jruby/runtime/load/LoadService.java
index 5f9645b..0d11a54 100644
--- a/src/org/jruby/runtime/load/LoadService.java
+++ b/src/org/jruby/runtime/load/LoadService.java
@@ -537,6 +537,7 @@ public class LoadService {
boolean loaded = tryLoadingLibraryOrScript(runtime, state);
if (loaded) {
addLoadedFeature(state.loadName);
+ addLoadedFeature(file);
}
return loaded;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment