Commit
add lazy_load_hooks.rb, which allows us to declare code that should be run at some later time. For instance, this allows us to defer requiring ActiveRecord::Base at boot time purely to apply configuration. Instead, we register a hook that should apply configuration once ActiveRecord::Base is loaded. With these changes, brings down total boot time of a new app to 300ms in production and 400ms in dev. TODO: rename base_hook
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
require 'active_support/json' | ||
require 'action_dispatch/http/request' | ||
|
||
module ActionDispatch | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
require 'active_support/core_ext/hash/keys' | ||
require 'rack/request' | ||
|
||
module ActionDispatch | ||
module Session | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require 'action_controller/test_case' | ||
require 'action_view' | ||
|
||
module ActionView | ||
class Base | ||
|
5 comments
on commit 39d6f9e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very nice already!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What effect does this have on threadsafe!
mode, if any?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm all for pushing initializer stuff to be as lazy as possible. Nice for console when you may not even use the db connection. Just connect right before we have to.
Using base require as the trigger seems brittle. Anything that loads AR::Base before the initializers run will trigger base hooks with no callbacks. This seems more likely with the suggestion we all should be using Bundler.require.
Almost everything in the framework railties wrap their initializers in this base_hook hook. Why not make it a convention to defer all "active_record.*" initializers till ActiveRecord::Base is loaded? And if its already defined, run them immediately.
And hopefully base_hook is not "public api".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yfeldblum: not much if any. This changeset affects (very) early framework loading. The only case for threading at boot time I can think of is initialization of EventMachine reactor in a thread, required by libraries like amqp gem. But EM startup really belongs to initializers, and they are executed later in the process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Josh, could see this being plugin API.
It's natural for a plugin to want to say "if Action Mailer is used, load this stuff" without having to write an initializer that does defined?
checks.
Is this line necessary? None of the other framework components have it and it's actually ActiveSupport::Autoload that's doing the extending.