Eagerly preload framework base classes#752
Merged
rafaelfranca merged 1 commit intoMay 1, 2026
Merged
Conversation
e1f2d9f to
742983d
Compare
932eb70 to
6e708f5
Compare
6e708f5 to
70dbe8e
Compare
After `config/environment` is loaded, eagerly autoload framework base classes (`ActionMailer::Base`, `ActionController::Base`, `ActionController::API`) so their `ActiveSupport.on_load` hooks fire in the parent process. Those classes shouldn't change and sometimes have side effects when loaded, although the biggest one is getting fixed in Rails (see rails/rails#57269), it won't hurt to still preload those classes so they don't get loaded on each fork again.
70dbe8e to
964e1a7
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Spring::Application#servecallsRails.application.reloaders.any?(&:updated?)before forking. ActionView'sCacheExpiry::ViewReloader#updated?lazily builds aFileUpdateCheckerfrom whatever view paths are registered at that moment (lazy-init contract from rails/rails#51308).Engines register view paths via
prepend_view_pathinsideon_load(:action_mailer)/:action_controller_baseblocks. In a fresh preload nothing has referenced those framework classes yet, sodirs_to_watchis empty when the probe runs — pinning the watcher empty and triggering a fullFileUpdateCheckerrebuild on everyprepend_view_pathin each fork.Preloading the framework classes (not
Application*, per Rafael's suggestion, framework code is never reloaded, app namespace is) targets theon_loadhooks directly and avoids coupling Spring's preload to user-reloadable code.While rails/rails#57269 closes the bug part of this from the Rails side, this still makes sense on it's own.