Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
  • Loading branch information...
commit 4d47220d7c4d07d23e4a1f01bdd6d86fa76237ca 1 parent 71e8f19
@schneems schneems authored
Showing with 3 additions and 1 deletion.
  1. +3 −1 actionview/lib/action_view/routing_url_for.rb
View
4 actionview/lib/action_view/routing_url_for.rb
@@ -82,7 +82,9 @@ def url_for(options = nil)
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

1 comment on commit 4d47220

@jonatack

Impressive difference :-)

Please sign in to comment.
Something went wrong with that request. Please try again.