1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionpack/lib
Aaron Patterson 559e7f9450 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.
2015-08-17 15:57:06 -07:00
..
abstract_controller Initialize symbols instead of mapping to_sym on the set of strings 2015-08-15 17:45:13 +02:00
action_controller Fix master build 2015-08-17 23:30:32 +02:00
action_dispatch drop object allocation during routes setup 2015-08-17 15:57:06 -07:00
action_pack Start Rails 5 development 🎉 2014-11-28 15:00:06 -02:00
abstract_controller.rb
action_controller.rb Return 204 if render is not called in API controllers 2015-06-11 16:54:17 -03:00
action_dispatch.rb Soften the lock requirements when eager_load is disabled 2015-07-09 02:23:23 +09:30
action_pack.rb Update copyright notices to 2015 [ci skip] 2014-12-31 08:34:14 +01:00