HN
Today

Ladybird Browser adopts Rust

The Ladybird browser is strategically porting its C++ JavaScript engine, LibJS, to Rust, a move motivated by the pursuit of memory safety and a robust ecosystem. This ambitious task was significantly accelerated by human-directed AI assistance, translating 25,000 lines of code in mere weeks without regressions. The announcement has sparked lively debate on Hacker News about the efficacy of AI in code migration, the perennial risks and rewards of language rewrites, and the strategic rationale behind Ladybird's evolving technology stack.

186
Score
61
Comments
#1
Highest Rank
11h
on Front Page
First Seen
Feb 23, 12:00 PM
Last Seen
Feb 23, 10:00 PM
Rank Over Time
11122222357

The Lowdown

The Ladybird browser project has announced a significant architectural shift, beginning the porting of its C++ codebase to Rust. The initial target is LibJS, Ladybird's JavaScript engine, specifically its lexer, parser, AST, and bytecode generator components. This decision follows a re-evaluation of Rust, which was initially dismissed for its mismatch with C++'s object-oriented paradigms, but is now embraced for its memory safety guarantees and mature ecosystem, mirroring trends seen in larger browsers like Firefox and Chromium.

  • Ladybird's team, led by Andreas Kling, utilized AI tools (Claude Code and Codex) for the translation process. This was a highly human-directed effort, involving hundreds of small prompts and subsequent adversarial review by other models to ensure correctness.
  • The AI-assisted port resulted in approximately 25,000 lines of Rust code being generated in just two weeks, a task estimated to take several months manually. Crucially, the port achieved byte-for-byte identical output and zero regressions across extensive test suites, including test262 and Ladybird's own regression tests.
  • The translated Rust code intentionally mimics the C++ structure to maintain compatibility and ensure identical output, acknowledging that it is not yet idiomatic Rust. Future efforts will focus on refactoring the Rust code for better idiomatic style once the C++ pipeline can be retired.
  • The Rust porting is described as a long-term, sidetrack effort that will coexist with ongoing C++ development. The core team will manage the order and selection of subsystems to be ported, emphasizing a deliberate and coordinated approach.

This strategic shift aims to bolster Ladybird's memory safety and leverage the advantages of the Rust language, despite the acknowledged controversial nature of such a foundational change within a growing project.

The Gossip

AI's Agile Assistance

Many commenters highlighted the innovative and practical use of AI for code translation, seeing it as a prime example of 'intelligence amplification' rather than replacement. The efficiency of porting 25,000 lines of C++ to Rust in two weeks, with human oversight and adversarial review, was widely praised. While some expressed concerns about AI 'killing the passion' for programming or questioned the definition of 'fast' for such a translation, the general consensus leaned towards AI being a powerful tool for accelerating tedious migration and refactoring tasks when guided by experienced developers.

Rewrites: Risky or Rewarding?

The decision to rewrite parts of the codebase sparked a classic Hacker News debate about the wisdom of language rewrites. Several users cited Joel on Software's famous essay, viewing rewrites as a major 'red flag' that often precedes project failure. Others countered that Ladybird's gradual, sidetracked approach, focused on memory safety and managed by the core team, mitigates these risks. Proponents argued that a rewrite can be a necessary differentiator and that successful, large-scale rewrites (like in Linux or PHP) demonstrate their potential for long-term dividends, especially when done before a project is fully established.

Rust's Rollout: Reconsidering a Rejection

Commenters noted the irony of Ladybird's founder, Andreas Kling, who was previously seen as critical of Rust hype, now adopting the language. The discussion included questions about Rust's C++ interop capabilities, especially given Ladybird's prior challenges with Swift interop. Some expressed disappointment or unease with the perceived 'shifting' language decisions (from C++ to Swift, now to Rust), likening it to a project lacking clear direction, while others welcomed Rust for its safety benefits and potential to attract more contributors.

Servo's Shadow: Self-Built vs. Shared Engines

A recurring question revolved around why Ladybird chooses to build its own JavaScript engine and browser components from scratch rather than leveraging existing Rust-based projects like Servo. Commenters defending Ladybird's approach explained its foundational philosophy of creating a truly independent "fourth engine" to offer an alternative to Blink, Gecko, and WebKit. They argued that using a third-party library like Servo, which itself doesn't have a JS engine and uses SpiderMonkey, would go against Ladybird's core mission of building all dependencies in-house and providing a distinct implementation.