aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/lib/action_view/helpers/asset_tag_helper.rb
Commit message (Collapse)AuthorAgeFilesLines
...
* Cut string allocations in content_tag_stringschneems2015-07-291-1/+1
| | | | | | content_tag's first argument is will generate a string with an html tag so `:a` will generate: `<a></a>`. When this happens, the symbol is implicitly `to_s`-d so a new string is allocated. We can get around that by using a frozen string instead which This change buys us 74,236 bytes of memory and 1,855 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)
* image_tag raises an error if size is passed with height and/or widthMike Stone2015-04-241-0/+7
|
* correct output of auto_discovery_link_tag [ci skip]yuuji.yaginuma2015-04-041-1/+1
|
* Allow to pass a string value to size option in `image_tag` and `video_tag`Mehdi Lahmam2015-02-161-0/+1
| | | | This makes the behavior more consistent with `width` or `height` options
* Uppercase HTML in docs.Hendy Tanata2014-08-081-2/+2
| | | | [skip ci]
* [ci skip] /javascript/ ~> JavaScriptAditya Kapoor2014-06-171-1/+1
|
* Revert "Correct Documentation for asset_tag_helpers"Rafael Mendonça França2014-06-041-17/+16
| | | | | | | | | | This reverts commit c22a253d1a72602331db1eba3e91bc945eff2346. Reason: Our documentation assumes the assets are in the proper place and we are using the default Rails stack. With the default Rails stack and the assets being in the correct place the assets helpers uses the `/assets` prefix.
* correct doc for (audio|video)_tag [ci skip]Aditya Kapoor2014-05-271-10/+10
|
* Correct Documentation for asset_tag_helpersAditya Kapoor2014-05-261-15/+16
|
* rewrites the API docs of favicon_link_tag [ci skip]Xavier Noria2014-04-291-9/+16
| | | | Motivated by #14907.
* Change favicon_link_tag helper mimetype from image/vnd.microsoft.icon to ↵glorieux2014-04-211-3/+3
| | | | | | | | image/x-icon. Although the official IANA-registered MIME type for ICO files is image/vnd.microsoft.icon, registered in 2003, it was submitted to IANA by a third party and is not recognized by Microsoft products. The MIME type image/x-icon should be used since is the one recognized by the major browsers on the market.
* Fix typo in image_tag documentationAdrien2014-01-071-1/+1
| | | image_tag only supports :alt and :size as additional keys, not three.
* duplication removed(DRY)abhishek2013-12-181-16/+10
|
* allow video_tag to accept `size` as `Number` for square shaped videosKuldeep Aggarwal2013-12-181-4/+10
|
* Typo and grammatical fixes [ci skip]Akshay Vishnoi2013-12-021-1/+1
|
* unnecessary checking of `size` with `second regex` if matched with first oneKuldeep Aggarwal2013-11-271-2/+5
|
* Merge pull request #12788 from kylefritz/patch-1Rafael Mendonça França2013-11-061-2/+2
| | | | | | rdoc: favicon source shouldn't begin with a slash to reference asset pipeline resource [ci skip] Conflicts: actionview/lib/action_view/helpers/asset_tag_helper.rb
* Fixed return strings in documentationJoseph Zidell2013-10-031-3/+3
|
* Fixed typo in documentationJoseph Zidell2013-10-031-3/+3
|
* Add "extname" option to javascript_include_tagNathan Stitt2013-08-031-3/+6
| | | | | | | | | | | | ActionView::Helpers.asset_path is where the logic for javascript_include_tag resides. It takes an extname option for specifying the extension or false to not append it. This exposes that option to javascript_include_tag. Without the option files that didn't end with ".js" would get the extension appended to them. This broke JST templates and other file types that should be interpreted as JavaScript but who's file extension isn't ".js"
* Move actionpack/lib/action_view* into actionview/libPiotr Sarnacki2013-06-201-0/+316