diff options
author | schneems <richard.schneeman+foo@gmail.com> | 2018-09-07 13:45:01 -0500 |
---|---|---|
committer | schneems <richard.schneeman+foo@gmail.com> | 2018-09-07 17:33:10 -0500 |
commit | 1bd578ffe6e89cbe828745c15d730be2ce850109 (patch) | |
tree | 7d4c93e3f4c4e4af7d80478ef49ff428d2ee6356 /actionview/lib | |
parent | c3e569550ca0a90561fe990f519719ba52402504 (diff) | |
download | rails-1bd578ffe6e89cbe828745c15d730be2ce850109.tar.gz rails-1bd578ffe6e89cbe828745c15d730be2ce850109.tar.bz2 rails-1bd578ffe6e89cbe828745c15d730be2ce850109.zip |
Don’t allocate array on no args
When no dependencies are present to be digested there is no reason to build an array just to turn around and turn it back into a string.
The dependencies array is not mutated in this method so we can use the same empty array across all invocations.
Total allocated: 791402 bytes (7294 objects)
Total allocated: 777442 bytes (7132 objects)
(791402 - 777442) / 791402.0 # => 1.76 % speed improvement
Diffstat (limited to 'actionview/lib')
-rw-r--r-- | actionview/lib/action_view/digestor.rb | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/actionview/lib/action_view/digestor.rb b/actionview/lib/action_view/digestor.rb index 39cdecb9e4..6d2e471a44 100644 --- a/actionview/lib/action_view/digestor.rb +++ b/actionview/lib/action_view/digestor.rb @@ -18,9 +18,12 @@ module ActionView # * <tt>name</tt> - Template name # * <tt>finder</tt> - An instance of <tt>ActionView::LookupContext</tt> # * <tt>dependencies</tt> - An array of dependent views - def digest(name:, finder:, dependencies: []) - dependencies ||= [] - cache_key = [ name, finder.rendered_format, dependencies ].flatten.compact.join(".") + def digest(name:, finder:, dependencies: nil) + if dependencies.nil? || dependencies.empty? + cache_key = "#{name}.#{finder.rendered_format}" + else + cache_key = [ name, finder.rendered_format, dependencies ].flatten.compact.join(".") + end # this is a correctly done double-checked locking idiom # (Concurrent::Map's lookups have volatile semantics) @@ -30,7 +33,7 @@ module ActionView root = tree(name, finder, partial) dependencies.each do |injected_dep| root.children << Injected.new(injected_dep, nil, nil) - end + end if dependencies finder.digest_cache[cache_key] = root.digest(finder) end end |