summaryrefslogtreecommitdiff
path: root/lib/rubygems/package.rb
diff options
context:
space:
mode:
authorSamuel Giddins <[email protected]>2023-09-18 18:51:15 -0700
committergit <[email protected]>2023-12-11 23:14:58 +0000
commit505715ddf17e004d184c0b71afb40a31e2e8c98e ()
tree483d4f9f86cf2628d822e4c0b6ce0c76e478524a /lib/rubygems/package.rb
parent4a94ce8569c9399bd286d943ff35f6f3a25ed1b6 (diff)
[rubygems/rubygems] Fewer allocations in gem installation
For now, on a small rails app I have hanging around: ``` ==> memprof.after.txt <== Total allocated: 872.51 MB (465330 objects) Total retained: 40.48 kB (326 objects) ==> memprof.before.txt <== Total allocated: 890.79 MB (1494026 objects) Total retained: 40.40 kB (328 objects) ``` Not a huge difference in memory usage, but it's a drastic improvement in total number of allocations. Additionally, this will pay huge dividends once https://.com/ruby/zlib/pull/61 is merged, as it will allow us to completely avoid allocations in the repeated calls to readpartial, which currently accounts for most of the memory usage shown above. https://.com/rubygems/rubygems/commit/f78d45d927
-rw-r--r--lib/rubygems/package.rb24
1 files changed, 13 insertions, 11 deletions
@@ -357,18 +357,21 @@ EOM
def digest(entry) # :nodoc:
algorithms = if @checksums
- @checksums.keys
- else
- [Gem::Security::DIGEST_NAME].compact
end
- algorithms.each do |algorithm|
- digester = Gem::Security.create_digest(algorithm)
-
- digester << entry.readpartial(16_384) until entry.eof?
- entry.rewind
@digests[algorithm][entry.full_name] = digester
end
@@ -437,8 +440,6 @@ EOM
FileUtils.rm_rf destination
- mkdir_options = {}
- mkdir_options[:mode] = dir_mode ? 0o755 : (entry.header.mode if entry.directory?)
mkdir =
if entry.directory?
destination
@@ -447,7 +448,7 @@ EOM
end
unless directories.include?(mkdir)
- FileUtils.mkdir_p mkdir, **mkdir_options
directories << mkdir
end
@@ -707,6 +708,7 @@ EOM
def verify_gz(entry) # :nodoc:
Zlib::GzipReader.wrap entry do |gzio|
gzio.read 16_384 until gzio.eof? # gzip checksum verification
end
rescue Zlib::GzipFile::Error => e