Skip to main content
gamedev.net
🔒 Locked

[Ruby] Garbage Collection Stutter

Started by Uphoreum Sep 9, 2010 at 1:34 AM 1 replies 1.6k views
Original Post
Uphoreum
Uphoreum
I'm playing around with Ruby and trying to see if it's viable to make small games with. A pretty major issue I've run into is that the garbage collection runs about once a second and causes a severe pause. I've confirmed that it's the GC because the stutter goes away if I disable it.

I was thinking I could manually enable/disable the GC so that it would only run occasionally, but I'm guessing that just means really long pauses occasionally rather than short ones frequently.

Are there any ways to optimize so that collection is less frequent other than allocating less objects? I don't think I can do much less allocating than I already am.

Also, is this particularly bad in Ruby or is it noticeably bad in all garbage collected languages?
rip-off
rip-off
Quote:

Also, is this particularly bad in Ruby or is it noticeably bad in all garbage collected languages?

I believe Ruby has a notably poor implementation when it comes to performance, which is a pity as it is a rather charming language otherwise. I believe the recent 1.9 versions have replaced the old interpreter with a bytecode implementation, but from some light Googling I can't find much information on any GC updates.

Ruby's performance isn't indicative of general GC performance. Of particular note are the Java and .Net runtimes, which feature advanced parallel collection algorithms that can, for certain use cases, outperform C-style memory management. Any weaknesses in Ruby certainly stem from the specific implementation.

I can't give this a thorough review right now but this looks promising.

Quote:

I was thinking I could manually enable/disable the GC so that it would only run occasionally, but I'm guessing that just means really long pauses occasionally rather than short ones frequently.

You could try it out. Disable it during the core game, re-enable it at level transitions or any other natural pauses. You might run it occasionally if the frame time is low enough, but certainly have a mechanism to avoid it when you're struggling to meet your frame deadlines.

It would be interesting to see whether memory buildups become an issue, one problem with Ruby is a lot of features that make the language nice probably involve "hidden" allocations.
Uphoreum
Uphoreum
Yea, 1.9 added a lot of performance enhancements -- but the GC is still mark and sweep.

I tried disabling the GC, but memory builds up really quickly. I guess you could try to completely avoid allocating anything temporary (that you would just free in C++) in the main loop, but when you start managing memory like this it kind of ruins a big part of Ruby's (or another memory managed language) benefits.

It looks like you need to use a different Ruby implementation if you want to do this, such as JRuby, but that adds a whole other layer of dependencies.

I think I'm going to call Ruby unsuitable in it's current version and play with Python or Java as alternative languages.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.