Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize ERB::Util.html_escape more than CGI.escapeHTML for template engines #27

Merged
merged 3 commits into from
Nov 4, 2022

Conversation

k0kubun
Copy link
Member

@k0kubun k0kubun commented Nov 3, 2022

https://bugs.ruby-lang.org/issues/19102

Benchmark

require 'benchmark/ips'
require 'erb'

class << ERB::Util
  def html_escape_old(s)
    CGI.escapeHTML(s.to_s)
  end
end

Benchmark.ips do |x|
  s = 'hello world'
  x.report('before') { ERB::Util.html_escape_old(s) }
  x.report('after')  { ERB::Util.html_escape(s) }
  x.compare!
end
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux]
Warming up --------------------------------------
              before     1.066M i/100ms
               after     1.879M i/100ms
Calculating -------------------------------------
              before     10.615M (± 0.3%) i/s -     53.320M in   5.023083s
               after     18.742M (± 0.4%) i/s -     93.929M in   5.011847s

Comparison:
               after: 18741747.6 i/s
              before: 10615137.1 i/s - 1.77x  (± 0.00) slower

@k0kubun k0kubun force-pushed the erb-escape branch 5 times, most recently from 81d2c01 to a260c2f Compare November 3, 2022 07:38
@k0kubun k0kubun changed the title Set up a C extension Optimize ERB::Util.html_escape more than CGI.escapeHTML for template engines Nov 4, 2022
@k0kubun k0kubun marked this pull request as ready for review November 4, 2022 07:06
@k0kubun k0kubun merged commit ecebf80 into ruby:master Nov 4, 2022
@k0kubun k0kubun deleted the erb-escape branch November 4, 2022 07:07
ext/erb/erb.c Show resolved Hide resolved
@eregon
Copy link
Member

eregon commented Nov 26, 2022

Please see https://bugs.ruby-lang.org/issues/19102#note-4
Specifically, could you build the C extension only for CRuby?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants