

Garbage Collection and the Ruby Heap - tmm1
http://timetobleed.com/garbage-collection-slides-from-la-ruby-conference/

======
leftnode
I'm not fluent in Ruby whatsoever, but I think we need more content like this
on HN. Incredibly informative and in depth. I probably won't ever learn Ruby
in depth, but I love reading about this type of stuff, learned a lot.

Thanks for the link.

~~~
ice799
thanks, glad you liked the slides.

------
cullenking
Was this a slidestack from a bit ago? I remember reading a slidestack of yours
a couple months back on the same topic, and found it VERY informative.

In any event, keep up the free education! I've learned alot going through your
site. Oh, and thanks for some great ruby libraries!

~~~
tmm1
This a new presentation specifically about the MRI GC, but it covers some of
the same tools mentioned in our Debugging Ruby and Threaded Awesome talks

------
mrduncan
Seriously excellent slides.

Any chance of a video of this talk being released? I'd love some commentary
from you guys.

~~~
ice799
yup, it was recorded. not sure when the video will be out, but i'll tweet it
or something as soon as i hear.

------
kevingadd
Very cool, detailed slides.

I think his notes demonstrate how wildly the 'optimal' settings for a
scripting runtime can vary based on use case - 500K slots in a slab makes
perfect sense for rails, but 10K also makes pretty good sense for running ruby
from the command line to execute a tiny script.

One thing that caught my eye - I think according to slide 52, at startup a
rails app is using over 3625840 bytes of heap just to represent newline nodes
generated from source code? Am I interpreting the data right, or is he just
counting the actual nodes and not the RVALUEs attached to them? Kind of funny
to think about optimizing memory usage in a rails app by stripping out
superfluous newlines.

~~~
tmm1
You're right, there's about 90k NEWLINE nodes on the heap, and at 40 bytes a
piece that's taking up about 3.6mb of slots on the heap that could be used by
other ruby objects instead.

Unfortunately, removing newlines from your codebase will not help since
NODE_NEWLINE is used for separators like semicolons as well.

Ruby 1.9 gets rid of NODE_NEWLINE altogether by adding a NEWLINE flag to the
next node instead. A similar patch will be in the next release of REE.

------
darkhelmetlive
I always learn so much from you and Damato.

~~~
ice799
glad you liked the slides.

------
chuhnk
Whoa extremely informative slides, thanks for those. Alot of stuff in there I
had no idea about. I love learning.

------
wingo
Sigh. Does anyone have a PDF link?

~~~
tmm1
<http://dl.dropbox.com/u/635/gc-export.pdf>

------
kristianp
It's a pity memprof doesn't support 32-bit linux yet. I would like to try out
the method in the slides on my 32 bit machine.

~~~
ice799
working on it.

------
jcnnghm
If you haven't, tune the garbage collector for rails. By tuning, I was able to
improve the performance of my production application by about 60%.

~~~
munctional
Can you elaborate a bit on this? Did you simply patch the GC? I've seen Evan
Weaver's post ([http://blog.evanweaver.com/articles/2009/04/09/ruby-gc-
tunin...](http://blog.evanweaver.com/articles/2009/04/09/ruby-gc-tuning/)) on
it, but that's it.

~~~
tmm1
GC tuning is easy with REE, you can set environment variables to change the
behavior of the mark and sweep collector. See slides 50-53 for more info.

~~~
munctional
Thanks for the info! I'll check out REE again.

------
jpr
Ruby is known as the slowest and memoryhungriest language in common use today,
is there any reason why people should know how it achieves that? How does this
advance the state of the art?

~~~
FooBarWidget
Uh what? Are you saying some like "X has problem Y, why should anybody study
problem Y"?

> and memoryhungriest language in common use today

I think you've never heard of Perl.

~~~
telemachos
I didn't realize that Perl was memory intensive compared with Ruby (or other
comparable languages more generally).

Any links for that? (Not trolling: I use both Perl and Ruby day to day, and
I'm curious. I certainly haven't noticed significant differences in memory
usage. Speed certainly - Perl being faster in many cases.)

~~~
sreque
[http://shootout.alioth.debian.org/u32/benchmark.php?test=all...](http://shootout.alioth.debian.org/u32/benchmark.php?test=all&lang=yarv&lang2=perl).
With the exception of one benchmark ruby's memory is about the same as perl's.
As for speed usage, ruby is no more than twice as slow as perl for most
benchmarks. It does poorly on pidigits because there aren't gmp bindings
available for ruby 1.9, and it does significantly worse on regex-dna because
perl's regex library is much higher quality.

Both are so much slower than C that a 2x difference is insignificant.

~~~
FooBarWidget
Benchmarks don't say anything when it comes to real memory usage. In my
experience Perl is a lot more memory hungry than Ruby. All the data structures
take so much memory. Defining a single, empty function eats 1.5 KB (!) of
memory. I had a Perl program of about 30k lines, and it ate 25 MB during
startup, most of which is consumed just by storing the Perl optree. During
runtime memory usage would jump to 35 MB as it loads all kinds of data into
hash tables and stuff.

------
jakedouglas
These slides are _ILL_ bro.

~~~
munctional
Avoiding local slang when writing is also "ill", my brother.

