Skip to content

Conversation

@scivola
Copy link

@scivola scivola commented Feb 4, 2020

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)

@agardiner
Copy link
Owner

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

@scivola
Copy link
Author

scivola commented Feb 5, 2020

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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants