Skip to content

Commit 52522a9

Browse files
committed
Fix performance regression with empty template rendering
Closes rspec#1537. The change in 80637fc introduced a performance regression because the template lookup cache was being lost every time an example was run. This commit fixes the problem by caching the EmptyTemplateResolver instances between example runs in a hash indexed by the path string.
1 parent cf97d15 commit 52522a9

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lib/rspec/rails/view_rendering.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,18 @@ def _path_decorator(path)
8585
end
8686
end
8787

88+
# @private
89+
RESOLVER_CACHE = Hash.new do |hash, path|
90+
hash[path] = EmptyTemplateResolver.new(path)
91+
end
92+
8893
included do
8994
before do
9095
unless render_views?
9196
@_original_path_set = controller.class.view_paths
97+
path_set = @_original_path_set.map { |resolver| RESOLVER_CACHE[resolver.to_s] }
9298

93-
empty_template_path_set = @_original_path_set.map do |resolver|
94-
EmptyTemplateResolver.new(resolver.to_s)
95-
end
96-
97-
controller.class.view_paths = empty_template_path_set
99+
controller.class.view_paths = path_set
98100
controller.extend(EmptyTemplates)
99101
end
100102
end

0 commit comments

Comments
 (0)