aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/routing/route_set.rb
Commit message (Collapse)AuthorAgeFilesLines
* 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.
* stop calling `scope` internallyAaron Patterson2015-08-081-6/+1
| | | | | | | 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-081-7/+7
| | | | | | | `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.
* 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
* | 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.
* 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)
* Routes resources avoid :new and :edit endpoints if api_only is enabledJorge Bejar2015-06-111-6/+16
|
* remove unused codeAaron Patterson2015-06-081-2/+2
|
* we only care about methods that the request object responds toAaron Patterson2015-06-081-2/+1
| | | | | matches? should only deal with methods on the request object, so lets just filter out anything that the request object doesn't respond to
* extract required_defaults from the conditions hash before constructing the routeAaron Patterson2015-06-081-2/+3
| | | | | this way we can remove the strange "respond_to?" conditional in the `matches?` loop
* sort_by instead of sortYang Bo2015-04-081-1/+1
| | | | | | it is avoid sort errot within different and mixed keys. used `sort_by` + `block` to list parameter by keys. keep minimum changes
* pass a config to the route setAaron Patterson2015-03-051-3/+19
| | | | | This way we can get the relative_url_root from the application without setting another global value
* Drop request class from RouteSet constructor.Aaron Patterson2015-03-041-4/+7
| | | | | If you would like to use a custom request class, please subclass and implemet the `request_class` method.
* Merge pull request #18775 from yasyf/issue_5122Rafael Mendonça França2015-03-031-1/+3
|\ | | | | | | Fallback to RAILS_RELATIVE_URL_ROOT in `url_for`
| * Fallback to RAILS_RELATIVE_URL_ROOT in `url_for`.Yasyf Mohamedali2015-02-241-1/+3
| | | | | | | | | | | | Fixed an issue where the `RAILS_RELATIVE_URL_ROOT` environment variable is not prepended to the path when `url_for` is called. If `SCRIPT_NAME` (used by Rack) is set, it takes precedence.
* | be optimistic about missing route keysAaron Patterson2015-03-021-13/+15
| | | | | | | | | | | | | | this patch makes errors slightly more expensive when someone is missing a route key, but in exchange it drops 4 allocations per `url_for` call. Since missing a route key is an error, optimizing for the non-error path seems like a good trade off
* | use arg size for parallel iterationAaron Patterson2015-03-021-1/+1
| | | | | | | | | | we already know the length of the args, so we can use that length for parallel iteration and cut down on allocations for `url_for` calls.
* | ask the routes objects for its Rack env keyAaron Patterson2015-03-021-0/+2
|/ | | | | | this centralizes the logic for determining the script name key and drops object allocations when calling `engine_script_name` (which is called on each `url_for`).
* Cache url_helpers instead of creating each timeEvan Phoenix2015-02-191-1/+3
| | | | | | | | | This has 2 effects: 1. RoutesProxy is CRAZY faster because it's no longer creating a new Module each time method_missing is hit. 2. It bypasses an existing bug in ruby that makes `class << obj` unsafe to be used in threading contexts.
* Skip url_helpers instead of caching, speed up integration testseileencodes2015-02-121-8/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We shouldn't cache if it's not absolutely necessary. Removes route caching and instead skips using the `url_helpers` is the integration test session doesn't require it. Benchmark ips on integration and controller index method tests below. Without any caching or changes to `#url_helpers`: ``` Calculating ------------------------------------- INDEX: Integration Test 71.000 i/100ms INDEX: Functional Test 99.000 i/100ms ------------------------------------------------- INDEX: Integration Test 728.878 (± 8.0%) i/s - 3.692k INDEX: Functional Test 1.015k (± 6.7%) i/s - 5.148k Comparison: INDEX: Functional Test: 1015.4 i/s INDEX: Integration Test: 728.9 i/s - 1.39x slower ``` With caching on `#url_helpers`: ``` Calculating ------------------------------------- INDEX: Integration Test 74.000 i/100ms INDEX: Functional Test 99.000 i/100ms ------------------------------------------------- INDEX: Integration Test 752.377 (± 6.9%) i/s - 3.774k INDEX: Functional Test 1.021k (± 6.7%) i/s - 5.148k Comparison: INDEX: Functional Test: 1021.1 i/s INDEX: Integration Test: 752.4 i/s - 1.36x slower ``` Afer removing the caching and bypassing the `url_helpers` when not necessary in the session: ``` Calculating ------------------------------------- INDEX: Integration Test 87.000 i/100ms INDEX: Functional Test 97.000 i/100ms ------------------------------------------------- INDEX: Integration Test 828.433 (± 6.4%) i/s - 4.176k INDEX: Functional Test 926.763 (± 7.2%) i/s - 4.656k Comparison: INDEX: Functional Test: 926.8 i/s INDEX: Integration Test: 828.4 i/s - 1.12x slower ```
* `RouteSet` should not be listed in the public API [ci skip]Sean Griffin2015-02-031-10/+10
| | | | | The use of `# :startdoc:` inside of the class was overriding the outer-most `# :nodoc:`, causing it to be listed in the documented API.
* Cache `url_helpers` separately for mailersAndrew White2015-02-011-44/+50
| | | | | The commit 3b63780 re-introduced url helper caching but we need to cache a separate module for Action Mailer without paths.
* Cache `url_helpers`eileencodes2015-02-011-42/+44
| | | | | | `url_helpers` used to be memoized. This was lost in a refactoring and this PR adds it back. We noticed this while investigating why integration tests are slower than controller tests.
* Preserve default url options when generating URLsTekin Suleyman2015-01-281-3/+4
| | | | | Fixes an issue that would cause default_url_options to be lost when generating URLs with fewer positional arguments than parameters in the route definition.
* improve performance of integration tests.Aaron Patterson2015-01-271-1/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I found delegate to be a bottleneck during integration tests. Here is the test case: ```ruby require 'test_helper' class DocumentsIntegrationTest < ActionDispatch::IntegrationTest test "index" do get '/documents' assert_equal 200, response.status end end Minitest.run_one_method(DocumentsIntegrationTest, 'test_index') StackProf.run(mode: :wall, out: 'stackprof.dump') do 3000.times do Minitest.run_one_method(DocumentsIntegrationTest, 'test_index') end end ``` Top of the stack: ``` [aaron@TC integration_performance_test (master)]$ stackprof stackprof.dump ================================== Mode: wall(1000) Samples: 23694 (7.26% miss rate) GC: 1584 (6.69%) ================================== TOTAL (pct) SAMPLES (pct) FRAME 7058 (29.8%) 6178 (26.1%) block in Module#delegate 680 (2.9%) 680 (2.9%) ActiveSupport::PerThreadRegistry#instance 405 (1.7%) 405 (1.7%) ThreadSafe::NonConcurrentCacheBackend#[] 383 (1.6%) 383 (1.6%) Set#include? 317 (1.3%) 317 (1.3%) ActiveRecord::Base.logger 281 (1.2%) 281 (1.2%) Rack::Utils::HeaderHash#[]= 269 (1.1%) 269 (1.1%) ActiveSupport::Notifications::Fanout::Subscribers::Evented#subscribed_to? 262 (1.1%) 262 (1.1%) block (4 levels) in Class#class_attribute 384 (1.6%) 246 (1.0%) block (2 levels) in Class#class_attribute ``` According to @eileencodes's tests, this speeds up integration tests so that they are only 1.4x slower than functional tests: Before: INDEX: Integration Test: 153.2 i/s - 2.43x slower After: INDEX: Integration Test: 275.1 i/s - 1.41x slower
* Remove unneeded requiresRafael Mendonça França2015-01-041-1/+0
| | | | These requires were added only to change deprecation message
* Remove deprecated usage of string keys in URL helpersRafael Mendonça França2015-01-041-17/+1
|
* Remove deprecated `only_path` option on `*_path` helpersRafael Mendonça França2015-01-041-28/+1
|
* Remove deprecate `*_path` helpers in email viewsRafael Mendonça França2015-01-041-25/+4
|
* Remove deprecated `NamedRouteCollection#helpers`Rafael Mendonça França2015-01-041-8/+0
|
* allow URL helpers to work with optional scopesAlex Robbin2014-12-131-1/+1
|
* Fix handling of positional url helper arguments when format is falseTatiana Soukiassian2014-12-131-2/+8
| | | | | | | There is no need to subtract one from the path_params size when there is no format parameter because it is not present in the path_params array. Fixes #17819.
* Merge pull request #17862 from lucasmazza/lm-hide-actionRafael Mendonça França2014-12-021-0/+2
| | | | `_generate_paths_by_default` should always be private.
* Pass symbol as an argument instead of a blockErik Michaels-Ober2014-11-291-2/+2
|
* sets script_name to always be a string.JONBRWN2014-11-251-1/+1
| | | | | | | | | | | Closes #17615 #17616 when script_name is nil in the options hash, script_name is set to nil. options = {script_name: nil} script_name = options.delete(:script_name) {‘’} # => nil Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>