From aaa9b669f80385d2fa96c5188cbd18d9320c7f29 Mon Sep 17 00:00:00 2001 From: Eugene Kenny Date: Tue, 17 Sep 2019 23:38:01 +0100 Subject: [PATCH] Allow ActionDispatch::Response to be autoloaded Similar to b744372f2dfd3d86f7eb4af99b1f9049e21f3d44, this defers loading `ActionDispatch::Response` until after initialization, which will allow applications to boot a bit faster in development but also paves the way for `return_only_media_type_on_content_type` to work correctly when set from `new_framework_defaults_6_0.rb`. Benchmark: $ cat test.rb require "bundler/setup" before = ObjectSpace.each_object(Module).count start = Process.clock_gettime(Process::CLOCK_MONOTONIC) require "action_controller" finish = Process.clock_gettime(Process::CLOCK_MONOTONIC) after = ObjectSpace.each_object(Module).count puts "took #{finish - start} and created #{after - before} modules" Before: $ ruby test.rb took 0.35654300000169314 and created 608 modules After: $ ruby test.rb took 0.2770050000108313 and created 466 modules Co-authored-by: Serena Fritsch --- actionpack/lib/action_controller.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/actionpack/lib/action_controller.rb b/actionpack/lib/action_controller.rb index 22dc2295997ec..b46defcd7ece8 100644 --- a/actionpack/lib/action_controller.rb +++ b/actionpack/lib/action_controller.rb @@ -2,7 +2,6 @@ require "abstract_controller" require "action_dispatch" -require "action_controller/metal/live" require "action_controller/metal/strong_parameters" module ActionController @@ -20,6 +19,10 @@ module ActionController end autoload_under "metal" do + eager_autoload do + autoload :Live + end + autoload :ConditionalGet autoload :ContentSecurityPolicy autoload :Cookies