Skip to content

Instantly share code, notes, and snippets.

@raggi
Created February 21, 2011 00:30
Show Gist options
  • Save raggi/836470 to your computer and use it in GitHub Desktop.
Save raggi/836470 to your computer and use it in GitHub Desktop.
Show the effects of rubygems source_index load on in-memory string size
RAW = true # flip me to make the logs readable, for interests sake.
def write_strings_to fn
open(fn, 'w+') do |f|
ObjectSpace.each_object do |o|
f.send((RAW ? :print : :puts), o) if o.class == String
end
end
end
file = %w[strings_no_gems.log strings_gems_no_gc.log strings_gems.log]
GC.start
write_strings_to file[ 0 ]
require 'rubygems'
Gem.source_index.find { |_,spec| }
write_strings_to file[ 1 ]
GC.start
write_strings_to file[ 2 ]
last = File.size file[ 0 ]
file.each do |fn|
cur = File.size(fn).to_f
pcge = cur / last * 100
puts "#%26s: %15d bytes, change: %8d%" % [fn, cur, pcge]
last = cur
end
@raggi
Copy link
Author

raggi commented Feb 21, 2011

Before RubyGems 1.6:

#       strings_no_gems.log:            2214 bytes, change:      100%
#    strings_gems_no_gc.log:         5173464 bytes, change:   233670%
#          strings_gems.log:         4795559 bytes, change:       92%

After RubyGems 1.6:

#       strings_no_gems.log:            2214 bytes, change:      100%
#    strings_gems_no_gc.log:         1663044 bytes, change:    75114%
#          strings_gems.log:         1368931 bytes, change:       82%

@raggi
Copy link
Author

raggi commented Feb 21, 2011

N.B. You may need to run: https://gist.github.com/836462 to get the above effect (after installing rubygems 1.6/master).

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