提交 9b189a31 编写于 作者: S schneems

Cut string ActionView template allocations

The instrument method creates new strings, the most common action to instrument is "!render_template` so we can detect when that action is occurring and use a frozen string instead.

This change buys us 113,714 bytes of memory and 1,790 fewer objects per request.
上级 2e95d2ef
......@@ -154,7 +154,7 @@ def supports_streaming?
# we use a bang in this instrumentation because you don't want to
# consume this in production. This is only slow if it's being listened to.
def render(view, locals, buffer=nil, &block)
instrument("!render_template") do
instrument("!render_template".freeze) do
compile!(view)
view.send(method_name, locals, buffer, &block)
end
......@@ -348,7 +348,12 @@ def identifier_method_name #:nodoc:
def instrument(action, &block)
payload = { virtual_path: @virtual_path, identifier: @identifier }
ActiveSupport::Notifications.instrument("#{action}.action_view", payload, &block)
case action
when "!render_template".freeze
ActiveSupport::Notifications.instrument("!render_template.action_view".freeze, payload, &block)
else
ActiveSupport::Notifications.instrument("#{action}.action_view".freeze, payload, &block)
end
end
EXPLICIT_COLLECTION = /# Template Collection: (?<resource_name>\w+)/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册