mirror of https://github.com/rails/rails
b8191db909
When working in a large rails app, I noticed in a flamegraph of a particular request that ~68ms was spent in the `xml_name_escape` method. I also ran an allocation tracer, which showed this method at the top of the list for String allocations. This patch updates this method to avoid 3 String allocations: - 2 allocations saved by using gsub! instead of gsub - 1 allocation saved by concatenating to an existing string instead of allocating a new output string For a rough benchmark in our rails app, I wrote a test with an allocation tracer around rendering a small view component. - 244 String allocations before this change - 228 String allocations from switching to gsub! - 220 String allocations with this full patch A ~10% reduction in String allocations in a real-world example seemed like a good justification for this small change. |
||
---|---|---|
.. | ||
bin | ||
lib | ||
test | ||
.gitignore | ||
CHANGELOG.md | ||
MIT-LICENSE | ||
README.rdoc | ||
Rakefile | ||
activesupport.gemspec |
README.rdoc
= Active Support -- Utility classes and Ruby extensions from Rails Active Support is a collection of utility classes and standard library extensions that were found useful for the Rails framework. These additions reside in this package so they can be loaded as needed in Ruby projects outside of Rails. You can read more about the extensions in the {Active Support Core Extensions}[https://edgeguides.rubyonrails.org/active_support_core_extensions.html] guide. == Download and installation The latest version of Active Support can be installed with RubyGems: $ gem install activesupport Source code can be downloaded as part of the Rails project on GitHub: * https://github.com/rails/rails/tree/main/activesupport == License Active Support 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