summaryrefslogtreecommitdiff
path: root/lib/rubygems/stub_specification.rb
diff options
context:
space:
mode:
authorSamuel Giddins <[email protected]>2023-09-18 14:07:41 -0700
committergit <[email protected]>2023-09-19 07:25:51 +0000
commit4023637d20e4f9c4c4806e0fb27f868eea7612b3 ()
tree1282c43f9412b198487c352ba6d6eb75ceaca502 /lib/rubygems/stub_specification.rb
parentcea7e6ecca99ae7730ea5ac44ed15f62b1599664 (diff)
[rubygems/rubygems] Reduce allocations for stub specifications
This helps with memory usage during application boot time ``` ==> memprof.after.txt <== Total allocated: 1.43 MB (18852 objects) Total retained: 421.12 kB (4352 objects) ==> memprof.before.txt <== Total allocated: 2.43 MB (28355 objects) Total retained: 469.69 kB (5425 objects) ``` See https://bugs.ruby-lang.org/issues/19890 about the readline allocations https://.com/rubygems/rubygems/commit/d7eb66eee3
-rw-r--r--lib/rubygems/stub_specification.rb19
1 files changed, 12 insertions, 7 deletions
@@ -35,7 +35,7 @@ class Gem::StubSpecification < Gem::BasicSpecification
def initialize(data, extensions)
parts = data[PREFIX.length..-1].split(" ", 4)
- @name = parts[0].freeze
@version = if Gem::Version.correct?(parts[1])
Gem::Version.new(parts[1])
else
@@ -113,14 +113,19 @@ class Gem::StubSpecification < Gem::BasicSpecification
Gem.open_file loaded_from, OPEN_MODE do |file|
file.readline # discard encoding line
- stubline = file.readline.chomp
if stubline.start_with?(PREFIX)
- extensions = if /\A#{PREFIX}/ =~ file.readline.chomp
- $'.split "\0"
- else
- StubLine::NO_EXTENSIONS
- end
@data = StubLine.new stubline, extensions
end
rescue EOFError