Formatting a 25M-line codebase overnight
Stripe's engineers tackled Ruby's lack of a strict autoformatter by developing rubyfmt, an open-source tool designed for speed and zero configuration. Born from a personal project and heavily optimized with Rust and Ruby's C API, rubyfmt eliminated formatting debates and streamlined onboarding for new engineers. The culmination was an overnight migration of Stripe's 25-million-line Ruby codebase, proving that deep technical investment in developer tooling can significantly enhance productivity.
The Lowdown
The story recounts the creation and implementation of rubyfmt, a novel autoformatter for Ruby, specifically engineered to manage Stripe's enormous 25-million-line (now 42-million-line) Ruby codebase. Before rubyfmt, the Ruby ecosystem lacked a true autoformatter, leading to time-consuming debates over code style and slower onboarding for engineers new to the language.
- The Genesis: The idea for
rubyfmtoriginated from a RubyConf debate in 2018, aiming to create a tool similar togofmt—fast, zero-configuration, and accessible. - Addressing Pain Points: Existing tools like
rubocopoffered too much configurability, leading to "bikeshedding" over style.rubyfmtsought to remove these debates entirely. - Performance First: A strict 100ms speed budget for "format on save" necessitated a deep dive into Ruby's internals, compiling a C program directly against
libruby. - Cross-Language Benefits: It significantly benefited engineers from other language backgrounds (like Go) by providing an opinionated formatter that removes uncertainty and allows them to focus on logic.
- Technical Evolution: Initially built in Ruby using
ripper, performance demands led to a rewrite in Rust. This involved innovative (and initially "janky") methods of passingripper's parse trees between Ruby and Rust, first via JSON, then by teachingserdeto directly walk RubyVALUEobjects in memory via the C API. - Stripe's Adoption: Stripe, experiencing the pain points firsthand with its large codebase and previous failed attempts with other formatters, funded
rubyfmt's full-time development, keeping it open source. - Massive Rollout: After a gradual, confident rollout, Stripe formatted its entire codebase overnight on a Saturday in 2024, minimizing merge conflicts and ensuring consistency.
- Impact: The tool became largely invisible infrastructure, praised by engineers for eliminating formatting discussions, speeding up code reviews, and improving overall developer experience.
- Future-Proofing: Migration to the new
Prismparser (which doesn't require a full Ruby VM) further improvedrubyfmt's speed and reduced its binary size.
rubyfmt stands as a testament to solving deeply technical problems at scale, transforming a personal open-source project into a critical piece of infrastructure that quietly empowers Stripe's developer productivity.