1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Went from 25% slower partials (vs. 2.3) to 10% faster. More to come.

This commit is contained in:
Yehuda Katz 2009-08-08 23:43:45 -03:00
parent 930d235981
commit 0ab40b039b
3 changed files with 23 additions and 10 deletions

View file

@ -70,9 +70,18 @@ class HttpPostController < ActionController::Metal
end end
end end
(ENV["M"] || 1).to_i.times do unless ENV["PROFILE"]
Runner.run(BasePostController.action(:partial), N, 'partial') (ENV["M"] || 1).to_i.times do
Runner.run(BasePostController.action(:many_partials), N, 'many_partials') Runner.run(BasePostController.action(:partial), N, 'partial')
Runner.run(BasePostController.action(:partial_collection), N, 'collection') Runner.run(BasePostController.action(:many_partials), N, 'many_partials')
Runner.run(BasePostController.action(:show_template), N, 'template') Runner.run(BasePostController.action(:partial_collection), N, 'collection')
Runner.run(BasePostController.action(:show_template), N, 'template')
end
else
require "ruby-prof"
RubyProf.start
Runner.run(BasePostController.action(:many_partials), N, 'partial')
result = RubyProf.stop
printer = RubyProf::CallStackPrinter.new(result)
printer.print(File.open("output.html", "w"), :min_percent => 2)
end end

View file

@ -177,6 +177,10 @@ module ActionView
@partial_names ||= Hash.new {|h,k| h[k] = ActiveSupport::ConcurrentHash.new } @partial_names ||= Hash.new {|h,k| h[k] = ActiveSupport::ConcurrentHash.new }
end end
def self.formats
@formats ||= Hash.new {|h,k| h[k] = Hash.new {|h,k| h[k] = {}}}
end
def initialize(view_context, options, block) def initialize(view_context, options, block)
partial = options[:partial] partial = options[:partial]
@ -187,8 +191,8 @@ module ActionView
# Set up some instance variables to speed up memoizing # Set up some instance variables to speed up memoizing
@partial_names = self.class.partial_names[@view.controller.class] @partial_names = self.class.partial_names[@view.controller.class]
@templates = Hash.new {|h,k| h[k] = {}} @templates = self.class.formats
@formats_hash = view_context.formats.hash @details_hash = [view_context.formats, I18n.locale].hash
# Set up the object and path # Set up the object and path
@object = partial.is_a?(String) ? options[:object] : partial @object = partial.is_a?(String) ? options[:object] : partial
@ -248,7 +252,7 @@ module ActionView
def find_template(path = @path) def find_template(path = @path)
return if !path return if !path
@templates[path][@formats_hash] ||= begin @templates[@details_hash][path][@view.controller_path] ||= begin
prefix = @view.controller.controller_path unless path.include?(?/) prefix = @view.controller.controller_path unless path.include?(?/)
@view.find(path, {:formats => @view.formats}, prefix, true) @view.find(path, {:formats => @view.formats}, prefix, true)
end end

View file

@ -30,12 +30,12 @@ module ActionView
# TODO: Figure out how to abstract this # TODO: Figure out how to abstract this
def variable_name def variable_name
identifier[%r'_?(\w+)(\.\w+)*$', 1].to_sym @variable_name ||= identifier[%r'_?(\w+)(\.\w+)*$', 1].to_sym
end end
# TODO: Figure out how to abstract this # TODO: Figure out how to abstract this
def counter_name def counter_name
"#{variable_name}_counter".to_sym @counter_name ||= "#{variable_name}_counter".to_sym
end end
# TODO: kill hax # TODO: kill hax