rails/activesupport/lib
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
..
active_support Reduce Striing allocations in `xml_name_escape` 2022-08-16 20:27:25 +00:00
active_support.rb Fix next Rails version in intended removal 2022-04-03 14:35:21 +02:00