No Appreciable Difference

| Shey Sewani | Toronto

Pre-pandemic DevOps was a strange place with stranger rules, rituals, and prayers. Here’s one I said regularly—something I thought would give me faster builds and smaller images.

RUN gem install bundler -v 2.6.7 && \
  bundle config set --global gem.rdoc false && \
  bundle config set --global gem.ri false && \
  bundle install --no-cache

It seemed reasonable: skip the docs, avoid the cache—build faster and ship smaller images. But I never actually tested whether these settings made a difference. Until now.

Bundling with local caching enabled and with rdocs: 87.8 seconds.

build-with-caching-and-docs

Bundling without local caching enabled and without rdoc: 89.7 seconds.

build-without-caching-and-docs

Build time? Basically the same. There’s some variability—public internet and all—but for Ruby, there’s no appreciable difference

Image size? Identical in both cases: 4.57GB.

And yes, I’m using Debian (Bookworm), which isn’t exactly slim–but that’s not the issue. The config flags I copied–the ones I believed made a difference–didn’t. They didn’t speed up the build. They didn’t shrink the image. I had assumed they would.

Turns out Bundler doesn’t generate docs during bundle install–it delegates installation to RubyGems, which skips documentation unless you explicitly ask for it. So all those extra flags like gem.rdoc and gem.ri? They don’t do anything. They just look useful.

Same with --no-cache, it sounds like it prevents .gem files from being stored in /usr/local/bundle/cache, but it doesn’t! That cache is created by RubyGems fetching gems before installation.So, if you want to reduce image size, you have to remove them manually.

RUN gem install bundler -v 2.6.7 && \
  bundle install --no-cache && \
  rm -rf /usr/local/bundle/cache/*

And there you have it—finally, a smaller image.

manual-removal

I’d been cargo-culting these flags for years. They didn’t speed anything up. They didn’t shrink the image. And now I’m here, confessing my sins. I hope this helps someone.