diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2015-08-17 15:57:06 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2015-08-17 15:57:06 -0700 |
commit | 559e7f94506ac3c3e8553f9510f43923e7c804da (patch) | |
tree | 26998a77988644fb7e99f791fe91d4c157b32906 /actionpack/test/journey/router_test.rb | |
parent | 8d7b883f33034732996f80f73f46d050c7dc9210 (diff) | |
download | rails-559e7f94506ac3c3e8553f9510f43923e7c804da.tar.gz rails-559e7f94506ac3c3e8553f9510f43923e7c804da.tar.bz2 rails-559e7f94506ac3c3e8553f9510f43923e7c804da.zip |
drop object allocation during routes setup
This commit introduces a functional Path AST visitor and implements
`each` on the AST in terms of the functional visitor. The functional
visitor doesn't maintain state, so we only need to allocate one of them.
Given this benchmark route file:
```ruby
require 'action_pack'
require 'action_dispatch'
route_set = ActionDispatch::Routing::RouteSet.new
routes = ActionDispatch::Routing::Mapper.new route_set
ObjectSpace::AllocationTracer.setup(%i{path line type})
result = ObjectSpace::AllocationTracer.trace do
500.times{|i|
routes.resource :omglol
}
end
result.find_all { |k,v| k.first =~ /git\/rails/ }.sort_by { |k,v|
v.first
}.each { |k,v|
p k => v
}
```
node.rb line 17 was in our top 3 allocation spot:
```
{["/Users/aaron/git/rails/actionpack/lib/action_dispatch/journey/nodes/node.rb", 17, :T_OBJECT]=>[31526, 0, 28329, 0, 2, 1123160]}
{["/Users/aaron/git/rails/actionpack/lib/action_dispatch/routing/mapper.rb", 2080, :T_IMEMO]=>[34002, 0, 30563, 0, 2, 1211480]}
{["/Users/aaron/git/rails/actionpack/lib/action_dispatch/routing/mapper.rb", 2071, :T_IMEMO]=>[121934, 1, 109608, 0, 7, 4344400]}
```
This commit eliminates allocations at that place.
Diffstat (limited to 'actionpack/test/journey/router_test.rb')
0 files changed, 0 insertions, 0 deletions