rails/actionview
Nicolò Rebughini a63ae913df Do not allocate the first path character in asset helper
In asset heavy views, the asset_path helper might be called a lot of
times. When checking the first character of the source element with []
we allocate a string each time just to check it against ?/.

By using String#start_with? we can avoid this step and go a bit faster.

This is the code I used to measure the change:

```

require "bundler/inline"

ROOT_STRING = '/'
TEST_PATH = "/some/path"

gemfile(true) do
  source "https://rubygems.org"

  gem "benchmark-ips"
end

Benchmark.ips do |x|
  x.report("source[0]") do
   TEST_PATH[0] != ROOT_STRING
  end

  x.report("source.start_with?") do
   TEST_PATH.start_with?(ROOT_STRING)
  end

  x.compare!
end
```

Warming up --------------------------------------
           source[0]   905.322k i/100ms
  source.start_with?     1.541M i/100ms
Calculating -------------------------------------
           source[0]      9.012M (± 0.7%) i/s -     45.266M in   5.022969s
  source.start_with?     15.395M (± 0.4%) i/s -     77.030M in   5.003691s

Comparison:
  source.start_with?: 15394807.0 i/s
           source[0]:  9012304.9 i/s - 1.71x  slower
2023-03-20 17:32:42 +01:00
..
app Ignore certain data-* attributes in rails-ujs when element is contenteditable 2023-03-13 12:13:42 -07:00
bin Use frozen string literal in actionview/ 2017-07-24 11:53:43 +03:00
lib Do not allocate the first path character in asset helper 2023-03-20 17:32:42 +01:00
test Fix rails-ujs tests not being linted 2023-03-17 00:56:59 -04:00
.eslintrc Convert rails-ujs to ES2015 modules 2022-07-07 21:52:08 -04:00
.gitignore use Karma as the test runner for the UJS tests 2022-12-31 23:03:09 +11:00
actionview.gemspec Merge pull request #45546 from skipkayhil/decaffeinate-ujs 2022-09-14 18:59:58 -04:00
CHANGELOG.md Remove deprecated support to instance variables as locals to partials 2023-03-03 00:38:39 +00:00
karma.conf.js add comments to explain the test rollup and karma config files 2023-01-04 00:08:47 +11:00
MIT-LICENSE Remove Copyright years (#47467) 2023-02-23 11:38:16 +01:00
package.json Fix rails-ujs tests not being linted 2023-03-17 00:56:59 -04:00
Rakefile add explaination of extracting from the ENCODED env var 2022-12-31 23:03:09 +11:00
README.rdoc Use stable guides link for package READMEs 2023-02-04 09:01:00 +09:00
rollup.config.js Convert rails-ujs to ES2015 modules 2022-07-07 21:52:08 -04:00
rollup.config.test.js add comments to explain the test rollup and karma config files 2023-01-04 00:08:47 +11:00
RUNNING_UJS_TESTS.rdoc use Karma as the test runner for the UJS tests 2022-12-31 23:03:09 +11:00
RUNNING_UNIT_TESTS.rdoc Fix typos and add a few suggestions 2017-11-28 19:27:43 +01:00

= Action View

Action View is a framework for handling view template lookup and rendering, and provides
view helpers that assist when building HTML forms, Atom feeds and more.
Template formats that Action View handles are ERB (embedded Ruby, typically
used to inline short Ruby snippets inside HTML), and XML Builder.

You can read more about Action View in the {Action View Overview}[https://guides.rubyonrails.org/action_view_overview.html] guide.

== Download and installation

The latest version of Action View can be installed with RubyGems:

  $ gem install actionview

Source code can be downloaded as part of the Rails project on GitHub:

* https://github.com/rails/rails/tree/main/actionview


== License

Action View is released under the MIT license:

* https://opensource.org/licenses/MIT


== Support

API documentation is at

* https://api.rubyonrails.org

Bug reports for the Ruby on Rails project can be filed here:

* https://github.com/rails/rails/issues

Feature requests should be discussed on the rails-core mailing list here:

* https://discuss.rubyonrails.org/c/rubyonrails-core