You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This call to `Unicode.tidy_bytes` has been introduced 10 years
ago in rails#19992 but this pull
request has been merged by mistake and was supposed to be reverted.
Semantically it makes no sense to deal with invalid strings at that
layer, and performance wise it impose a massive overhead.
```
ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +YJIT +PRISM [arm64-darwin24]
Warming up --------------------------------------
current 504.509k i/100ms
no_tidy 1.749M i/100ms
Calculating -------------------------------------
current 5.607M (± 1.0%) i/s (178.34 ns/i) - 28.253M in 5.038946s
no_tidy 21.792M (± 0.6%) i/s (45.89 ns/i) - 110.211M in 5.057658s
Comparison:
current: 5607354.4 i/s
no_tidy: 21791597.8 i/s - 3.89x faster
ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +YJIT +PRISM [arm64-darwin24]
Warming up --------------------------------------
current 261.902k i/100ms
no_tidy 518.277k i/100ms
Calculating -------------------------------------
current 2.795M (± 1.3%) i/s (357.72 ns/i) - 14.143M in 5.060105s
no_tidy 5.508M (± 0.2%) i/s (181.55 ns/i) - 27.987M in 5.081000s
Comparison:
current: 2795448.7 i/s
no_tidy: 5508171.9 i/s - 1.97x faster
```
```ruby
require "bundler/inline"
gemfile do
gem "rails"
gem "benchmark-ips"
end
require "active_support/all"
require "active_support/core_ext/erb/util"
module ERB::Util
def self.html_escape_no_tidy(s) # :nodoc:
s = s.to_s
if s.html_safe?
s
else
unwrapped_html_escape(s)
end
end
end
Benchmark.ips do |x|
s = "Hello World"
x.report("current") { ERB::Util.html_escape(s) }
x.report("no_tidy") { ERB::Util.html_escape_no_tidy(s) }
x.compare!(order: :baseline)
end
Benchmark.ips do |x|
s = "Hello World" * 20
x.report("current") { ERB::Util.html_escape(s) }
x.report("no_tidy") { ERB::Util.html_escape_no_tidy(s) }
x.compare!(order: :baseline)
end
```
0 commit comments