Created
May 27, 2012 15:49
-
-
Save d11wtq/2814849 to your computer and use it in GitHub Desktop.
Rails startup time optimization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Instructions for use | |
# | |
# 1. Execute "time rails runner nil" a few times in your shell, see how long rails takes to boot | |
# 2. Add this monkey patch to the top of config/boot.rb | |
# 3. Repeat step 1. What's the difference? | |
# | |
# This is just an experiment, but it gains me 30% on Rails' start time, which suggests there is something | |
# in Rails that is breaking the "run only once" behaviour of #require. | |
# | |
# Note: You can't override Kernel#require, since Rails by-passes it most of the time. | |
class Object | |
def require_with_dirty_filthy_hack(path) | |
return false if (@@__seen ||= {})[path] | |
@@__seen[path] = true | |
require_without_dirty_filthy_hack(path) | |
end | |
alias_method :require_without_dirty_filthy_hack, :require | |
alias_method :require, :require_with_dirty_filthy_hack | |
end |
require
to get the module into scope, include
to mix it into the model. Do you mean require
or load
?
I meant require, wondered why you mentioned it since we're using Rails' autoload and don't require it at all - possibly why it still works.
Ah, I see… yeah, we did a whole bunch of other stuff to prevent gems from loading during Rails startup, so we're requiring the actual gems by hand in some places ;)
Il giorno 30/mag/2012, alle ore 16:28, Mal Curtis ha scritto:
… I meant require, wondered why you mentioned it since we're using Rails' autoload and don't require it at all - possibly why it still works.
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/2814849
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Are you using
require
orinclude
?