From 4d47220d7c4d07d23e4a1f01bdd6d86fa76237ca Mon Sep 17 00:00:00 2001 From: schneems Date: Thu, 14 Aug 2014 12:29:25 -0500 Subject: [PATCH] Perf optimization for `url_for` called w/ Hash Benchmarking the existing code: ```ruby { :only_path => options[:host].nil? }.merge!(options.symbolize_keys)) ``` Against optimized code, that does not require a new hash or a merge: ```ruby options = options.symbolize_keys options[:only_path] = options[:host].nil? unless options.key?(:only_path) options ``` We see a statistically significant performance gain: ![](https://www.dropbox.com/s/onocpc0zfw4kjxl/Screenshot%202014-08-14%2012.45.30.png?dl=1) Updated to not mutate incoming parameters --- actionview/lib/action_view/routing_url_for.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/actionview/lib/action_view/routing_url_for.rb b/actionview/lib/action_view/routing_url_for.rb index 881a123572..75febb8652 100644 --- a/actionview/lib/action_view/routing_url_for.rb +++ b/actionview/lib/action_view/routing_url_for.rb @@ -82,7 +82,9 @@ module ActionView when nil super({:only_path => true}) when Hash - super({ :only_path => options[:host].nil? }.merge!(options.symbolize_keys)) + options = options.symbolize_keys + options[:only_path] = options[:host].nil? unless options.key?(:only_path) + super(options) when :back _back_url when Symbol