Extracto de la transcripción automática del vídeo realizada por YouTube.
- Hey everyone, can you hear me okay? Good? Rock on, I think we'll go ahead and get started. So yes, The Hitchhiker's Guide to Ruby GC. I, like Justin, speak very quickly, so if I do speak, I get going, I get excited, cause Ruby's exciting and garbage collections is cutting, if I start talking way too fast, you guys could just kinda like, I don't know like, some kind of, something, yeah, exactly, please.
That'd be awesome. So, unlike Justin, however, I don't have any TenX insights for you. I do make silly jokes like Aaron does, but unlike Aaron, I'm not gonna offer you life changing insights into the Ruby virtual machine. My talk is in fact, literally garbage, or about garbage.
Speaking of, did you guys hear about this controversy about the show Dirty Jobs? Maybe it was just me, basically I guess it has something to do with the huge number of microservices, that they're employing. Thank you, somebody laughed at it, alright good.
Good, good. I also don't like enjoy my puns like nearly as much as Aaron does, so I'm just gonna put a line through that. I'm not gonna do that anymore. Anyway, alright cool. I should say I'm learning a lot. That was a terrible joke. I'm learning a lot at this conference, I'm learning a lot at RubyConf, and I'm trying to apply it immediately.
Gary had a great talk about ideology and belief and it's one of those things that I'm sort of trying to internalize. But you know, it's hard, right? We don't know what we don't know, and even when we know it, sometimes we are unable to disarm ourselves. So this is my first time giving this talk.
This is actually my second talk ever. I spoke earlier this year at a RailsConf. So I'm going to try to confront my own impostordom and also channel Aaron and not die. And also, you'll see that my nervousness manifests in obnoxious slide transitions, so there's that.
The Condé Nast entertainment folks actually are all using Ruby and Rails. So we are hiring, I feel obligated to say that we're hiring. And you might be interested, sort of, by this strange hash, and why is it a hash and not an object, like a person. new? And that is foreshadowing, so you will see.
There's a lot of literary devices in this talk. So, also obligatory, self promotion. I wrote the Ruby curriculum on Code Academy a couple years ago, and I also wrote this book called Ruby Wizardry. It's for kids ages 8-12. There's a really great birds of a feather organized by Jay McGavren who actually is doing a talk on method lookup later in this very room, so I highly encourage you to go to that talk as well.
And if you're interested in learning Ruby or teaching Ruby, kids Ruby, nouns please come see me after the show. And I am, so no starch has been delightful and is offering a 40% off so if anyone does want the book RUBYCONF2015, and it'll be 40% off I think for the week.
Garbage collection, so there's a lot of mythology around GC and GC tuning and sort of how it all works, it's actually not as bad as it seems. And for those not familiar the don't panic! Is kind of like emblazoned in large friendly letters on the cover of the Hitchhiker's Guide to the Galaxy.
This also as much for my benefit as yours. So, part zero, cause you know this is a computer type conference and we should start at zero. Ruby is not slow. Okay yes, sort of, sometimes depending, it can be. But not for the reasons that you think. So people will say okay well my Ruby program is slow it must be a database thing.
Or it must be there's some superlinear crazy four-deep nested loop and I'm doing something bananas in there that I shouldn't be doing. Or Ruby's an interpreted language and can't possibly be fast and we should all be using Go or Java or something. And so really what I've found is that when Ruby programs slow down these aren't always or often the culprits.
The object space in GC is actually a rich part of the language. Not surprisingly, when you have a lot of richness there's a lot of nuance and performance bugs can hide in there. These things are true, that are on the screen. They sort of do make some operations slower than you know Java or compiled language.
But the reason that we have all this for better and for worse is cause everything is an object. Not everything you know blocks, we're not objects but, you get the idea. So let's take some time and talk about the history of garbage collection in Ruby. First we're talking about MRI, CRuby, we're not talking about Rubinius or JRuby, which have different garbage collectors, I'd wanted to include them in this talk but unfortunately I only have so much time and they ended up on the cutting room floor.
I also don't know nearly as much about them, but if you are interested in Rubinius or JRuby or have some cool stuff to share please come find me. I make make comparisons to these alternate implementations if the comparisons make sense so they might kind of make guest appearances but by and large the talk is about MRI.
So let's talk about Ruby 1. 8. 7. 1. 8. 7 uses tracing,as opposed to say reference counting. GC and GC traces our sort of like, you're looking for reachable objects in the object grab. So if by traversing objects I can get to one that object is reachable, and great.
That should not be collected there are still references to it. As demonstrated in the graph. And if they're not reachable if an object is unreachable it is eligible for collection. 1. 8. 7 uses very simple mark & sweep mark & sweep was invented by, John McCarthy that's right.
It's not Alexander Graham Link, for LISP in 1959 and it's astounding that Ruby had gotten, had gone so far with just simple mark & sweep. Garbage collection, and garbage collection works this way in mark & sweep. Ruby will allocate some amount of memory, we'll talk about details in a little bit.
When there's no more free memory, Ruby says okay great, I'm gonna go through I'm gonna look for all of the active objects that I can find, I'm gonna mark them as active, and then anything that's inactive I can sweep onto a new list and that's where I'll go when I need more stuff.
So this is what Ruby is doing. This was a fun animation, I like the arrows moving. Anyway, the important thing to realize though when you're marking & sweeping and marking & sweeping and having a great time is that everything stops. Because reachability in the object graph can change from you know, when you are marking and then sweeping.
It can change while the program is executing and it does change while the program is executing. So in order to mark & sweep the collector has to stop the world. So if you hear people talking about stop the world garbage collection. major garbage collection this is what they're talking about.
Everything stops, Ruby marks, sweeps, everything's great and then continues execution. So in 1. 9. 3 we got some improvements. We got lazy mark & sweep. And this is an improvement because it increases or rather reduces the pause time by saying okay I'm actually just going to sweep in phases.
It doesn't really do anything to the amount of time you spend collecting garbage but if you say I'm gonna garbage collect and it's gonna take half a second, and I'm gonna do it like ten times instead of one second and doing it five times, you know you don't get these unacceptable hangtimes while garbage collection is happening.
[ ... ]
Nota: se han omitido las otras 3.670 palabras de la transcripción completa para cumplir con las normas de «uso razonable» de YouTube.