利用 AI 辅助工作流,Bun 的核心代码在短短 11 天内完成了从 Zig 到 Rust 的重写 [1]。该项目动用了 64 个并发 AI 代理(Claude Code),消耗了约 16.5 万美元的 API Token,其工作量相当于大约 3 名工程师一年的工作时长 [1]。此次重写修复了 v1.3.14 版本中存在的 128 个漏洞,包括内存泄漏和崩溃问题 [1]。
在性能与资源优化方面,通过 Rust 重写及链接器优化,Linux 和 Windows 平台的二进制文件大小减少了约 20% [1]。借助 LLVM 生命周期内在函数(lifetime intrinsics),解析器(如 TOML、JSON、YAML 等)的栈空间使用量得到降低 [1]。此外,通过 C/C++与 Rust之间的跨语言链接时优化(LTO),实现了 2%至5%的性能提升 [1]。
为了保障代码质量,项目对所有解析器实施了全天候的指导型模糊测试(coverage-guided fuzzing),自动发现了约 15 个漏洞 [1]。尽管底层语言变更,但 Rust 代码在机械结构上保持了与原始 Zig 代码的高度相似性,从而维持了项目的可维护性 [1]。
A team successfully rewrote the core of the Bun runtime from Zig to Rust over an 11-day period using AI-assisted workflows [1]. This project utilized Claude Code with 64 concurrent AI agents and incurred a cost of approximately $165,000 in API tokens, which is equivalent to roughly three engineer-years of work [1]. The rewrite resolved 128 bugs present in version v1.3.14, addressing issues such as memory leaks and crashes [1].
Performance metrics improved following the migration; binary sizes for Linux and Windows were reduced by approximately 20% through the Rust implementation and linker optimizations [1]. Parser stack space usage was decreased via LLVM lifetime intrinsics applied to TOML, JSON, YAML, and other parsers [1]. Additionally, cross-language LTO between C/C++ and Rust yielded a performance improvement of 2-5% [1]. To ensure reliability, the team implemented 24/7 coverage-guided fuzzing for all parsers, which automatically identified approximately 15 bugs [1]. Despite these changes, maintainability was preserved as the resulting Rust code remains mechanically similar to the original Zig codebase [1].