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. |
||
---|---|---|
.. | ||
active_support | ||
active_support.rb |