Rails World 2026: The RubyGems Compact Index: What Powers Every `bundle install` (Jenny Shen) Video: https://www.youtube.com/watch?v=Z9XUvK8Sr5c Talk page: https://www.rubyevents.org/talks/the-rubygems-compact-index-what-powers-every-bundle-install Unedited machine transcript, generated with Whisper. It contains recognition errors (names, technical terms). Check the video before quoting. ---- Awesome. Thanks, Michelle. Hey, everyone. Thanks for coming, especially since this is the last talk before the ending keynote. I have a great time at Rails World so far. Even though the weather is so hot, it's amazing to hang out with cool folks like y'all. Today, I'll be talking about the RubyGems compact index. To get us started, who has heard of the compact index before? Raise your hands. Oh, looks like there's a couple of you. For those who don't know and get us warmed up a bit, I have a simple magic trick. For this, I'll get Michelle to get back up here. Well, let's have a round of applause for Michelle. Amazing. Simple question for you. Okay. What is the first major Rails version you started developing on? Four? Okay. Yeah. Well, that number has traveled a meter and is in my pocket right here. Okay. It's a four. It's a four. Whoa. Amazing. Okay, I'll get that back. Thanks, Michelle. So, a magician never spoils their secrets. But I'm not really a magician, so I'll share the secret to this trick. It's the compact index. More specifically, it's the quiver compact index. It is a wallet that stores up to 16 cards and allows you to quickly take them out. Unfortunately, it was all sold out online. So I made my own right here. I think it's definitely an upgrade. It's V2. So yeah, that is the V2 version. But the V2 version. But the compact index. But the compact index is actually also an algorithm. It's related to finance. It compresses hundreds to thousands of stocks within an index and it compresses it down to only a handful while maintaining diversification. I'm not supposed to the compact index. This isn't the compact index. This isn't the compact index. This isn't the compact index. This isn't the compact index. I'm supposed to be talking about though. It's the RubyGems compact index. But they all share a similar theme. They compress and organize large amounts of information for quick retrieval or simplicity. So for the quiver compact index, it compresses a deck of cards into an organized wallet. While for the financial algorithm, it compresses hundreds of stocks into an organized wallet. It compresses a deck of a tiny fraction while maintaining diversification. And the ruby gems. And the ruby gems compact index is not that different. It compresses info from all 200,000 gems on rubygems.org for bundler to resolve dependencies. Ruby gems is important for the Ruby and Rails ecosystem. You might be thinking, why are we talking about Ruby gems at Rails world? Well, Gems and gem installation is an important part in running a Rails application. And it's important to keep it up to date by improving things like performance, reliability, reliability, and security. And when we made these improvements, we found that the compact index is a core part of making these changes. So today, we'll be talking a little bit about the internals of the compact index and how it interacts with bundler, recent evolutions to the compact index and the new features in bundler, and some future additions that we can make. Hopefully, out of this talk, you can use some of these new features to level up your dependency installation game. But before we get started, let me introduce myself. I'm Jenny. I am not a magician, but I can be considered a software magician. I can be considered a software magician. I can make code appear out of nowhere. The secret to that is AI. And I can sometimes make bugs magically appear as well. I work at Shopify as a senior developer, and I'm based in Ottawa, Canada. I'm also a rubygems.org maintainer. I'm an operator. We always welcome contributions to their projects. So if you find some of the stuff interesting, come find me afterwards. Okay, so let's talk a bit about the rubygems compact index. Okay, so let's talk a bit about the rubygems compact index. As I mentioned before, it compresses information from more than 200,000 gems on rubygems.org for bundler to use. It runs with three endpoints and serves over 50 million requests per day. These three endpoints. These three endpoints. These three endpoints are the info endpoints. These three endpoints are the info endpoints, the versions endpoints, and the names endpoints, though bundler only uses the former two. When you bundle install, if there's no gemfile lock, there's changes to the gemfile, or if there's dependencies not found locally, bundler will need it. Bundler will need it. Bundler will need it. Bundler will need it. Bundler will need to re-resolve and interact with the index. First of which, it'll make sure there's an up-to-date list of gems, and this is the versions endpoint. So as you can see here, this is what it looks like. So this is the list of gems available to download. You can see the name of the gem, the versions available, and something called the info checksum that we'll get back to later. The index. The index is also stored locally on your machine. The index is also stored locally on your machine. Bundler tries to keep them in sync. Bundler tries to keep them in sync, and it's stored in the bundle cache directory in your machine. Bundler will try and update the versions file locally if it needs to be updated. It will request with an e-tag, and the index will return any bytes and that are new versions and updated here. So the gem called D gets updated locally. So the gem called D gets updated locally. Then Bundler needs to resolve more, needs more info about each gem in order to resolve or determine if it can be installed. Some of this includes the transitive dependencies and the requirements, Ruby or RubyGems requirements, and the gem checksums, and the gem checksums, and the gem checksums, and the gem checksums. It needs to be updated. It needs to be updated. Bundler will calculate a hash of the contents of the file. Bundler will calculate a hash of the contents of the file. And if it matches the info checksum we mentioned earlier, then it doesn't need to refetch. But if the version's checksum is different, it will request the new info file. Something else that I want to talk about is what happens when a new version gets pushed. RubyGems gets pushed. RubyGems gets pushed. RubyGems gets pushed. RubyGems gets pushed. RubyGems gets pushed. RubyGems gets pushed. RubyGems gets pushed. It will fire a background job to update the version's file. RubyGems gets pushed. It will do the same for the gem info file, and it gets updated to an AWS bucket. You may be asking, why are we updating to the AWS bucket? Well, for our CDN, it checks if a request comes in and if it's a compact index request, it's a compact index request. It will redirect to the AWS bucket. It will redirect to the AWS bucket and serve it through there. And if not, it will fall back to the server if the file doesn't exist or there's something wrong with the bucket. So when a gem gets pushed, the new row gets appended to a new line. The new gem gets appended to a new line in the versions file. And it gets updated in the info file. And it gets updated in the info file. And when a gem gets yanked, it will subtract that version and it will remove it from the info file. You may be thinking, oh, if there's a lot of pushes and yanks, wouldn't the version's file get really large? Well, we have a monthly rake task that consolidates all of the redundant lines of the redundant lines of a gem and rolls it up to one line here. So yeah. So yeah. That's a little bit about the index and how Bundler interacts with it. Now we can talk about some of the exciting new changes we have to the index. The first one is related to security. This is dependency cooldowns. More specifically, it's dependency cooldowns. So if you specify a cooldowns. If you specify a cooldown of something like seven days, then new versions of the gems only get installed seven days after published. So if a new Rails version comes out today, you will need to wait. After seven days, it will be able to be installed. You may be asking, why do we need this feature? Well, over the recent while there has been an increase of gem takeover attacks. More so because of AI being able to take over maintainers accounts and push malicious versions. So the one that inspired it all is earlier this year in the NPM ecosystem, Axios was compromised. So someone was able to take over the container's account and push a malicious version. And cooldowns. And cooldowns allow time to detect malicious gems before installation. And cooldowns allow time to detect malicious gems before installation. So scanners will be able to detect them and then yank them. PyPI and NPM quickly added cooldowns to their tooling. And RubyGems should follow suit. How do we do that, you may ask? So if you may ask? Bundler, Bundler would need to know published timestamps of the gems. Bundler would need to know published timestamps of the gems. But as you can see here, there's no timestamps or create at info in the info file. Luckily enough, in the compact index spec, you can add more requirements in the requirements section. So we can easily just add the create at information here. What makes this difficult, though, as I said before, all of the files are stored in AWS buckets. What makes this difficult, though, is as I said before, all of the files are stored in AWS buckets. So we had to regenerate 200,000 files for each info file in order for this to work. We investigated different approaches, but we landed on something called the blue-green migration. So essentially, what we did is that we had the CDN pointing to the current index. And then for the current index. And then for new pushes and Yanks, we update the current index. We update the current index. We update the current index and the new one under a V2 subdirectory. And then we backfill 200,000 gems, the info files of them into the new directory. Then, once that was completed, we were able to direct the CDN to serve the new directory. So this was all possible. This was all possible. Well, we chose this approach. Well, we chose this approach because if something did go wrong, we could easily revert back and go to the pre-existing version. So now there is create at info in the compact index. And HSBT added the cooldown feature in Bundler. You can add the cooldown flag to your gem install method. You can set it in your configuration. You can set it in your configuration and in your gem file. You can also read more in this block post right here. Cool. So that's cooldowns. Next, I want to talk about performance. UV is super fast. And in order for Ruby gems to stay up to date, we wanted to be fast. We wanted to be fast as well. We found that more than 70% of bundle install times is compiling native extensions, which is a lot. And you may ask, what are native extensions? Well, some gems have C or Rust code to make the gem more performant, and they need to compile before use. So when you bundle install. So when you bundle install, Bundler will run, Bundler will run a compilation script specified in the gem spec right here. There is a pre-existing solution to this though, which is having the gem pre-compiled for you. An example of this is Nokogiri. So you can see there's multiple versions compiled by platform. And within each platform, there are many versions versions. ABI versions. ABI versions for each gem. ABI versions for each gem. An ABI version is an application binary interface. So what that means is that with each minor Ruby version, there are data structures and internals that changes. So binaries aren't compatible between each Ruby version. So you need to have one compile for each one. So you need to have one compile for each one. So yeah, the more pre-compiled gems. So yeah, the more pre-compiled gems, the faster. But there's one problem, or one thing that is suboptimal. A pre-compiled gem can be big. As I mentioned before, a pre-compiled gem supports multiple ABIs. But most of the time, but most of the time, you'll only need to use one. Because yeah, you'll probably use one Ruby version. Also, gem maintainers need to add code in their gem to load the right binary in as well. So being able to publish gems for one Ruby API allows for smaller gems, faster downloads, faster downloads, faster downloads, and less configuration for maintainers. Another perk is that for existing gems, when a new Ruby version comes out, you can't update the gem with new Ruby ABI versions. And it'll be great to be able to push new Ruby ABI support. And it'll be great to be great. And it'll be great to be great to be great to be great to be great. So for the gem. And the gem is platform suffix, and it's multi-ABI. And now it's SHA suffix with the single ABI. The reason why we had to make this naming change is that currently we cannot specify multiple ABI's per version, because that will cause a name collision. So what does that mean for the compact index? It means that the suffix is the suffix is the suffix. What was the suffix that matches the suffix that matches the first eight digits of the suffix that matches the first eight digits of the checksum. And we move the platform as to a requirement so we can get that information still. We also scope the Ruby requirement to scope to a single Ruby ABI. There's one caveat. By doing this rename, old clients of Bundler thinks this is a platform that we can't really because this is a platform. So this is a platform. So this is a platform. So this is a platform. So this is a platform. So we have tools in the tools in the tools in the toolchain to support pushing content-adjustable gems. So we have a PR up to Raid compiler. So hopefully in the next couple of weeks, folks that are using Raid compiler to precompile their gems can try pushing content-adjustable gems. And if you own a gem that has native extensions, but they aren't precompiled, you should precompile them. You should precompile them. You can try out CI build gem. Edward created. And essentially it's a gem that helps you create a GitHub workflow. And that will help you precompile per platform and push it up to RubyGems.org. So for people that install content-adjustable gems, they will be preferred over the legacy multi-adjustable gems. They will be preferred over the legacy multi-API versions. And you'll see them in your gemfile.lock in a new section. You may be thinking, OK, what's the impact of all of this? We can push single ABI's, but what's the impact? Well, I push single ABI versions of all the gems that are precompiles that are precompiled for a new rails version. And it reduces the download size of the entire bundle by 20%. It's OK. But the real savings here is that there are about more than a dozen gems that have native extensions but aren't precompiled. So we're unlocking a lot of future savings. Cool. So there are a lot of new features that are new features that have been shipped over the past year. And let's talk about some future ideas. The first one is related to security like cooldowns. These are security warnings. It would be great for Bundler to help you identify when you're using a vulnerable version of a gem. And we can add that into the compact index by which we're possibly adding some advisory information. Another feature we can add. Another feature that we can add is more requirements to precompiled gems to ensure correct compatibility. Right now, we like Ruby engine information. There's a bug currently in Ruby gems where if you're using another Ruby implementation like TruffleRuby and install Ruby binaries. So we can add the engine information. So we can add the engine information so that we can compile more binaries for different engines. So we can add the engine information so that we can compile more binaries for different engines. Okay, great. So to conclude, we talked about the compact index internals and how it interacts with Bundler. Some recent evolution is a lot of new features. So we can add the new features. So we can add the new features to the index. So we can add the new features to the index. So we can add the new features to the index. Hopefully, we can add the new features to the index. Hopefully, you can use some of the new features like cooldowns and try out the beta versions of RubyGems.org. That will be very helpful to figure out bugs and get them solved before the stable release gets released. You can take a look at more about all the new features that are coming in the next. So we can take a look at the next. So we can take a look at the next. So we can take a look at the next. So we can take a look at the next.