From 0668c22a41e4c88ccb7600fc5b4bfb1a5b76e45d Mon Sep 17 00:00:00 2001 From: Kir Shatrov Date: Sat, 24 Jun 2017 10:57:36 -0400 Subject: Eager load controller and mailer actions On the first request, ActionController::Base#action_methods computes and memoized the list of available actions [1]. With this PR we move this expensive operation into eager load step to reduce response time of the first request served in production. This also reduces the memory footprint when running on forking server like Unicorn. [1] https://github.com/rails/rails/blob/a3813dce9a0c950a4af7909111fa730a2622b1db/actionpack/lib/abstract_controller/base.rb#L66-L77 --- actionpack/lib/action_controller/railtie.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/railtie.rb b/actionpack/lib/action_controller/railtie.rb index 1c1cd58732..0d7a230b17 100644 --- a/actionpack/lib/action_controller/railtie.rb +++ b/actionpack/lib/action_controller/railtie.rb @@ -77,5 +77,11 @@ module ActionController end end end + + initializer "action_controller.eager_load_actions" do + ActiveSupport.on_load(:after_initialize) do + ActionController::Metal.descendants.each(&:action_methods) if config.eager_load + end + end end end -- cgit v1.2.3