csv-diff-report icon indicating copy to clipboard operation
csv-diff-report copied to clipboard

minimal requirement to use CGI.escapeHTML

Open scivola opened this issue 4 years ago • 2 comments

We need to require only cgi/escape to use CGI.escapeHTML.

This change save memory usage about 265 KB and load time about ten milliseconds.

require "objspace"

GC.start
before = ObjectSpace.memsize_of_all
require "cgi"
after = ObjectSpace.memsize_of_all
puts "about %d KB" % ((after - before).fdiv(1024).round)
# => 269 KB
require "objspace"

GC.start
before = ObjectSpace.memsize_of_all
require "cgi/escape"
after = ObjectSpace.memsize_of_all
puts "about %d KB" % ((after - before).fdiv(1024).round)
# => 4 KB

(Ruby 2.7.0)

scivola avatar Feb 04 '20 03:02 scivola

Thanks for the PR, but unfortunately, this change does not work for older versions of Ruby, which are still a target for this project.

agardiner avatar Feb 05 '20 08:02 agardiner

How about this? cgi/escape was introduced at Ruby 2.3.0. cgi/utils is available instead of cgi/escape for older Ruby versions (even for Ruby 1.9).

cgi/utils is larger than cgi/escape, but is smaller than entire cgi.

scivola avatar Feb 05 '20 12:02 scivola