Bun 1.4
Bun 1.4
Bun is the complete toolkit for building and testing full-stack JavaScript and TypeScript applications. If you’re new to Bun, you can learn more from the Bun 1.0 blog post. Bun 是用于构建和测试全栈 JavaScript 和 TypeScript 应用程序的完整工具包。如果您是 Bun 的新用户,可以通过 Bun 1.0 的博客文章了解更多信息。
Bun 1.4 adds +1,517 tests from the Node.js test suite - our biggest jump in Node.js compatibility since Bun 1.0. Bun v1.4 also fixes over 2,900 issues. It reduces idle CPU usage by 5x, reduces memory usage by up to 35%, and starts 50% faster on Linux. It adds Bun.Image, Bun.WebView, Bun.markdown, Bun.cron(), Bun.Terminal, bun run —parallel, bun test —parallel, bun audit fix, bun dedupe, and bun prune. And it rewrites Bun from Zig to Rust.
Bun 1.4 从 Node.js 测试套件中增加了 1,517 个测试用例,这是自 Bun 1.0 发布以来我们在 Node.js 兼容性方面最大的飞跃。Bun v1.4 还修复了超过 2,900 个问题。它将空闲 CPU 使用率降低了 5 倍,内存使用率降低了高达 35%,并且在 Linux 上的启动速度提升了 50%。此外,它还新增了 Bun.Image、Bun.WebView、Bun.markdown、Bun.cron()、Bun.Terminal、bun run --parallel、bun test --parallel、bun audit fix、bun dedupe 和 bun prune。同时,Bun 的底层代码已从 Zig 重写为 Rust。
This post covers everything we’ve shipped since Bun 1.3.0 (with new to Bun v1.4 tagged). To upgrade: bun upgrade
本文涵盖了自 Bun 1.3.0 发布以来我们推出的所有功能(Bun v1.4 的新功能已作标记)。升级方式:bun upgrade
Node.js compatibility
Node.js 兼容性
Bun is designed to be a drop-in replacement for Node.js. We’ve added +1,517 tests from the Node.js test suite to run on every commit of Bun. node:http, node:fs, node:cluster, node:timers, node:zlib, node:vm, and node:stream pass 97% of Node’s own tests; node:quic 99%; node:events, node:trace_events, and node:sqlite 100%. Bun 旨在成为 Node.js 的直接替代品。我们从 Node.js 测试套件中增加了 1,517 个测试用例,以在 Bun 的每次提交中运行。node:http、node:fs、node:cluster、node:timers、node:zlib、node:vm 和 node:stream 通过了 Node 自身 97% 的测试;node:quic 通过了 99%;node:events、node:trace_events 和 node:sqlite 通过了 100%。
Bun is not 100% compatible with Node.js yet. In practice, much of the existing JavaScript ecosystem just works. You can more closely track Bun’s Node.js test suite progress here. Bun 目前尚未实现 100% 的 Node.js 兼容。但在实践中,现有的 JavaScript 生态系统大部分都可以直接运行。您可以在此处更密切地跟踪 Bun 在 Node.js 测试套件方面的进展。
Production
生产环境
Bun v1.4 uses less memory, less CPU, and starts faster. Until Bun v1.4, Bun used two memory allocators - JavaScriptCore’s libpas allocator and mimalloc. JavaScriptCore in Bun now uses mimalloc (improving memory reclamation), and we’ve extended mimalloc with features like partial page clearing, a scavenger thread that frees memory while JavaScript idles, and improved lazy zeroing. Bun v1.4 使用更少的内存和 CPU,启动速度也更快。在 Bun v1.4 之前,Bun 使用了两种内存分配器——JavaScriptCore 的 libpas 分配器和 mimalloc。现在,Bun 中的 JavaScriptCore 使用了 mimalloc(改善了内存回收),并且我们为 mimalloc 扩展了诸如部分页面清理、在 JavaScript 空闲时释放内存的清理线程以及改进的惰性归零等功能。
CPU usage
CPU 使用率
For Claude Code, a large long-running application built on Bun, production CPU usage dropped by 2×: p99 from 24% to 10%, p50 from 5.8% to 2.5%. For a small “hello world” app, idle CPU usage drops by 5x. 对于基于 Bun 构建的大型长驻应用程序 Claude Code,其生产环境的 CPU 使用率下降了 2 倍:p99 从 24% 降至 10%,p50 从 5.8% 降至 2.5%。对于小型 “hello world” 应用程序,空闲 CPU 使用率下降了 5 倍。
Memory usage
内存使用率
Applications using HTTP servers with Bun should see a 13% - 48% memory usage reduction. 使用 Bun 构建 HTTP 服务器的应用程序内存使用量预计将减少 13% 到 48%。
Startup
启动速度
On Windows, Bun starts 2.5× faster. On Linux, Bun starts 2× faster and uses less than half the memory. 在 Windows 上,Bun 的启动速度提升了 2.5 倍。在 Linux 上,Bun 的启动速度提升了 2 倍,且内存占用不到原来的一半。
Binary size
二进制文件大小
On Linux and Windows, Bun gets up to 17% smaller. 在 Linux 和 Windows 上,Bun 的体积缩小了高达 17%。