a63ae913df
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 |
||
---|---|---|
.. | ||
app | ||
bin | ||
lib | ||
test | ||
.eslintrc | ||
.gitignore | ||
actionview.gemspec | ||
CHANGELOG.md | ||
karma.conf.js | ||
MIT-LICENSE | ||
package.json | ||
Rakefile | ||
README.rdoc | ||
rollup.config.js | ||
rollup.config.test.js | ||
RUNNING_UJS_TESTS.rdoc | ||
RUNNING_UNIT_TESTS.rdoc |
= 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