aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch
Commit message (Collapse)AuthorAgeFilesLines
* Freeze string literals when not mutated.schneems2015-07-196-13/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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)
* Stop using deprecated `render :text` in testPrem Sichanugrist2015-07-171-1/+1
| | | | | | | | | This will silence deprecation warnings. Most of the test can be changed from `render :text` to render `:plain` or `render :body` right away. However, there are some tests that needed to be fixed by hand as they actually assert the default Content-Type returned from `render :body`.
* Oops! :bomb:Akira Matsuda2015-07-171-1/+1
|
* "warning: instance variable @routes not initialized"Akira Matsuda2015-07-171-1/+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.
* Rack implements `redirect?` so we don't need itAaron Patterson2015-07-141-3/+0
| | | | Rack [already implements `redirect?` on the response object](https://github.com/rack/rack/blob/1569a985e17d9caaf94d0e97d95ef642c4ab14ba/lib/rack/response.rb#L141) so we don't need to implement our own.
* use a lookup table for `assert_response`Aaron Patterson2015-07-131-3/+8
| | | | | | | | We shouldn't depend on specific methods imlemented in the TestResponse subclass because the response could actually be a real response object. In the future, we should either push the aliased predicate methods in TestResponse up to the real response object, or remove them
* move buffer caching on to the bufferAaron Patterson2015-07-131-3/+11
|
* Merge pull request #20842 from TheBlasfem/removed_usage_lines_docsClaudio B.2015-07-111-1/+1
|\ | | | | Removed usage line docs [ci skip]
| * added description instead of remove usage [ci skip]Julio Lopez2015-07-111-1/+1
| |
* | Merge pull request #17102 from matthewd/load-interlockAaron Patterson2015-07-101-0/+21
|\ \ | | | | | | Concurrent load interlock (rm Rack::Lock)
| * | Fix the Interlock middlewareMatthew Draper2015-07-091-5/+14
| | | | | | | | | | | | | | | We can't actually lean on Rack::Lock's implementation, so we'll just copy it instead. It's simple enough that that's not too troubling.
| * | Soften the lock requirements when eager_load is disabledMatthew Draper2015-07-091-0/+12
| | | | | | | | | | | | | | | We don't need to fully disable concurrent requests: just ensure that loads are performed in isolation.
* | | start disconnecting the parameter parser from the instanceAaron Patterson2015-07-101-3/+3
| | | | | | | | | | | | | | | pass in the instance variable to start decoupling the meat of the parser from the instance of the middleware
* | | drop a conditional by always assigningAaron Patterson2015-07-101-6/+5
| |/ |/| | | | | | | We will always make an assignment to the env hash and eliminate a conditional
* | drop runtime conditionals in parameter parsingAaron Patterson2015-07-091-13/+9
| | | | | | | | | | If we only deal with proc objects, then we can eliminate type checking in the parameter parsing middleware
* | assign the cookie hash on request allocationAaron Patterson2015-07-081-1/+1
| | | | | | | | this prevents mutations from being available globally
* | add a new constructor for allocating test requestsAaron Patterson2015-07-082-9/+9
| |
* | make `env` a required parameterAaron Patterson2015-07-081-1/+1
| |
* | pass the starting env and session to build_requestAaron Patterson2015-07-081-1/+1
| |
* | let the superclass build the request and responseAaron Patterson2015-07-081-1/+1
| | | | | | | | | | We should leverage the request / response objects that the superclass has already allocated for us.
* | remove useless `new` implementationAaron Patterson2015-07-081-4/+0
|/
* pass cookies from the jar in the HTTP_COOKIE headereileencodes2015-07-071-9/+4
| | | | | we should be pushing the cookies in via headers rather than maintaining some object and "recycling" it.
* Send cookies with requesteileencodes2015-07-072-1/+5
|
* Merge pull request #13897 from gmalette/nested-parameter-filtering-2Arthur Nogueira Neves2015-07-061-7/+17
|\ | | | | Allow filtering params based on parent keys
| * Allow filtering params based on parent keysGuillaume Malette2015-06-221-7/+17
| | | | | | | | | | | | | | | | | | | | Add the possibility to only filter parameters based on their full path instead of relying on the immediate key. config.filter_parameters += ['credit_card.code'] { 'credit_card' => { 'code' => '[FILTERED]' }, 'source' => { 'code' => '<%= puts 5 %>' } }
* | Refactor cookie_jar to decouple it from request objecteileencodes2015-07-051-7/+3
| | | | | | | | | | | | This change decouples `cookie_jar` allocation from the request object. We need this for moving controller tests to integration tests so we can access the `cookie_jar` object separately.
* | [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.
* | Merge pull request #19431 from hmarr/head-routingRafael Mendonça França2015-06-221-1/+2
|\ \ | |/ |/| Respect routing precedence for HEAD requests
| * Respect routing precedence for HEAD requestsHarry Marr2015-03-201-1/+2
| | | | | | | | | | | | | | Fixes the issue described in #18764 - prevents Rack middleware from swallowing up HEAD requests that should have been matched by a higher-precedence `get` route, but still allows Rack middleware to respond to HEAD requests.
* | 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.
* | Merge pull request #20584 from arthurnn/fix_urlArthur Nogueira Neves2015-06-161-4/+8
|\ \ | | | | | | Catch InvalidURIError on bad paths on redirect.
| * | 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.
* | | Fix the comment about attr_reader of headers [ci skip]Mehmet Emin İNAÇ2015-06-161-1/+1
|/ /
* | remove `header=` on the response object.Aaron Patterson2015-06-152-13/+14
| | | | | | | | | | | | People should be free to mutate the header object, but not to set a new header object. That header object may be specific to the webserver, and we need to hide it's internals.
* | set the default charset in response initializeAaron Patterson2015-06-151-4/+12
| | | | | | | | | | this way we don't have to mutate the instance (as much) when writing a rack response
* | ActionDispatch::SSL should keep original header's behaviorFumiaki MATSUSHIMA2015-06-141-1/+1
| | | | | | | | | | | | `ActionDispatch::SSL` changes headers to `Hash`. So some headers will be broken if there are some middlewares on ActionDispatch::SSL and if it uses `Rack::Utils::HeaderHash`.
* | don't hold a reference to `env` in the options objectAaron Patterson2015-06-131-13/+11
| | | | | | | | | | I want to decouple Rails from the rack ENV as much as possible. We should try to keep as few references to the env as possible
* | Handle param-parsing errors from Rack in ExceptionWrapperGrey Baker2015-06-121-1/+3
| |
* | 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 Unneeded ApiPublicExceptions middleware, PublicExceptions already ↵Santiago Pastorino2015-06-111-46/+0
| | | | | | | | does the work
* | Adhere to Rails convention for private indentationSantiago Pastorino2015-06-111-21/+20
| |
* | Add ApiPublicException middlewareSantiago Pastorino2015-06-111-0/+47
| |
* | Change the `index` arg of `ActionDispatch::Static#new` to a kwargYuki Nishijima2015-06-111-4/+3
| |
* | 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-083-8/+8
| | | | | | | | | | this way we can remove the strange "respond_to?" conditional in the `matches?` loop
* | Add missing documentation for ActionDispatch::Request::Session [ci skip]Mehmet Emin İNAÇ2015-06-071-0/+33
| |