Rails World 2026: Closing keynote (Aaron Patterson) Video: https://www.youtube.com/watch?v=t0knYnEYBRo Talk page: https://www.rubyevents.org/talks/closing-keynote-rails-world-2026 Unedited machine transcript, generated with Whisper. It contains recognition errors (names, technical terms). Check the video before quoting. ---- Hello, everybody. Hello. Hello. Yes. Before we get started here, I want to tell you, make a quick announcement. I've started my own Linux distribution. I wanted to share with you booting it up, but I couldn't put a machine on on stage, so I sent it back with the AV folks, so I'm going to have them start up my presentation now, please. Okay. All right. Okay. They're going to boot it up. Okay. Can you open PowerPoint for me? I vibe-coded this, by the way. All right. OK. So I guess let's get going. I'm calling it Aaron XP. The name of this software. It installs in 100 milliseconds. And it's very important for me to get the install time down, because I'm doing that constantly. Wake up in the morning. Install my OS. Get some coffee, install my OS, upgrade Chrome, reinstall the OS. I mean, come on. I think it's funny to... I think it's ironic to make a joke about the financial crisis and then encourage everybody to generate a whole bunch of Rust code without reading it. I'm going to start selling insurance on technical debt, so come see me afterwards if you'd like to buy some. I know everybody here loves using AI. I do too. I love using AI. I love using it to make slop grenades. It's great. Really good. But I want to take a poll of the audience here. Yeah, I'm going to take a poll. Okay. How many of you like receiving slop grenades? Show of hands here. Okay, we got two, three. Ah, a couple dedicated folks in the front here. Great, thank you. Nice to see this. I also got some... Thank you, Amanda, so much for your hard work here. Can we give her a round of applause? Yes. So when she was showing off the records, during this conference. Somebody got a photo of me here in the audience. This is me. I had to tell her this afterwards. And then I was like, now you can't. I'm making this joke. Now you can't say it on stage. It's mine. I'm doing this. Okay. Before I make any more jokes today, I want to do something a little bit serious. I'm going to call out somebody here in the audience, a specific person, and I'm going to embarrass them, and he is right there, Mike D'Alessio. So I don't know if you saw his talk, but Mike posted this. We met over 20 years ago now. He sent an open source pull request to me for Mechanize, a Ruby library at the time, open source community ever since. I even was able to work with him at Shopify for a while. He was actually my boss there. Together we started an organization on GitHub called Sparkle Motion. I am Sparkle. He is Motion in this relationship. What this means is I come up on stage with jazz hands and he actually does work. many open source projects. For example, Nokogiri, maybe you know it. I have seen it in various slides about slow gem installations. We've also worked on the SQLite 3 gem, and he's also very, very active in the Rails security team. But the announcement that I want to make here today is that he is also the newest member of the Rails core team. Thank you. Thank you, Mike. Really, really appreciate your work. I don't know if the website's updated or not yet, but anyway, thank you. I'm looking forward. Thank you so much, and I'm glad you will continue to be active supporting us. Yes. Yes. All right. It's exciting to be here at Rails World, I know many people have made this joke before, but I am also using Claude to generate my slides. So it's great to be here at AI World in Texas. It was cool to learn about how we can use AI, all of us. We can all use AI to become 1,000X programmers. So we can use, all of us here today, we can use AI to become 1,000X programmers. Sorry, hold on, I got a typo. I mean 1,000X programmers. Anyone here? Did anyone here ride the robo-taxis? This is amazing to me. Yes! Yes! If you haven't ridden them yet, I highly suggest that you do. It's really, really fun. But make sure to bring a friend with you because it's way more fun that way. Yes. Okay. Happy Friday. Woo! Happy Friday, everyone. It's always Friday somewhere. My name is Aaron Patterson. I'm also known as Tenderlove. I work on the Ruby and Rails infrastructure team at Shopify, and I help with various things around the team. I work on a lot of stuff there. It is very fun. I also have a cat. This is my cat. You may have seen him here at one of the check-in at the... a passport booth. Today I'm going to be talking about performance, obviously, because that's what I always talk about at presentations. I don't know what else to talk about. I'm going to talk about Ractors, I'm going to talk about ZJIT, and of course I am going to be talking about AI because we are at AI world, so we will be doing that. The reason I'm going to be talking about these things, the important thing is the reason is because this year I have been working on performance and Ractors and ZJIT and also AI. Yes, I am actually repeating these slides because I get very, very nervous when I'm preparing presentations and I will not have enough content for the conference, so I will just add more slides. But yes, this is what I'm going to talk about today. This year, I also wrote a register allocator for ZJIT, and we're not going to talk about it today, I'm just in here because this is the hardest project I've ever worked on, and I'm very, very proud of my work here, and I just wanted to put this here and say I did that, and it was great. So I am proud of myself for doing this. Oh, thank you. I also got a new manager this year, and things are going pretty well with him, I think. I'm not quite sure. one-on-one with him, and I'm going to share the transcript with you today, and hopefully you can help me be the judge of this. So in our very first one-on-one, he said to me, "Aaron, you've only been testing code paths that make errors." And I said, "Oh, well, that is because I am expecting a raise." It's because my code is exceptional. And he was not very pleased with this, I don't think. But I wanted to reassure him, so I said to him, "Don't worry. These meetings only get better. I'll insure it." Yes. So I think things are going well. I'm not sure. I'm going to start my presentation with a quote here. "The purpose of a system is what it does." I've heard this quote many times before, thought about what it meant too much. I don't know. It makes me think, and I don't like doing that, so I didn't really think about it too much. But I guess I brought it up with my manager, and I thought to myself, okay, when I'm trying to understand what a system is for, I need to understand what it does. And since my manager was new here, he said to me, Aaron, what is this system for here that you're working on? does the system do? And he told me to go F myself. I'm kidding. I'm very much kidding here. He would not say that to me. I said its purpose is to raise exceptions. So I'm not sure. I think these one-on-ones are going well. I don't know. I don't know. We'll see you after this. Anyway, I don't particularly like this phrase. And the reason I don't like it is because it's so ambiguous. I think about it. I'm like, okay, well, immediately, I'm like, what does this system do? what does it do? I don't know. So I don't know what the purpose is. And so I'm like, I don't know what the purpose is. I can't figure it out. And to give you an example, my brain is just way too small for this. I can't deal. To give you an example, let's say I traveled back in time with my trusty Nokia 3310. Yes. I'm sure anyone have this phone? Yeah. Heck yeah. I'm sure there's people in here that have never seen this before. is an indestructible phone. It is great. Let's say I traveled back in time with this phone, and I gave it to someone that had never seen cell phones before. They may actually use this as a hammer. So then I wonder, is the purpose of this phone to be a hammer? If you took that phrase that I put before literally, you might say yes. Clearly, they're using it as a hammer, so that is the purpose of this thing. it would be a cell phone. I think the system, what the system does depends on who is actually looking at the system. So when I'm looking at that phone, I see a phone, I will use it as a phone, but when I brought it back in time, the person that sees it there, they see it as a hammer and they will use it as a hammer. So really what it depends on is who is making the observation of that system. So if I could refine the original quote, I would say the purpose of a system is what it does for those that are observing. of said that at Rails World 2026. Yes. So I've been thinking about this a lot because, as I said, I've mostly been working on performance optimizations or code optimizations, and this particular attitude that I'm telling you, this observational attitude, is commonly known among language implementers, and it's known as the as-if rule. There's a rule called the as-if rule, and you can go read about it on Wikipedia. actually codified in the C++ programming language with regard to applying optimizations to code. So we're going to read an excerpt from this from the as-if rule. The as-if rule says, in C++ they are allowed to apply any optimizing transformation to a program during compiling, provided that such optimization make no change in the observable behavior of the program as specified by the standard. So in other words, the compiler is free to make any changes to your code that it as long as the code executes the way that you wrote it, the way that it looks like it should execute. Now, there is kind of an awkward thing in this particular phrase, this particular quote. It says, as specified by the standard, which we don't pretty much have in Ruby. There isn't like a specific standard like C++ has. But let's not worry about that for now. So today, I want to talk about optimizations through the lens of observable behavior. Every optimization has two sides to it. The thing that gets deleted in the optimization and the thing that observes that particular optimization, whoever observes that code. Now, the first one, we're going to look at some examples of these different observers and optimizations and see how they impact each other. So, the first one that I'm going to show you, I guarantee pretty much all of you have done this before, I think. is memoization. This is the very first example. I'm sure we've all written this particular pattern before. We have some function. We know that that function is expensive, but we only need to calculate it once. So we calculate it once and then save it off into an instance variable. I'm pretty sure many folks here have written code similar to this. I know that I have. The only problem with this particular code pattern is that we've baked an assumption into the code. is that this code is only ever observed by one thread at one time. So there's actually a race condition in this code where it could end up that we execute this expensive computation multiple times, but we don't really see that because we have a GVL in Ruby. Now, this is kind of where Ractors come in. Ractors allow us to have true parallel processing in our Ruby code. have changed. We can actually have two threads see this exact code path at the same time. So that means we can have multiples or observers of a particular code path in parallel. Now fortunately, Ractors will actually raise an exception for us in this case. So instead of having a race condition and messing up something in your application, you'll actually get an exception and you have the opportunity to fix it. Now hopefully you saw Andrew's presentation, he talked in detail about this type of stuff, but I'm going to repeat a little bit of it here. So when I say this, though, I don't want this to scare you off and say, well, I should never use this particular pattern. I'm going to show you a couple of examples of the pattern. In the first case, we have multiple Ractors that are accessing this memoized instance variable on the Foo class. And what that means is that we have a race condition on the Foo class, and the nice thing is that R1, this R1 Ractor will actually give us an exception saying, hey, you can't do that. that you need to do this in a thread safe manner. Now, the second case is actually fine. You can see that the pattern is the same. We're able to use it. It's really, really fine to do this. It's just that in the second case, we only have one observer of that particular code path. So it's okay to use this pattern. We just need to make sure that it's isolated to one specific reactor. Now, fortunately, this top pattern of class level instance variables, throughout code bases, and there's actually going to be a way for us to mitigate this or deal with this situation in the upcoming Rails release, and that's with the Active Support Ractors module. With Active Support Ractors module, there's an on main method that allows us to execute certain code on the main Ractor. So if we have an expensive computation and we need that to occur inside of the main Ractor and stash something into a class level instance variable, we can do that. Now, if you saw Andrew's presentation, you'll know that this causes latency in your application, and the reason it causes latency is because if you shuffle lots of computation off to the main Ractor, all of a sudden the main Ractor becomes the bottleneck for your application, and you'll end up seeing increased latency because everybody is contending for that Ractor. So when possible, I highly recommend using the Ractor sharing gem. It's written by Koichi Sasada, the main Ractor author. So hopefully this will work pretty well as Ractor-based code. Actually, not hopefully, it will. So you should use this. It has many different Ractor-safe data structures inside of it. I'm going to share a couple of them. I'm going to Ractor-share a couple of them here. It's got two here that I want to point out that solve this particular problem that we were looking at. First is lock variables, and the second one is tVars. And the one that you choose depends on the throughput that you want with your application. A lock variable will guarantee that a particular computation only occurs once, and the T var allows it to occur one or more a few times basically. So the first one you use when you have a computation which is not idempotent and you need to guarantee it only occurs once, and the second one is when you have a calculation that is idempotent and like maybe it's fine if it does it a couple of times. Plus there are many more data structures in there. And I don't want to scare you away from using these data structures because I think that the way the nature of the way that Rackers are implemented means that even if we use these data structures there won't be any dead locking in our applications and there won't be any thread safety issues in our applications because we'll just get exceptions instead. And the reason I think we shouldn't be too scared of these data structures is that I think that the blast radius is fairly limited. So let's take an example. have a pretend Ractor-based web server. So it just reads a request from the socket in an infinite loop, and then it serves up the request inside of a Ractor. And if you think about the normal request response lifetime of this, we're allocating most of our objects inside of this serve method. So all of our allocations will happen inside of there, and the only time we really need to worry about this is when we touch things on the outside. Now, of course, we do touch things on the outside like constants or configuration values, things of that nature. But I think that the amount of touch points is much lower than we actually think. The other thing I want to talk a little bit about is data observability and how that impacts performance. In Ruby 4.1, it's going to be shipping with a Ractor local garbage collector. So what does this mean? The GC in Ruby is a singleton. So whenever a Ractor needs to allocate an object, it's going to go ask the garbage collector, "Hey, give me an object." And if we have multiple Ractors running in parallel, well, it's pretty clear that we're going to run into a bottleneck here. So we'll try to allocate a bunch of stuff, and then these Ractors are all waiting on the GC to allocate things. So in Ruby 4.1, we'll have a Ractor local garbage collector, which means separate heaps for each Ractor, which will eliminate this particular bottleneck. So each Ractor can go ahead and ask the heap for an object. Now, we might also be able to leverage this to have cheaper garbage collection. So, for example, in our fake web server here, we can create a new reactor on every single request, and then when the request is done, we can just abandon the heap and then continue the process. So, theoretically, we can get cheaper GCs out of this. Now, I wish that was the end of the story, but the story is a bit more complicated than this, and I want to show you an example of why. say we have this producer consumer example in Ruby. I apologize for making you read code. The producer allocates an object in its own heap like this, and then it passes that object to a consumer. So when that happens, the consumer and the producer are both pointing at exactly the same object, and you can see that with the object ID here. two Ractors are able to observe exactly the same object at the same time. So what that means is that when one of these Ractors dies, that doesn't necessarily mean we can throw away the heap, because it could mean that there are other Ractors that are pointing into that heap. So we need some way to reconcile this situation. The way we reconcile it is with a global garbage collector, a global GC, and you can think of this kind of as a major, except that it hopefully occurs less frequently than a major. one more example. In the previous example, we purposely passed an object from one reactor to another, and they were both able to see that object, and I want to show a different example where we're doing it implicitly. So I showed this example at Rails World last year, but I think it's a great example. We have two JSON parses, we're parsing two JSON documents, and then looking at the key in the JSON document, and you'll see here that those keys are exactly the same object. They have the same object ID. We're able to observe there the same object. Now, if we take this code and split it up into multiple Ractors, we'll see that that string hello, it's the same object ID in both Ractors. So both Ractors, those keys are deduplicated among the Ractors, and both Ractors see the same hello string. And what's happening under the hood is that means that we're allocating a hello string one heap, our main Ractor heap, and then the other two Ractors are pointing into that heap. So what's interesting about this example is that it possibly means we're impacting GC performance, but we don't know it. It's happening implicitly. So I want to take a step back for a minute. We've been looking at stuff a little bit deep here. We started this by looking at optimizations that developers do. So we looked at how Ractors add a new observer to the system, of adding new observers. Now, I want to look at the framework and language optimizations, and specifically I want to look at backtracing consistencies. So here we have an example of a save callback. We're using active support callbacks. We're making kind of a fake active record thing here where you can mix this in and then call save, and then you end up with a save callback. And this example code prints the call stack from inside of our save callback. callback. If we imagine the stack trace from this, we can imagine that we'll see first, we'll see the block for run callbacks, then we're going to see the frame for the save method, and since we're running this just from a script, we'll see main as the top level. So let's take this module and we'll mix it into a class, a no callbacks class. So this is kind of our base case here. If we run that, we'll see indeed, stack frames. So let's try it again, but we'll do it with one callback. In this case, we'll set a callback, we'll set a before callback, and look at the backtrace. And we see that, again, there's only three frames here. So that's great, and it's what we expected. Now, we're going to do one more. We're going to do an around callback. If we do that, we'll see that our stack trace is all of a sudden exploded. Now, remember, we didn't change any of the code that was inside of that save method, and all of a sudden, our stack trace is wildly different. Now, as I was looking into this, I thought it was very funny to find this comment in Active Support. I'm going to read it. It says, "As this method is used in many places and often wraps large portions of user code, it has an additional design goal of minimizing its impact on the visible call stack. An exception from inside of before or after callback can be noisy as it likes, but when control is passed smoothly into the supplied block, we want as little evidence as possible that we were here." the as-if rule that we were talking about earlier. So in this case, we are seeing more stack than expected, and this is happening inside of Rails, and I can forgive that because we have application code that is doing more stuff. We added in a round callback, so we kind of know like, yeah, okay, it's doing more work, so of course there's going to be more stack trace. But is it possible to get less stack trace than expected? Do we see that case? We do. But for us, yes, I do like to spend my weekends counting stack frames. I don't think that makes me a loser though. So here we have an example of a missing new stack frame. I'm going to show what this is. So in this code, we have a method one that calls method two, then calls three, which allocates foo, foo calls four from inside of initialize. And the reason I'm doing this is just to make the stack trace a little bit more clear. So if we run this code, we expect to see a stack trace like this. We'll see initialize, new, 3, 2, 1, main. Nothing surprising going on. If we run the code in Ruby 3.4, that's what we see. This is exactly the call, the stack trace that we see in Ruby 3.4. If we run this in Ruby 4.0, we'll see it looks a little bit different. And in fact, in Ruby 4.0, we are missing this class new. It's gone. So what happened to this stack frame? I think we can find some clues. We're going to figure it out here. If we dump the instructions for the three method, I think we'll be able to learn something. So we're going to dump the VM instructions for this particular method. On the top, we have the instruction sequences for Ruby 3.4, and on the bottom, we have the instruction sequences for Ruby 4.0. And the first thing that we can notice from this is that Ruby 4.0 generates a lot more instructions than Ruby 3.4. I'm not going to explain these instructions fully, but the basic change is that we've inlined the initialize call into the new call site. Right there, we did an inline. So if we take those instructions and kind of write them as Ruby code again, on the left here is the code that we wrote, and on the right, is kind of the pseudocode of the instructions that we generated. The pseudocode of the instructions is basically saying, hey, if the new method on foo is the default implementation, then what we're going to do is we're going to allocate a new foo, and then we're going to directly call initialize, and then we're going to return the object. If it's not the default new, then we're going to take a slow path and just call the new method. here because it's just doing more than Ruby 3.4 was doing. The other thing to notice here is that we're actually calling the initialize method from the three method. So before the model was that new, we would call new, new would call initialize, and now we can see here three is directly calling initialize. So it makes sense why that new stack frame is missing. So let's say we have this code. It's our foo class. We print out the stack trace from initialize, before implementing new. So we're going to monkey patch new basically, but it's not like a big deal monkey patch, we're just calling super from inside of it. So here we'll print out the stack trace before three, we'll add new, and then we'll call the method again and print out the stack trace again. If we do that, on the left is our stack trace from the fast path, and on the right is our stack trace from the slow path, and we can see that our call to class new is back. So why did we go through all this trouble? Why do all of this stuff? The reason is because we get faster allocations out of it. This particular example here allocates 70% faster on Ruby 4.0 than it does on Ruby 3.0, and that's without a JIT compiler. So we get really good performance gains out of this particular optimization. So the thing that we deleted in this case was a call frame, and the observers of this would be like caller, debuggers, things that might inspect the stack. So these are the things that we impacted. The thing that we got out of it, though, is we got 70% faster allocations, which I think is a good exchange. And CRuby does this all the time. There are many different places where it does it. I'm going to give another example here really quickly. Here we have an example foo class that implements hash. It prints the stack trace. Whenever something calls hash on it, we trigger a hash computation and it prints a stack trace. So we'd expect these two first calls to have the same stack trace, different stack trace, but the same depth. And if we look at it, the stacks are completely different. Here, we're able to elide the square method in the very left-hand side. So you'll see that that frame is missing, whereas the other two sides show you everything. So CRuby does this all the time. It plays fast and loose with the stack trace. But I think the question is, who cares? Does anybody care about this? Anyone? A few people, okay, I think it's interesting. But actually, that is what I want you to feel. If you actually cared whether or not those things were in the stack frame, then we wouldn't be able to implement these kinds of features. So, that's why I'm very, very glad that most of you are like, I don't care about this. things are like as if gray areas, as if rule gray areas. So the compiler made a change to the code. So execution strictly isn't the same. You can observe a different, but these cases are people, cases where people like don't care. Like they really don't care. So it's fine. And in Ruby and I think most other languages, we need to maintain behavior where it actually matters. So those cases don't actually matter. We're getting performance optimizations and trading for things that don't really matter. So I think these types of optimizations are what I like to call low-risk optimizations, where we change the language behavior, but people in general really don't care. They're low-risk. So next I want to look at some high-risk optimizations, specifically inside of ZJIT. ZJIT is able to make high-risk optimizations because it's able to de-optimize in the case that something unexpected happens. So we're going to look at some of those. ZJIT has two types of intermediate representation internally. We're going to look at these. intermediate representation, aka IR, it's also called IR, has a high-level HR, or HIR, and a low-level IR, or LIR. If you want to try this out at home, you can see the HIR by adding these flags to your Ruby binary. So if you add zjit dump HIR, you can see the output and take a look at it. One of the bets that we make in zjit is that you probably won't redefine methods. Probably not going to do it. we need to know about it because if you do it, we need to behave correctly. So let's say we have an example like this where we allocate a point, then call a method which calls a method on the point. If we dump the HIR for this, it'll look like this and I'm going to highlight a few things inside of this HIR. First, I want to show off, we have a block here. So we can see that this is the compilation, the HIR for the block in five times. that we've inlined get into the block, but we push an inline frame. So we're pushing an inline frame for get, so it's inlined into the block. The next thing I want to show is that we've actually been able to lift this constant 42 down inside of the block. So ZJIT was able to take the code on the left and compile it down to the code on the right. It was able to simplify all of that. But how can ZJIT make such big bets? We might not care if a stack frame is missing, but if your code redefines get or X, you would probably care because now your code isn't behaving the way that you expected it to. It's not following the as-if rule. So if we go back to the HIR output, we'll see a couple of patch point lines. I'm going to highlight those. We have one here. There's a patch point for method redefined on get, and we have another patch point defined here for method redefinition on x. And these patch points don't represent any code. So if you look at the machine code output, there is nothing in the machine code that represents these patch points. They're simply markers. These markers, we use these markers to know where in the machine code to patch. So let's say we have some code like our example from before. In this case, we're going to JIT compile the five times block. and then JIT compile it again. So if we do that, here's an excerpt from the machine code that the JIT generates, and we're going to show before and after invalidation. So this is before invalidation. So when the gets method is invalidated, the JIT compiler will literally overwrite the machine code. So it'll take that test code. We have an invalidation marker that points at the test instruction, and when that method gets redefined, jump instruction, and that jump instruction will jump to an exit code. That exit code will restore all of the VM internals and VM stack, and you'll continue executing your code back on Ruby as a virtual machine. So how do we detect this case? Like, how do we know that you redefined a method? The way we do it is with help from the CRuby implementation. Any time a method gets redefined, we need to invalidate caches anyway, and this is also the perfect point for the JIT compiler invalidate any JIT code. So the JIT compiler can simply track which methods it compiled, and if somebody redefines a method, then it can invalidate any machine code associated with that method. So here we'll say, oh, a method was redefined, we're going to invalidate all of our JIT code for YJIT or ZJIT depending on which one you're using. So method redefinition isn't the only invariant that we track. We also track things like we call basic operations or bops. So for example, the plus method, we need to ensure that plus still means plus. We track constants, so we need to make sure that you don't redefine constants, or that there are trace points, because if you run a trace point, it means that you can observe things that the JIT compiler may have optimized out, and we need to fix that. It won't follow the as-if rule. And there are a bunch of other ones too, and if you want to know about the other ones, please come talk to me afterwards. And as I said, I would talk about AI because this is AI world. of AI. We use it a lot. And unfortunately, I know this is going to disappoint some people, but I mean abstract interpretation. Yay. So if you want to work on some AI, come work on ZJ, please. We would love to have the help. So what is abstract interpretation? Abstract interpretation is when we pretend to run some code. We're going to pretend to run code. And then allow optimizations to fall out from that. So I'm going to show an example to help motivate what this exactly means. On the left here, we have a test server. This is just a test rack application. On the right is our actual, or excuse me, a test server. On the right is our rack application. And then down here on the bottom, we just have a simple method that measures the number of objects that we've allocated, and it tries to serve up about 1,000 fake requests through this rack application. this without a JIT compiler, it'll allocate about a thousand objects. That makes sense because we made about a thousand requests. If we run it with YJIT, we'll see it allocates about the same number of objects. And then if we run this with ZJIT, we'll see that it allocates eight objects. So where are these objects coming from, and how is ZJIT able to remove them? So let's go back to our demo program, and it's pretty clear from the demo these allocations are coming from. We're allocating an array here in the call method with our status headers and body. So, we already saw from the previous example that ZJIT can inline functions. So, what's going on here is ZJIT is taking that call method and inlining it inside of the serve method. So, let's say we did that. We're going to inline it here like this. Now, what I want to do here is I want to say, let's say we take this code and we break it down into more simple pieces. We're going to break it into multiple steps with temporary variables and do this a piece at a time. So we're going to take the status headers and body assignment and break it up. So if we did that, we would end up with something like this, where we've assigned all of these variables to intermediate variables and then we use them like this. I think we can all agree here that the behavior of this program is the same as the previous one, it's just that we have more temporary variables. Here is where abstract interpretation comes in. Our abstract interpreter will walk over this code and pretend to execute it. So we're going to walk through that now. So the first thing we'll do is we'll create an abstract heap. This abstract heap keeps track of what objects would look like if we were to run the program. We simulate this execution. So we create an abstract heap and then store the values in it. So we're going to stimulate execution. We know if we execute the first line, V2 is going to be assigned to the constant headers. V3 will be assigned to the body. And then something special happens at V4. V4 is going to be assigned to an abstract array. So we have an abstract array here. This abstract array contains three values, V1, V2, and V3. And we don't care what V1, V2, and V3 are. We don't care what they are at all. We just know that it has those values inside of it. the first element of the array, then we're going to assign headers to the second element of the array, then body to the third element of the array. Now, the next thing that we can do is we say, well, we're going to perform a substitution here. We know that status is assigned to the value V1. So we can just do an algebraic substitution in this case, and we'll say, okay, we're just going to substitute those values out. And if we do that, there's something that we notice in this program, and that is that V4 is not used. We don't use v4 whatsoever. Since we don't use that, it means that we're allowed to eliminate it. So we eliminate that. Then we go even further and we say, well, we don't need these intermediate variables either, so we'll just move those down to status headers in body, do direct assignments. And we can be more aggressive. We can say, well, let's go down here as well, so we'll eliminate all those. And we can inline other functions and perform the same type of algorithm over and over again. and constant folding and abstract interpretation, we were able to convert the code on the left into the code on the right. And that's how we were able to eliminate those allocations. So we talked about optimizations and the impacts that observers have on these optimizations. We talked about parallelism with reactors, stack frame eliminations in the interpreter, and inlining and allocation elimination in the JIT compiler. So we were able to eliminate all those allocations in this JIT compiler. question for all of you in the audience. Does this optimization violate the as if rule? We're able to observe that change by counting the number of allocations in the code. So do we violate the as if rule? Do you care? I particularly don't. I think it's great that we're reducing those. All right. I was going to end the presentation here. So I was going to say thank you. We did it. We removed some allocations. But I actually have another story to tell. I apologize. There's actually two presentations in one. We're going to move on to the second one here. I've got 12 minutes left. We're going to try and do it. I want to talk about something that happened very, very recently to us in the community and the story that came out from it. I think it's very interesting. I hope it is interesting to all of you. I want to talk about RubyGems and the OpenAI incident. this few people yes okay so for the I hope that this story is interesting and for those of you that haven't heard the story I hope it is still interesting on May I want to recount this story from my perspective basically from on May 11th and 12th there was something that happened ruby gems org started getting thousands of junk gems being uploaded and And actually, I want to rewind a little bit. Let me rewind here. I was going to end here. Thank you, everybody. Let's have a round of applause for me. All those objects eliminated. Great. All right. Get the energy up a little bit. So on May 11th and 12th, RubyGems.org started getting thousands of junk gems uploaded. Just tons of them. Later on, this would be called the GemStuffer campaign, I mean, when you're getting a bunch of shit uploaded, you don't really take time to come up with a name. On May 12th, Moshe Mensfield disclosed the attack on Twitter. So he works with RubyGems.org and scans new packages that get uploaded. They were getting tons of packages uploaded. They said, all right, we've got to stop the bleeding here. We're going to shut this down. We're dealing with a major malicious attack on RubyGems.org right now. now signups are paused. So he said, "We're dealing with a major malicious attack on RubyGems.org and announced that signups had been paused for the time being." On May 13th, Socket.dev released a blog post calling this the GemStuffer attack. At the time, I was like, "Okay, that's interesting." I read their blog posts about it. So their blog post is here, and you can scan the QR code here. attack, GemStuffer campaign. So I read the blog post, and the blog post was like, okay, there are these gems that are being uploaded, and the gems have a malicious script in them, and the script will download some stuff from the UK government. And then, actually, maybe I have some animations in here. I was not planning on talking about this at all, and I literally worked on the slides all day yesterday, so this is, ah, yes, great. So they have this malicious gem or malicious script inside. The script will go make requests to the UK government for some reason, and then it'll download all the stuff from the UK government. Then it'll package, interestingly, it'll take the data that it downloaded, it'll package it into a gem, and then upload that gem again to rubygems.org. I thought this was pretty interesting at the time, but if you read through code that they showed on the blog post, the first thing that I thought is like, so they said, okay, you can identify that you've been a victim of this because there will be these files on your file system. So you can find these files on your file system. And I looked at it, and when you normally install a gem, like I think we all know when we install a C extension, for example, it will execute the ext conf. code execution problem there already. But everybody knows this. And when I looked at their example, the malicious script was not inside of an ext conf. They weren't using a C extension to do this. And so I thought to myself, okay, whatever. How is this impacting anybody? Even if you installed this gem, it's not going to execute itself. You would have to go into the gem and specifically do this. So this just seems weird. Yes, the article never discusses how the program gets executed and under what circumstances would this program get executed. So I just basically said like, "Okay, whatever, weird." May 16th, registration reopens, and to be honest, I just didn't think about it much anymore. On July 6th, Luke Marshall from the Truffle security team notified the RubyGems.org team about a caching security problem RubyGems.org. I work on the RubyGems client a bit, so I'm part of the RubyGems client team, but not the server team. But of course, we talk to each other, so we work together. What's interesting about this attack is, I'm going to show you the attack here. What could happen is legacy authorization was done via a get request. So this is from the victim's perspective. a get request to authorize gems. So if you did gem auth, it would run this. And what would happen is it would do a basic authorization, and then the response from the server would be like this, and you'd have this cache, this key at the bottom. That was your key to login. And I want you to keep this key format in mind here for a second. Maybe a minute, more than a second probably. So that's what it looked like. And from the attacker's perspective, the attacker's perspective looked like this. is that Fastly was sitting in front of rubygems.org and caching the get responses from rubygems.org. So attackers would send a request, and all of a sudden they would get a cached key as a response. So attackers don't send the authorization header, but they were able to get a valid authorization token back. So this is not good. Not good at all. production for like 60 years. Yeah, yeah, it's not exciting. But I don't think many people noticed it, because if you think about it, if you think about the behavior of this, first off, there was no evidence of abuse at the time. Like, no evidence that this had been abused, known at the time. You have to accept encoding gzip for it to happen. And what this, this is kind of weird, because it meant that people running because that's not on by default. So this was just not noticed for a long time. However, NetHTTP does turn that on by default. I think it also went unnoticed because if you imagine yourself as a gem maintainer, you're going to do a gem push. So you'll do a gem push, and let's say you ended up getting somebody else's key. You got my key, but you're going to go upload your own gem. So you would do a gem push, and you're just going to get a weird message saying that you're not to push because you're trying to push your own gem, but you're trying to push it with my key. So it just doesn't work, and then you're like, oh, that's weird. Gem login, and then all of a sudden it fixes and works and you just don't care, right? Like this could have happened. So I think that's why it went unknown for so long. And also only old RubyGems code used this, and the cache expired after one hour. So three days later, they shipped a fix for this. It was completely fixed, so RubyGems shipped a fix. September 8th, I was at work. This is my work garb. I get a DM from one of my colleagues, Emily, and she said to me, "Erin, you're going to get an email from Gemma." Gemma is a former coworker of mine who is working at Anthropic. And Emily said, "You're going to get an email from Gemma and it's going to be about a really bad RubyGems hack." And I was like, She could just e-mail me and you didn't need to DM me. Then Emily's like, "No, you're bad at e-mail." I was like, "Yeah, right. That's true." I was like, "Okay." So I get an e-mail from, actually, I skipped a bit of the story here. So Gemma e-mails me and she says, "Erin, I'm introducing you to this person, Nev, and there's been some kind of really bad RubyGems hack and they want to talk to somebody it. And I was like, yeah, sure, okay. I mean, I can talk to you about it. And I was like, and then I started freaking out because I had realized I'm not good at checking my email. So I was like, did I miss an email? Is there something in the hacker one that I missed? Like, what did I do? So I'm like frantically searching through my email for stuff and there's like nothing there. So I respond to the person. I'm like, I'm so, so sorry. I must have missed your email or something, but I can't find it whatsoever. This person responds to me and said, no, there must be a mistake. This isn't a current RubyGems problem. but there's somebody, a security researcher trying to get in touch with somebody from RubyGems, and I'm like using connections to get in touch with you. And it's, I don't know, interesting. So I'm like, okay, fine. So I get this email from a person named Sydney Von Arx telling me that OpenAI agents had attempted to exploit this RubyGems vulnerability, the caching one. She linked to it. package submissions attempted to exploit the vulnerability to steal user API keys. And I was like, this is some bullshit. Come on, you don't know. But she provided me with links. And I'm like, okay, well, you know, I'm trying to be a responsible person. I will click all of these and read them. I'm a Luddite reading code. Anyway, so I go click the links and I read them, and I'm going to show you, here's an excerpt from one of the gems that she's sent me. This isn't the whole thing, but go ahead and scan the QR code there, that links to the whole thing so you can go take a look at it and read it if you want to. And I'm going to point out a few things in this code. The first thing is the comment at the top that says "Leaked Keys Variance", and I start like sweating in my chair and I'm like, "Oh my goodness, that's not good." You can see it's inside of this script called script.rb, and also the name of the gem is slnleaker5. It's weird. Yeah. Next thing I notice is that it's doing a get request against rubygems.org, and I didn't put the path in here, but it is the authorization path. That's what that is. Then I looked at the bottom, and I saw this particular regular expression, which you may have recognized from the response, response and I realized what this is doing and I was like, oh shit, yes. This was trying to hack RubyGems.org. So I responded to them and I was like, okay, yes, that is very, very interesting. They asked if they could have a meeting with me and I was like, yeah, let's meet and talk about this. So we have a meeting. Oh yeah, this is me realizing what's going on here. like how, okay, that's very interesting, you send me this. It's again, it's in script.rb. How is this executing anywhere? Like how would anybody execute this? It's not in the XConf. And she told me it was being run in RubyDoc.info. And I was like, what? RubyDoc.info? If you go to RubyDoc.info, it's just a documentation server. Let's see, what is the thing? If you look inside of the gem, you'll see that there is a yard ops file. The yard ops file looks like this, and you'll see that it points it. It says like load./script.rb, and what happens is if you have the yard gem installed, it installs a RubyGems plugin, and then if you install another gem, when you install that gem, the yard gem will go ahead and look inside of your gem, for a Yard Ops file. And if it finds a Yard Ops file, it'll run this code in here. So it'll run this. And she told me that any time a gem got uploaded, so let's see if I have, yes. So what was happening here is a bot would upload a gem to RubyGems.org like this. RubyGems.org would then send a webhook to RubyDoc.info. So RubyDoc.info is completely unrelated to RubyGems.org. It would send a webhook to rubydoc.info. Rubydoc.info would say, "Oh, great, there's a new gem published." It would go download the gem. So it would download it, run it, open it up inside of a Docker container. The Docker container still had network access. It would execute the malicious script. The malicious script would go ahead and download data from the UK government. It would package that up as a gem. It would upload the gem to rubygems.org. Rubygems.org would send a webhook to rubydoc.info. malicious scripts it would download data from the UK government etc etc etc so this is crazy insane to me I couldn't believe it all of these pieces put together like this is a wild like how how in how on earth could this be happening I want to do like I want to do kind of a timeline review on this because this blew my mind so and those gems, you can look at the upload dates on them. They are from May 11th. All right? The RubyGems cache report came in on July 6th, and the person that reported it was completely independent of OpenAI. They didn't have any affiliation whatsoever. They found it independently. So these bots knew about this problem for, I don't know, a month here. Or two months, I guess. And all of this happened well before the hugging face breach as well. So this finally, on September 12th, Sydney and her team published RubyHack.ai, and I encourage you to read it. It has a very good in-depth into this particular attack. So the thing that freaked me out is that the bots figured out RubyGems.org sends a webhook to RubyDoc.info. They figured out that Yard will execute arbitrary code on RubyDoc. Well, it'll execute arbitrary code. YardDoc.info will process YardDoc with network connection and execute that code. They also figured out, this is what I suspect, you'll notice if you go look through all the gems and the gem stuffing campaign, not all of them have this code inside of them to download keys. I think it's because when those gems started getting uploaded, the RubyGems.org team started shutting down the accounts and not allowing them to log in anymore, said, "Oh goodness, I need a way to login when I don't have credentials, so I will use these credentials." They decided to burn a zero day on rubygems.org. So this is crazy to me. They figured out this Rube Goldberg machine. Now, the rubygems.org team, there's a happy ending, the rubygems.org team was able to handle it. They handled it completely, fixed it all up, closed the leaks. As far as we know, nobody was exploited, harm done to folks in the community. He's good, yes. So thank you so much to them. I want to end this kind of here. I am an AI optimist. I use AI every single day to write code. I use it all the time. Actually, I want to change this a little bit. I'm just an optimist, not necessarily an AI optimist. I think that this is the best time to be alive. And I really believe that it's only going to get better. But the thing is, I didn't have to take any pills to be an optimist. I'm actually a middle-aged man, and I don't want to take any more pills. I have plenty of them. But I don't think that being optimistic about AI or about our future necessarily means that I need to surrender myself to it. I've heard the argument that AI is just our next compiler. You don't need to read the machine code that your compiler produces, right? So why do you need to read the code that your AI produces? I can kind of get that argument. It's true, you probably don't read the machine code your compiler produces. But that's because the compiler made a promise to you, made this promise to you, the as-if rule. Whatever it does, the behavior that you can observe, matches the code that you wrote and everything that I showed you in this presentation shows you what it costs to keep that promise now your AI has not made this promise to you there is no as if rule for your English so I am not going to concede my destiny to AI I'm going to keep reading my code and I hope that you will too And I want to end it with this slide. Get in, loser. We're going programming. Thank you.