rails/activesupport
Ian C. Anderson b8191db909 Reduce Striing allocations in `xml_name_escape`
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.
2022-08-16 20:27:25 +00:00
..
bin Remove `AS::Multibyte`'s unicode table 2018-02-20 03:58:22 +09:00
lib Reduce Striing allocations in `xml_name_escape` 2022-08-16 20:27:25 +00:00
test Improve failure safety for `RedisCacheStore#delete_multi` 2022-08-04 18:53:10 +03:00
.gitignore Clean up and consolidate .gitignores 2018-02-17 14:26:19 -08:00
CHANGELOG.md Add `skip_nil:` support to `ActiveSupport::Cache::Store#fetch_multi` 2022-07-20 17:02:25 -05:00
MIT-LICENSE Bump license years to 2022 [ci-skip] 2022-01-01 15:22:15 +09:00
README.rdoc Rename master to main in all code references 2021-01-19 20:46:33 +00:00
Rakefile allow running each test with pure ruby path/to/test.rb 2019-12-18 08:49:19 -06:00
activesupport.gemspec Enable connection pooling by default for MemCacheStore and `RedisCacheStore` 2022-06-07 11:40:17 +03:00

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