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

20 commits

Author SHA1 Message Date
Akira Matsuda
dcecbb4234 File encoding is defaulted to utf-8 in Ruby >= 2.1 2015-09-18 17:05:05 +09:00
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
Aaron Patterson
4d1b3a1312 reuse path formatter from the non-optimized path.
The optimized and non-optimized path share more code now without
significant performance degretation
2014-05-21 14:27:30 -07:00
Aaron Patterson
25c6726372 remove dead code 2014-05-20 13:25:14 -07:00
Aaron Patterson
e883db02bc translate AST to a formatter before url generation 2014-05-20 13:25:13 -07:00
Aaron Patterson
74a847771f prepopulate the dispatch cache so we don't need the ThreadSafe cache. 2014-05-20 11:10:52 -07:00
Aaron Patterson
e08696421f make the each visitor top-down left-right 2014-05-20 11:00:27 -07:00
Aaron Patterson
dc2e3ea8c4 fix escaping in generation 2014-05-19 16:43:16 -07:00
Aaron Patterson
62d1b330c4 Revert "Rewrite journey routes formatter for performance"
This reverts commit 5c224de9e1.

Conflicts:
	actionpack/lib/action_dispatch/journey/visitors.rb

5c224de9e1 introduced a bug in the
formatter.  This commit includes a regression test.
2014-05-19 16:14:47 -07:00
Andrew White
5460591f02 Make URL escaping more consistent
1. Escape '%' characters in URLs - only unescaped data
   should be passed to URL helpers

2. Add an `escape_segment` helper to `Router::Utils`
   that escapes '/' characters

3. Use `escape_segment` rather than `escape_fragment`
   in optimized URL generation

4. Use `escape_segment` rather than `escape_path`
   in URL generation

For point 4 there are two exceptions. Firstly, when a route uses wildcard
segments (e.g. *foo) then we use `escape_path` as the value may contain '/'
characters. This means that wildcard routes can't be optimized. Secondly,
if a `:controller` segment is used in the path then this uses `escape_path`
as the controller may be namespaced.

Fixes #14629, #14636 and #14070.
2014-04-20 10:11:38 +01:00
Andrew White
d017e92e1d Use a custom route vistor for optimized route generation
Using a Regexp to replace dynamic segments in a path string is fraught
with difficulty and can lead to odd edge cases like #13349. Since we
already have a parsed representation of the path it makes sense to use
that to generate an array of segments that can be used to build an
optimized route's path quickly.

Tests on a simple route (e.g. /posts/:id) show a speedup of 35%:
https://gist.github.com/pixeltrix/8261932

Calculating -------------------------------------
    Current Helper:       5274 i/100ms
    New Helper:           8050 i/100ms
-------------------------------------------------
    Current Helper:     79263.6 (±3.7%) i/s -     395550 in   4.997252s
    New Helper:        153464.5 (±4.9%) i/s -     772800 in   5.047834s

Tests on a more complex route show even an greater performance boost:
https://gist.github.com/pixeltrix/8261957

Calculating -------------------------------------
    Current Helper:       2367 i/100ms
    New Helper:           5382 i/100ms
-------------------------------------------------
    Current Helper:     29506.0 (±3.2%) i/s -     149121 in   5.059294s
    New Helper:         78815.5 (±4.1%) i/s -     398268 in   5.062161s

It also has the added benefit of fixing the edge cases described above.

Fixes #13349
2014-01-05 00:36:25 +00:00
thedarkone
2dea0dd099 Replace global Hash with TS::Cache. 2013-09-28 19:19:07 +02:00
Rafael Mendonça França
3cdeac8cb7 No need the else clause 2013-09-24 14:14:04 -03:00
Rafael Mendonça França
9357e5e383 Use join to concat the both side of the AST
Onf of the sides can be nil and it will raise a Conversion error
2013-09-24 14:13:51 -03:00
Bogdan Gusiev
5c224de9e1 Rewrite journey routes formatter for performance 2013-08-28 11:13:11 +03:00
Charlie Somerville
5e356de271 store a symbol directly inside DISPATCH_CACHE for extra roflscale 2013-06-30 11:31:36 +10:00
Andrew White
86cf7a2d16 Use custom visitor class for optimized url helpers
Rather than trying to use gsub to remove the optional route segments,
which will fail with nested optional segments, use a custom visitor
class that returns a empty string for group nodes.

Closes #9524
2013-03-03 19:18:01 +00:00
Francesco Rodriguez
eb493f5ac8 update AD::Journey to follow Rails coding conventions 2012-12-20 15:42:39 -05:00
Francesco Rodriguez
a36ae63d07 :nodoc: Journey because is not part of the public API [ci skip] 2012-12-19 19:24:25 -05:00
Andrew White
56fee39c39 Integrate Journey into Action Dispatch
Move the Journey code underneath the ActionDispatch namespace so
that we don't pollute the global namespace with names that may
be used for models.

Fixes rails/journey#49.
2012-12-19 22:13:08 +00:00