Skip to content

Commit dde7134

Browse files
committed
Freeze fragment cache related instrument name.
ActionMailer::Base#instrument_name and ActionController::Base#instrument_name will be frequently called once caching is enabled. So it's better to freeze them instead of create new string on every call. Also, the instrument name in #instrument_fragment_cache will usually be "write_fragment.action_controller" or "read_fragment.action_controller". So freezing them might also gain some performance improvement. We have done something like this in other places: https://github.com/rails/rails/blob/master/actionview/lib/action_view/template.rb#L348
1 parent e3afc83 commit dde7134

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

actionmailer/lib/action_mailer/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ def instrument_payload(key)
972972
end
973973

974974
def instrument_name
975-
"action_mailer"
975+
"action_mailer".freeze
976976
end
977977

978978
ActiveSupport.run_load_hooks(:action_mailer, self)

actionpack/lib/abstract_controller/caching/fragments.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def expire_fragment(key, options = nil)
136136

137137
def instrument_fragment_cache(name, key) # :nodoc:
138138
payload = instrument_payload(key)
139-
ActiveSupport::Notifications.instrument("#{name}.#{instrument_name}", payload) { yield }
139+
ActiveSupport::Notifications.instrument("#{name}.#{instrument_name}".freeze, payload) { yield }
140140
end
141141
end
142142
end

actionpack/lib/action_controller/caching.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def instrument_payload(key)
3838
end
3939

4040
def instrument_name
41-
"action_controller"
41+
"action_controller".freeze
4242
end
4343
end
4444
end

0 commit comments

Comments
 (0)