fix: Eager load when 'rake_eager_load = false'#88
Open
smudge wants to merge 1 commit intoBetterment:mainfrom
Open
fix: Eager load when 'rake_eager_load = false'#88smudge wants to merge 1 commit intoBetterment:mainfrom
smudge wants to merge 1 commit intoBetterment:mainfrom
Conversation
38cc214 to
f4966b1
Compare
aryakarnik1
reviewed
Feb 3, 2026
| # `cache_classes` & explicitly eager load if true. | ||
|
|
||
| eager_loaded = Rails.application.config.respond_to?(:rake_eager_load) && Rails.application.config.rake_eager_load | ||
| next if eager_loaded || !Rails.application.config.cache_classes |
There was a problem hiding this comment.
What does !Rails.application.config.cache_classes check for? My understanding is it skips eager loading in development (where cache_classes = false) since classes reload anyway. Is that correct?
Member
Author
There was a problem hiding this comment.
Yeah -- if cache_classes == false, I use that as a signal to skip eager loading.
In newer rails versions, cache_classes is equivalent to !enable_reloading. So line 37 could be read as:
next if eager_loaded || Rails.application.config.enable_reloadingSo if you've already enabled dynamic reloading, then we infer that you aren't in an environment where you care about deterministic load order in general.
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.
By default, Rails wants to disable eager loading inside of
rakecommands, even ifeager_loadis set to true. This is done to speed up the boot time of rake tasks that don't need the entire application loaded.The problem is that long-lived processes like
delayeddo want to eager load the application before spawning any threads or forks. (Especially if in a production environment where we want full load-order parity with therails serverprocesses!)When a Rails app boots, it chooses whether to eager load based on its
eager_loadconfig and whether or not it was initiated by arakecommand. If it did eager load, we don't want to eager load again, but if it was initiated by arakecommand, it setseager_loadto false before the point at whichdelayedstarts setting up its rake environment.So we cannot rely on that config to know whether or not to eager load -- instead we must make an inference:
config.rake_eager_loadoption, which tells us whether the app has already eager loaded in arakecontext.rake_eager_loadingis not defined orfalse, we will then checkcache_classes& explicitly eager load if true./no-platform