aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/routing
Commit message (Collapse)AuthorAgeFilesLines
...
* avoid calling `scope` on `defaults` methodsAaron Patterson2015-08-101-3/+6
|
* let the `controller` method push / pop the stackAaron Patterson2015-08-101-11/+5
| | | | | since `controller` and `controller_scope` were the same, just combine them
* remove another call to `scope`Aaron Patterson2015-08-101-3/+4
|
* remove dead codeAaron Patterson2015-08-101-12/+0
| | | | | This method isn't used internally, isn't tested, isn't documented. We should delete it.
* avoid is_a? callsAaron Patterson2015-08-101-1/+5
| | | | | add a predicate method so that we can avoid is_a? calls on the resource object.
* avoid another call to `scope`Aaron Patterson2015-08-101-1/+1
| | | | | calling `scope` isn't cheap, so try to call cheaper methods that do the same thing for those particular parameters (in this case `path_scope`)
* push `with_scope_level` up so resource_scope doesn't knowAaron Patterson2015-08-101-25/+27
| | | | | `resource_scope` should just put resource scopes on the stack, and doesn't need to know what a `scope_level` is.
* reuse the same frame so we don't need a singleton hashAaron Patterson2015-08-101-2/+1
| | | | | We just want to augment the scope level, not the frame itself, so just copy the frame to the new scope object.
* add a null node at the top of the stackAaron Patterson2015-08-101-13/+9
| | | | this gives us an easier way to iterate the stack
* remove `@nesting` ivarAaron Patterson2015-08-101-9/+21
| | | | | The same information is stored in the `@scope` linked list, so just get it from there.
* pass `shallow` in to the resource constructorAaron Patterson2015-08-101-10/+5
| | | | this lets us remove the setter and make the Resource object Read-Only
* we have the resource on the stack, so just use itAaron Patterson2015-08-101-1/+1
| | | | | We don't need to ask `scope` for the resource because we already have it right here.
* Remove wrong commentRafael Mendonça França2015-08-091-1/+0
| | | | | This method raises conditionally not always so we should not documment as it always raise.
* Remove the conditional since it is done in the methodRafael Mendonça França2015-08-091-4/+4
|
* Execute the block when the controller doesn't existRafael Mendonça França2015-08-091-0/+1
| | | | | We should return when the contoller key is not present or if the controller doesn't exist and we didn't raised an error.
* Name the argument according with its jobRafael Mendonça França2015-08-091-2/+2
| | | | Related with dc1b937db780155089fce522f03d340e62f5df36
* push `scope` calls up one frameAaron Patterson2015-08-091-5/+13
| | | | | | eliminates calling `scope` in one method, pushes the other calls up one frame. This goes a little way towards eliminating the internal calls to `scope`.
* remove useless hashAaron Patterson2015-08-081-2/+2
| | | | we don't really need this hash.
* stop calling `scope` internallyAaron Patterson2015-08-082-13/+24
| | | | | | | we need to get a grip on what `scope` actually does. This commit removes some of the internal calls to `scope`. Eventually we should add public facing methods that provide the API that `scope` is trying to accomplish.
* remove useless conditionalAaron Patterson2015-08-081-1/+1
| | | | | | `prepare_params!` would raise an exception if `params` wasn't initialized, so it must always be available. Remove the existence conditional from the `controller` method.
* eliminate assignment in conditionalAaron Patterson2015-08-081-1/+3
| | | | | The method we called already has the conditional we need. Just add an else block so that we don't need two tests.
* Remove `defaults` hash from `Dispatcher`Aaron Patterson2015-08-082-9/+9
| | | | | | | `Dispatcher` doesn't need to hold on to the defaults hash. It only used the hash to determine whether or not it should raise an exception if there is a name error. We can pass that in further up the stack and alleviate Dispatcher from knowing about that hash.
* eliminate runtime conditionalAaron Patterson2015-08-081-10/+9
| | | | | | We know in advance whether the object is a dispatcher or not, so we can configure the Constraints object with a strategy that will call the right method.
* whitespaceAaron Patterson2015-08-081-3/+3
|
* remove the setter from `Scope`Aaron Patterson2015-08-081-4/+0
| | | | it isn't used.
* Merge pull request #21167 from AaronLasseigne/use_each_keyKasper Timm Hansen2015-08-081-1/+1
|\ | | | | replace each with each_key when only the key is needed
| * replace each with each_key when only the key is neededAaron Lasseigne2015-08-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Using each_key is faster and more intention revealing. Calculating ------------------------------------- each 31.378k i/100ms each_key 33.790k i/100ms ------------------------------------------------- each 450.225k (± 7.0%) i/s - 2.259M each_key 494.459k (± 6.3%) i/s - 2.467M Comparison: each_key: 494459.4 i/s each: 450225.1 i/s - 1.10x slower
* | Allow a custom dispatcher to be provided to routing.Xavier Shay2015-08-071-2/+3
| |
* | Move `controller_reference` and `controller_class_names` to protectedXavier Shay2015-08-071-2/+6
| | | | | | | | scope so that they are available to subclasses.
* | the request class is never changed, so just use it directly in the method bodyAaron Patterson2015-08-071-3/+3
|/
* Merge pull request #21061 from yui-knk/refactor/route_setRafael Mendonça França2015-08-061-4/+2
|\ | | | | Remove duplicated `Array#to_param`
| * Remove duplicated `Array#to_param`yui-knk2015-08-011-4/+2
| | | | | | | | | | `Array#to_param` is defind in active_support/core_ext/object/to_query.rb, so we can call `to_param` if value is_a Array.
* | Use #start_with? and #[] for speedBenjamin Quorning2015-08-021-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | While the readability may be slightly worse, the speed improvement is significant: Twice as fast when there's no leading "/" to remove, and over 4 times as fast when there is a leading "/". Benchmark: require 'benchmark/ips' def match(controller) if controller if m = controller.match(/\A\/(?<controller_without_leading_slash>.*)/) m[:controller_without_leading_slash] else controller end end end def start_with(controller) if controller if controller.start_with?('/'.freeze) controller[1..-1] else controller end end end Benchmark.ips do |x| x.report("match") { match("no_leading_slash") } x.report("start_with") { start_with("no_leading_slash") } x.compare! end Benchmark.ips do |x| x.report("match") { match("/a_leading_slash") } x.report("start_with") { start_with("/a_leading_slash") } x.compare! end Result (Ruby 2.2.2): Calculating ------------------------------------- match 70.324k i/100ms start_with 111.264k i/100ms ------------------------------------------------- match 1.468M (± 7.1%) i/s - 7.314M start_with 3.787M (± 3.5%) i/s - 18.915M Comparison: start_with: 3787389.4 i/s match: 1467636.4 i/s - 2.58x slower Calculating ------------------------------------- match 36.694k i/100ms start_with 86.071k i/100ms ------------------------------------------------- match 532.795k (± 4.7%) i/s - 2.679M start_with 2.518M (± 5.8%) i/s - 12.566M Comparison: start_with: 2518366.8 i/s match: 532794.5 i/s - 4.73x slower
* | [ci skip]yui-knk2015-08-011-0/+15
| | | | | | | | | | | | | | | | | | | | | | Add descriptions about `ActiveRecord::Base#to_param` to * `ActionDispatch::Routing::Base#match` * Overriding Named Route Parameters (guide) When passes `:param` to route definision, always `to_param` method of related model is overridden to constructe an URL by passing these model instance to named_helper.
* | Avoid hash duplication by skipping mutationschneems2015-07-301-2/+2
| | | | | | | | | | | | If we don't mutate the `recall` hash, then there's no reason to duplicate it. While this change doesn't get rid of that many objects, each hash object it gets rid of was massive. Saves 888 string objects per request, 206,013 bytes (thats 0.2 mb which is kinda a lot).
* | Only allocate new string when neededschneems2015-07-301-1/+7
| | | | | | | | | | | | Instead of calling `sub` on every link_to call for controller, we can detect when the string __needs__ to be allocated and only then create a new string (without the leading slash), otherwise, use the string that is given to us. Saves 888 string objects per request, 35,524 bytes.
* | Freeze a string in comparatorschneems2015-07-301-1/+1
| | | | | | | | Saves 888 string objects per request.
* | Reduce hash allocations in route_setschneems2015-07-291-1/+1
| | | | | | | | | | | | | | | | When generating a url with `url_for` the hash of arguments passed in, is dup-d and merged a TON. I wish I could clean this up better, and might be able to do it in the future. This change removes one dup, since it's literally right after we just dup-d the hash to pass into this constructor. This may be a breaking, change but the tests pass...so :shipit: we can revert if it causes problems This change buys us 205,933 bytes of memory and 887 fewer objects per request.
* | Decrease route_set allocationsschneems2015-07-291-3/+7
|/ | | | | | | | In handle_positional_args `Array#-=` is used which allocates a new array. Instead we can iterate through and delete elements, modifying the array in place. Also `Array#take` allocates a new array. We can build the same by iterating over the other element. This change buys us 106,470 bytes of memory and 2,663 fewer objects per request.
* Merge pull request #20751 from repinel/remove-unnecessary-dupRafael Mendonça França2015-07-201-1/+1
|\ | | | | Remove unnecessary `dup` from Mapper `add_route`
| * Remove unnecessary `dup` from Mapper `add_route`Roque Pinel2015-07-011-1/+1
| | | | | | | | | | | | | | The `dup` was introduced by c4106d0c08954b0761726e0015ec601b7bc7ea4b to work around a frozen key. Nowadays, the string is already being duplicated by the `tr` in `options[:action] ||= action.tr('-', '_')` and later joined into a new string in `name_for_action`.
* | Freeze string literals when not mutated.schneems2015-07-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I wrote a utility that helps find areas where you could optimize your program using a frozen string instead of a string literal, it's called [let_it_go](https://github.com/schneems/let_it_go). After going through the output and adding `.freeze` I was able to eliminate the creation of 1,114 string objects on EVERY request to [codetriage](codetriage.com). How does this impact execution? To look at memory: ```ruby require 'get_process_mem' mem = GetProcessMem.new GC.start GC.disable 1_114.times { " " } before = mem.mb after = mem.mb GC.enable puts "Diff: #{after - before} mb" ``` Creating 1,114 string objects results in `Diff: 0.03125 mb` of RAM allocated on every request. Or 1mb every 32 requests. To look at raw speed: ```ruby require 'benchmark/ips' number_of_objects_reduced = 1_114 Benchmark.ips do |x| x.report("freeze") { number_of_objects_reduced.times { " ".freeze } } x.report("no-freeze") { number_of_objects_reduced.times { " " } } end ``` We get the results ``` Calculating ------------------------------------- freeze 1.428k i/100ms no-freeze 609.000 i/100ms ------------------------------------------------- freeze 14.363k (± 8.5%) i/s - 71.400k no-freeze 6.084k (± 8.1%) i/s - 30.450k ``` Now we can do some maths: ```ruby ips = 6_226k # iterations / 1 second call_time_before = 1.0 / ips # seconds per iteration ips = 15_254 # iterations / 1 second call_time_after = 1.0 / ips # seconds per iteration diff = call_time_before - call_time_after number_of_objects_reduced * diff * 100 # => 0.4530373333993266 miliseconds saved per request ``` So we're shaving off 1 second of execution time for every 220 requests. Is this going to be an insane speed boost to any Rails app: nope. Should we merge it: yep. p.s. If you know of a method call that doesn't modify a string input such as [String#gsub](https://github.com/schneems/let_it_go/blob/b0e2da69f0cca87ab581022baa43291cdf48638c/lib/let_it_go/core_ext/string.rb#L37) please [give me a pull request to the appropriate file](https://github.com/schneems/let_it_go/blob/b0e2da69f0cca87ab581022baa43291cdf48638c/lib/let_it_go/core_ext/string.rb#L37), or open an issue in LetItGo so we can track and freeze more strings. Keep those strings Frozen ![](https://www.dropbox.com/s/z4dj9fdsv213r4v/let-it-go.gif?dl=1)
* | Make AC::Parameters not inherited from HashPrem Sichanugrist2015-07-151-0/+4
|/ | | | | | | | This is another take at #14384 as we decided to wait until `master` is targeting Rails 5.0. This commit is implementation-complete, as it guarantees that all the public methods on the hash-inherited Parameters are still working (based on test case). We can decide to follow-up later if we want to remove some methods out from Parameters.
* [ci skip] Improve the url_for documentationRoque Pinel2015-07-011-3/+19
| | | | | | | | | Clarify the `url_for` usage in mailers. Re-add the documentation about `url_for` and Route's path parameters, first introduced by 5c4f1859970d06228a0b67cad6d4486c1526ef2a. This was reported on #15097 and until it is decided to deprecate it or not, I believe the documentation should exist.
* Revert "Merge pull request #20584 from arthurnn/fix_url"Arthur Neves2015-06-171-8/+4
| | | | | | | | This reverts commit 0b3397872582f2cf1bc6960960a6393f477c55e6, reversing changes made to 56d52e3749180e6c1dcf7166adbad967470aa78b. As pointed out on the PR, this will hide development mistakes too, which is not ideal.
* Catch InvalidURIError on bad paths on redirect.Arthur Neves2015-06-161-4/+8
| | | | | Handle URI::InvalidURIError errors on the redirect route method, so it wont raise a 500 if a bad path is given.
* Revert changes related with api apps in RouteWrapperJorge Bejar2015-06-111-11/+1
| | | | | See the following commit to have context about this change: https://github.com/rails/rails/commit/757a2bc3e3e52a5d9418656928db993db42b741b
* Routes resources avoid :new and :edit endpoints if api_only is enabledJorge Bejar2015-06-112-12/+35
|
* Refactor internal? to query internal_controller? and internal_asset? methodsSantiago Pastorino2015-06-111-1/+11
|
* remove unused codeAaron Patterson2015-06-081-2/+2
|