-
-
Save josevalim/1437939 to your computer and use it in GitHub Desktop.
# THANKS EVERYONE FOR YOUR BELOVED BENCHMARKS. | |
# THIS PATCH IS NOW IN RAILS: | |
# | |
# https://github.com/rails/rails/commit/885a599303585b796da7a0a1c3ccd0bc5c642134 | |
# Please add the following lines after Bundler.require | |
# and before "class Application < Rails::Application" | |
# in your config/application.rb | |
# | |
# Notice this is just an experiment, don't leave those | |
# lines there after the experiment. Then please benchmark | |
# your app boot time in development before and after adding | |
# those lines. A simple benchmark is: | |
# | |
# time script/rails runner "MODEL" | |
# | |
# Where MODEL is a model available in your app. Also, | |
# please run the command above at least three times to | |
# ensure we don't have fake samples. :) | |
# | |
# Please post the results in the comments below of the | |
# benchmarks before and after adding the code. <3 | |
# | |
# This patch should work on Rails 3.0, 3.1 and master. | |
# | |
# Extra: if you could run your app in development and | |
# production (in your machine!!) with this patch on | |
# for a couple minutes and report any errors, you will | |
# win extra <3 <3 <3. | |
require "active_support/dependencies" | |
ActiveSupport::Dependencies::WatchStack.class_eval do | |
def watching? | |
[email protected]? | |
end | |
end | |
def load_dependency(file) | |
if ActiveSupport::Dependencies.load? && ActiveSupport::Dependencies.constant_watch_stack.watching? | |
ActiveSupport::Dependencies.new_constants_in(Object) { yield } | |
else | |
yield | |
end | |
rescue Exception => exception # errors from loading file | |
exception.blame_file! file | |
raise | |
end |
Ruby 1.9.3p0, Rails 3.1.3
Before:
real 14.01s
user 12.22s
sys 1.73s
After:
real 13.70s
user 11.73s
sys 1.78s
Before:
script/rails runner "Call" 8.48s user 1.05s system 96% cpu 9.900 total
script/rails runner "Call" 8.50s user 0.86s system 99% cpu 9.374 total
script/rails runner "Call" 8.41s user 0.83s system 99% cpu 9.254 total
After:
script/rails runner "Call" 7.85s user 0.81s system 99% cpu 8.663 total
script/rails runner "Call" 7.92s user 0.84s system 99% cpu 8.763 total
script/rails runner "Call" 7.67s user 0.77s system 99% cpu 8.449 total
I'll leave the patch in development mode and report back if I have any errors.
Ruby 1.9.3-p0, Rails 3.1.3
Before:
5.30s user 0.70s system 99% cpu 6.009 total
5.49s user 0.72s system 98% cpu 6.337 total
5.34s user 0.69s system 99% cpu 6.050 total
After:
4.95s user 0.72s system 99% cpu 5.686 total
4.96s user 0.71s system 99% cpu 5.685 total
5.04s user 0.71s system 99% cpu 5.789 total
Will be leaving the patch in today and I'll report any issues...
Ruby 1.9.2, Rails 3.1, openSUSE 12.1
Before
real 0m30.473s
user 0m29.551s
sys 0m0.771s
real 0m31.978s
user 0m30.984s
sys 0m0.892s
real 0m31.855s
user 0m30.922s
sys 0m0.823s
After
real 0m30.095s
user 0m29.201s
sys 0m0.810s
real 0m30.118s
user 0m29.303s
sys 0m0.731s
real 0m30.385s
user 0m29.494s
sys 0m0.805s
With JRuby 1.6.4
Before
λ time script/rails runner Advisor real 0m11.627s user 0m23.053s sys 0m0.967s
After
λ time script/rails runner Advisor real 0m11.437s user 0m23.101s sys 0m0.987s
No much difference.
Sorry... ignore the error i reported... accidentally deleted the Bundler.require... doh
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.0.0]
Rails 3.0.9
Before:
13,37s user 1,03s system 100% cpu 14,397 total
13,42s user 1,05s system 99% cpu 14,468 total
13,48s user 1,06s system 100% cpu 14,534 total
After:
13,21s user 1,07s system 99% cpu 14,394 total
13,37s user 1,06s system 99% cpu 14,433 total
13,34s user 1,06s system 100% cpu 14,391 total
No actual improvement noticed...
Rails 3.0.10
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.1.0]
Before:
real 0m38.392s
user 0m35.857s
sys 0m2.511s
After:
real 0m36.849s
user 0m34.325s
sys 0m2.443s
Same app with ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.1.0]
Before:
real 0m17.713s
user 0m14.797s
sys 0m1.444s
After:
real 0m15.556s
user 0m14.086s
sys 0m1.400s
Thanks everyone for your beloved benchmarks. This patch is now in Rails:
Development mode, REE, 3.0.10,
script/rails runner User
Before:
real 0m14.498s user 0m10.630s sys 0m3.006s
After:
real 0m12.922s user 0m9.591s sys 0m2.893s