aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2019-04-07 12:30:34 +0200
committerXavier Noria <fxn@hashref.com>2019-04-07 13:05:26 +0200
commit57c7cbb1623c0e8befc58988a34bbb9896fd226a (patch)
tree56160343a026cd0fc0bf7e64c988b6937c224aed
parentc9e4c848eeeb8999b778fa1ae52185ca5537fffe (diff)
downloadrails-57c7cbb1623c0e8befc58988a34bbb9896fd226a.tar.gz
rails-57c7cbb1623c0e8befc58988a34bbb9896fd226a.tar.bz2
rails-57c7cbb1623c0e8befc58988a34bbb9896fd226a.zip
depend on Zeitwerk 2
-rw-r--r--Gemfile.lock4
-rw-r--r--activesupport/CHANGELOG.md6
-rw-r--r--activesupport/activesupport.gemspec2
-rw-r--r--activesupport/lib/active_support/dependencies/zeitwerk_integration.rb7
-rw-r--r--railties/lib/rails/application/finisher.rb2
-rw-r--r--railties/test/application/zeitwerk_integration_test.rb14
6 files changed, 28 insertions, 7 deletions
diff --git a/Gemfile.lock b/Gemfile.lock
index 92dcee9542..b1f9991adc 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -71,7 +71,7 @@ PATH
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
- zeitwerk (~> 1.4, >= 1.4.3)
+ zeitwerk (~> 2.0)
rails (6.0.0.beta3)
actioncable (= 6.0.0.beta3)
actionmailbox (= 6.0.0.beta3)
@@ -526,7 +526,7 @@ GEM
websocket-extensions (0.1.3)
xpath (3.2.0)
nokogiri (~> 1.8)
- zeitwerk (1.4.3)
+ zeitwerk (2.0.0)
PLATFORMS
java
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md
index db9c7e96f3..cf72673dbb 100644
--- a/activesupport/CHANGELOG.md
+++ b/activesupport/CHANGELOG.md
@@ -1,3 +1,9 @@
+* Depends on Zeitwerk 2, which stores less metadata if reloading is disabled
+ and hence uses less memory when `config.cache_classes` is `true`, a standard
+ setup in production.
+
+ *Xavier Noria*
+
* In `:zeitwerk` mode, eager load directories in engines and applications only
if present in their respective `config.eager_load_paths`.
diff --git a/activesupport/activesupport.gemspec b/activesupport/activesupport.gemspec
index bf0fe0f76d..e719fc6176 100644
--- a/activesupport/activesupport.gemspec
+++ b/activesupport/activesupport.gemspec
@@ -34,5 +34,5 @@ Gem::Specification.new do |s|
s.add_dependency "tzinfo", "~> 1.1"
s.add_dependency "minitest", "~> 5.1"
s.add_dependency "concurrent-ruby", "~> 1.0", ">= 1.0.2"
- s.add_dependency "zeitwerk", "~> 1.4", ">= 1.4.3"
+ s.add_dependency "zeitwerk", "~> 2.0"
end
diff --git a/activesupport/lib/active_support/dependencies/zeitwerk_integration.rb b/activesupport/lib/active_support/dependencies/zeitwerk_integration.rb
index a43d03cf09..faf9edef27 100644
--- a/activesupport/lib/active_support/dependencies/zeitwerk_integration.rb
+++ b/activesupport/lib/active_support/dependencies/zeitwerk_integration.rb
@@ -51,15 +51,15 @@ module ActiveSupport
end
class << self
- def take_over
- setup_autoloaders
+ def take_over(enable_reloading:)
+ setup_autoloaders(enable_reloading)
freeze_paths
decorate_dependencies
end
private
- def setup_autoloaders
+ def setup_autoloaders(enable_reloading)
Dependencies.autoload_paths.each do |autoload_path|
# Zeitwerk only accepts existing directories in `push_dir` to
# prevent misconfigurations.
@@ -72,6 +72,7 @@ module ActiveSupport
autoloader.do_not_eager_load(autoload_path) unless eager_load?(autoload_path)
end
+ Rails.autoloaders.main.enable_reloading if enable_reloading
Rails.autoloaders.each(&:setup)
end
diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb
index 8d2c13d2a8..1cf44a480c 100644
--- a/railties/lib/rails/application/finisher.rb
+++ b/railties/lib/rails/application/finisher.rb
@@ -24,7 +24,7 @@ module Rails
initializer :let_zeitwerk_take_over do
if config.autoloader == :zeitwerk
require "active_support/dependencies/zeitwerk_integration"
- ActiveSupport::Dependencies::ZeitwerkIntegration.take_over
+ ActiveSupport::Dependencies::ZeitwerkIntegration.take_over(enable_reloading: !config.cache_classes)
end
end
diff --git a/railties/test/application/zeitwerk_integration_test.rb b/railties/test/application/zeitwerk_integration_test.rb
index dc6db429a9..a9da060347 100644
--- a/railties/test/application/zeitwerk_integration_test.rb
+++ b/railties/test/application/zeitwerk_integration_test.rb
@@ -131,6 +131,20 @@ class ZeitwerkIntegrationTest < ActiveSupport::TestCase
assert $zeitwerk_integration_test_post
end
+ test "reloading is enabled if config.cache_classes is false" do
+ boot
+
+ assert Rails.autoloaders.main.reloading_enabled?
+ assert_not Rails.autoloaders.once.reloading_enabled?
+ end
+
+ test "reloading is disabled if config.cache_classes is true" do
+ boot("production")
+
+ assert_not Rails.autoloaders.main.reloading_enabled?
+ assert_not Rails.autoloaders.once.reloading_enabled?
+ end
+
test "eager loading loads code in engines" do
$test_blog_engine_eager_loaded = false