Mara has significantly optimized Rust's string formatting macros, resulting in faster compilation times, smaller binaries, and more efficient runtime code for println!(), format!(), and related macros.
Mara, a prominent Rust contributor, has delivered a substantial performance optimization to one of Rust's most fundamental features: string formatting. The improvements affect all formatting macros in Rust, including println!(), panic!(), format!(), write!(), and log::info!()—essentially everything built on format_args!(). This optimization represents years of careful work to untangle and modernize Rust's formatting infrastructure.
The Performance Gains
The improvements manifest in multiple ways. Compilation becomes faster—"Hello world" compiles 3% faster, while larger projects like Ripgrep and Cargo see 1.5% to 2% improvements. The resulting binaries are roughly 2% smaller. These might seem like modest numbers, but they compound across the entire ecosystem since string formatting is ubiquitous in Rust code.
Some workloads see dramatic improvements. The large-workspace benchmark, which uses hundreds of crates each with simple println!() statements, now compiles 38% faster and produces 22% smaller binaries. This showcases how the optimization particularly benefits codebases with extensive formatting usage.
The Technical Challenge
What makes this achievement remarkable is the complexity of the problem Mara tackled. The previous implementation had become a tangled web of dependencies and constraints that made changes nearly impossible without breaking the compiler itself.
Several factors contributed to this complexity:
- Bootstrap complications: During the compiler's self-hosting process, the standard library had to be compiled with both the old and new compiler versions, requiring support for both old and new
format_args!()expansions simultaneously. - Stable API promises: Certain design decisions, like supporting the full
usizerange for width and precision fields, had become entrenched and blocked potential improvements. - Clippy dependencies: The popular linter had come to depend on the exact expansion of
format_args!(), meaning any change would break it. - Compiler architecture: The code that expanded the macro was deeply intertwined with implementation details of the
fmt::Argumentsstructure, requiring massive rewrites just to experiment with new approaches.
Mara describes this as "years" of work to systematically remove these roadblocks one by one, finally reaching a point where a comprehensive overhaul became feasible.
The Solution
The new implementation achieves its gains through several key changes:
- Reduced indirection: The previous version used an array of arrays structure that introduced unnecessary overhead.
- Smaller data structures: The
fmt::Argumentsstruct has been made more compact. - Special casing: A dedicated path for the "no arguments" case eliminates overhead for simple formatting operations.
- Simplified compiler integration: The macro expansion code is now cleaner and less coupled to implementation details.
Mara has shared detailed diagrams comparing the before and after implementations, showing how the new approach eliminates layers of complexity. The optimization essentially transforms the formatting system from a complex interpreted structure into something closer to direct code generation.
Community Impact
The Rust community has responded with enthusiasm and appreciation. Developers noted that the previous implementation had remained largely unchanged since pre-1.0 days and was considered "incredibly arcane." The optimization represents a rare case where nearly every Rust program benefits—even if only slightly—from a single change.
Some developers were surprised by the magnitude of the gains, particularly given that string formatting seems like a straightforward operation. Mara clarified that the old implementation had quirks like needing to toggle SSE registers just to print "Hello, world," which certainly contributed to the overhead.
Looking Forward
The changes are landing in Rust Nightly imminently and will ship as part of Rust 1.93.0 in January 2026. This follows the typical Rust release cycle where major optimizations first appear in Nightly builds for testing before being stabilized.
For developers, this means upcoming projects will benefit automatically from faster compilation and smaller binaries without any code changes. The optimization particularly benefits large codebases and projects with extensive logging or formatted output.
Mara's work exemplifies the kind of deep, patient engineering that improves foundational systems in ways that compound across the entire ecosystem. By finally untangling years of accumulated complexity, they've delivered a win that every Rust developer will feel, even if they never see the code that makes it possible.


Comments
Please log in or register to join the discussion