Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable ActionView::Template finalizers in test environment #32418

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions actionview/CHANGELOG.md
@@ -1,3 +1,12 @@
* Disable `ActionView::Template` finalizers in test environment

Template finalization can be expensive in large view test suites.
Add a configuration option,
`action_view.finalize_compiled_template_methods`, and turn it off in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reminder me that we need to update the configuration guide to add this new option. Can you do that?

the test environment.

*Simon Coffey*

* Extract the `confirm` call in its own, overridable method in `rails_ujs`.
Example :
Rails.confirm = function(message, element) {
Expand Down
8 changes: 8 additions & 0 deletions actionview/lib/action_view/railtie.rb
Expand Up @@ -10,6 +10,7 @@ class Railtie < Rails::Engine # :nodoc:
config.action_view.embed_authenticity_token_in_remote_forms = nil
config.action_view.debug_missing_translation = true
config.action_view.default_enforce_utf8 = nil
config.action_view.finalize_compiled_template_methods = true

config.eager_load_namespaces << ActionView

Expand Down Expand Up @@ -45,6 +46,13 @@ class Railtie < Rails::Engine # :nodoc:
end
end

initializer "action_view.finalize_compiled_template_methods" do |app|
ActiveSupport.on_load(:action_view) do
ActionView::Template.finalize_compiled_template_methods =
app.config.action_view.delete(:finalize_compiled_template_methods)
end
end

initializer "action_view.logger" do
ActiveSupport.on_load(:action_view) { self.logger ||= Rails.logger }
end
Expand Down
7 changes: 6 additions & 1 deletion actionview/lib/action_view/template.rb
Expand Up @@ -9,6 +9,9 @@ module ActionView
class Template
extend ActiveSupport::Autoload

mattr_accessor :finalize_compiled_template_methods
self.finalize_compiled_template_methods = true

# === Encodings in ActionView::Template
#
# ActionView::Template is one of a few sources of potential
Expand Down Expand Up @@ -307,7 +310,9 @@ def #{method_name}(local_assigns, output_buffer)
end

mod.module_eval(source, identifier, 0)
ObjectSpace.define_finalizer(self, Finalizer[method_name, mod])
if finalize_compiled_template_methods
ObjectSpace.define_finalizer(self, Finalizer[method_name, mod])
end
end

def handle_render_error(view, e)
Expand Down
7 changes: 7 additions & 0 deletions guides/source/configuring.md
Expand Up @@ -600,6 +600,13 @@ Defaults to `'signed cookie'`.

* `config.action_view.default_enforce_utf8` determines whether forms are generated with a hidden tag that forces older versions of Internet Explorer to submit forms encoded in UTF-8. This defaults to `false`.

* `config.action_view.finalize_compiled_template_methods` determines
whether the methods on `ActionView::CompiledTemplates` that templates
compile themselves to are removed when template instances are
destroyed by the garbage collector. This helps prevent memory leaks in
development mode, but for large test suites, disabling this option in
the test environment can improve performance. This defaults to `true`.

### Configuring Action Mailer

There are a number of settings available on `config.action_mailer`:
Expand Down
Expand Up @@ -47,4 +47,7 @@ Rails.application.configure do

# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true

# Prevent expensive template finalization at end of test suite runs.
config.action_view.finalize_compiled_template_methods = false
end