Ruby-gnome2's effects on garbage collection time

Hi all,

I’ve created two little demo applications that demonstrate how loading
the ruby-gnome2 bindings (without even using them) seems to have an
extremely detrimental effects on Ruby’s garbage collection time.

==============================================
A test program NOT using ruby-gnome2 bindings:

module ObjectSpace
def self.object_count(base_class = Object)
count = 0
each_object(base_class) { count += 1 }
return count
end
end

Toss some junk in the trunk

trunk = []
strs = (‘a’…‘z’).to_a
100.times do
trunk << (1…1000).collect { strs[rand(strs.size)] +
strs[rand(strs.size)] } # …random combinations…
puts “#{ObjectSpace.object_count} objects, #{start = Time.now ;
GC.start ; Time.now - start} GC time, #{ObjectSpace.object_count}
remain”
end

==============================================
Output:

1436 objects, 0.001289 GC time, 1424 remain

5432 objects, 0.002776 GC time, 5430 remain

100527 objects, 0.032424 GC time, 100525 remain

Note 0.0028 for 5k objects, 0.032 seconds for 100k objects

==============================================
Now, a new program using ruby-gnome2 bindings:

module ObjectSpace
def self.object_count(base_class = Object)
count = 0
each_object(base_class) { count += 1 }
return count
end
end

require ‘gtk2’

No junk, no trunk, just the bindings loaded

5.times do
puts “#{ObjectSpace.object_count} objects, #{start = Time.now ;
GC.start ; Time.now - start} GC time, #{ObjectSpace.object_count}
remain”
end

==============================================
Output:

11639 objects, 0.015278 GC time, 5168 remain
5170 objects, 0.018248 GC time, 5167 remain
5169 objects, 0.063149 GC time, 5167 remain
5169 objects, 0.060721 GC time, 5167 remain
5169 objects, 0.060337 GC time, 5167 remain

First of all, we’re seeing many thousand new objects before using the
library at all. This increases the time for every future GC run, so it
would be nice to reduce this.

But more importantly, with the GTK bindings loaded, only 5k objects
takes 0.06 seconds to GC. It’s almost twice as long as GC’ing 100k
objects without the GTK bindings loaded!

And this is before creating a single GTK widget…

This issue makes doing any sort of animation in a Ruby/GTK app
tremendously frustrating, as even a lowly 24fps requires doing a frame
every 0.04 seconds, and right from the start a Ruby/GTK app’s GC
operation pauses the entire app for 0.06 seconds. (And with a full GTK
GUI loaded and around 16k objects, a Ruby/GTK app’s GC time reaches 0.2
seconds!)

Any ideas as to why the ruby-gnome2 bindings have this effect and how we
can reduce/eliminate it?

Cheers,
-Ian