# Bun（JavaScript 运行时）

**Bun** 是一款一体化的 [JavaScript](https://www.edgepedia.org/zh/javascript) 与 [TypeScript](https://www.edgepedia.org/zh/typescript) 运行时及工具集，由 Jarred Sumner 于 2021 年创建，由 Oven 公司开发，旨在作为 Node.js 的直接替代品。2023 年 9 月，它发布 1.0 版本，开发者宣布其稳定并可用于生产环境；Bun 采用 MIT 许可；2025 年 12 月，[Anthropic](https://www.edgepedia.org/zh/anthropic) 宣布已收购该项目。<sup>[1](https://bun.com/blog/bun-v1.0)</sup><sup> • </sup><sup>[2](https://www.nexifer.com/blog/bun-in-production)</sup><sup> • </sup><sup>[3](https://www.infoq.com/news/2023/09/bun-ga-nodejs-alternative/)</sup>

| 关键事实 | 详情 |
|---|---|
| 引擎 | JavaScriptCore（Safari 背后的引擎），而非 V8；厂商声称启动速度最高可达 Node.js 的 4 倍<sup>[1](https://bun.com/blog/bun-v1.0)</sup><sup> • </sup><sup>[4](https://developer.mozilla.org/en-US/blog/leveraging-bun-on-vultr-a-superior-node-js-alternative/)</sup> |
| 工具集 | 运行时、兼容 npm 的包管理器、兼容 Jest 的测试运行器，以及打包器，全部集成于一个二进制文件中<sup>[1](https://bun.com/blog/bun-v1.0)</sup> |
| 实现语言 | 直至 1.3 版本均用 Zig 编写；Bun 1.4 用 Rust 重写了代码库<sup>[5](https://bun.com/blog/bun-v1.4)</sup><sup> • </sup><sup>[3](https://www.infoq.com/news/2023/09/bun-ga-nodejs-alternative/)</sup> |
| 安装速度 | 厂商基准测试：T3 技术栈的 Next.js 项目冷安装耗时 1.41 秒，而 npm 为 18.1 秒、pnpm 为 13.5 秒、yarn 为 20.5 秒<sup>[5](https://bun.com/blog/bun-v1.4)</sup> |
| 兼容性 | 截至 1.4 版本，node:http、node:fs、node:cluster、node:timers、node:zlib、node:vm 和 node:stream 通过了 Node 自身测试的 97%；node:events、node:trace_events 和 node:sqlite 通过 100%<sup>[5](https://bun.com/blog/bun-v1.4)</sup> |
| 治理 | MIT 许可；没有等同于 Node.js LTS 系列的长期支持承诺<sup>[3](https://www.infoq.com/news/2023/09/bun-ga-nodejs-alternative/)</sup><sup> • </sup><sup>[2](https://www.nexifer.com/blog/bun-in-production)</sup> |
| 归属 | 由 Oven 开发（融资超过 700 万美元）；2025 年 12 月被 Anthropic 收购，仍保持 MIT 许可，并在 GitHub 上公开开发<sup>[6](https://blog.pragmaticengineer.com/bun-lessons-from-disrupting/)</sup><sup> • </sup><sup>[2](https://www.nexifer.com/blog/bun-in-production)</sup> |

## 架构及其快速的原因

Bun 运行在 JavaScriptCore 上，这是苹果为 WebKit 开发的引擎；而 Node.js 和 Deno 运行在谷歌的 V8 上。两种引擎做出了不同的取舍：JavaScriptCore 优先考虑更快的启动时间和更低的内存占用，使用三个优化编译器；而 V8 侧重于快速执行，使用两个优化编译器，内存消耗更高。<sup>[4](https://developer.mozilla.org/en-US/blog/leveraging-bun-on-vultr-a-superior-node-js-alternative/)</sup>

实现语言在项目发展过程中发生过变化。直至 1.3 版本，Bun 均用 Zig 编写——Zig 是一种强调编译期安全、手动内存分配和避免隐藏控制流的语言；2023 年一项经同行评审的能耗研究（当时 Bun 为 0.5.9 版本）将 Bun 的部分效率归功于 Zig，并测得 Bun 的能耗为 Node.js 的三分之一到六分之一，同时在所测试的各染色体尺寸上运行更快。<sup>[7](https://www.scitepress.org/Papers/2023/121281/121281.pdf)</sup> Bun 1.4 将代码库从 Zig 重写为 Rust。<sup>[5](https://bun.com/blog/bun-v1.4)</sup>

除引擎之外，Bun 以原生代码而非 JavaScript 实现了 fetch、Request、Response、WebSocket 和 ReadableStream 等 Web 标准 API；其包管理器、测试运行器和打包器同样是原生的。<sup>[1](https://bun.com/blog/bun-v1.0)</sup> 在一家出版物的基准测试中，Bun 的 SQLite 实现大幅优于 Node 和 Deno 的对应实现。<sup>[8](https://byteofdev.com/posts/what-is-bun/)</sup>

独立测量结果使厂商的说法变得复杂。一项针对后端工作负载的独立基准分析发现，Bun 与 Node.js 之间没有显著的性能差异；一个专业基准测试系列得出结论：对于 CLI 程序，V8 与 JavaScriptCore 的运行时性能大致相当，现实世界中的开销更可能来自系统开销或实现细节。<sup>[9](https://evertheylen.eu/p/node-vs-bun/)</sup><sup> • </sup><sup>[10](https://just.billywhizz.io/blog/on-javascript-performance-03/)</sup> 一项经同行评审的比较使用 Docker 容器和 Ansible 自动化测量，发现 Bun 在排序和 JSON 处理等同步计算中表现最佳，但在素数检查上落后于 Node.js 和 Deno。<sup>[11](https://journals.rcsi.science/2454-0714/article/view/359397)</sup>

## 一体化工具集

Bun 在一个二进制文件中集成了四款工具：运行时、兼容 npm 的包管理器、兼容 Jest 的测试运行器，以及打包器。<sup>[1](https://bun.com/blog/bun-v1.0)</sup>

**包管理器。** `bun install` 使用全局模块缓存来避免重复从 npm 注册表下载，通过符号链接将项目包链接到中心位置，并存储二进制锁文件。<sup>[1](https://bun.com/blog/bun-v1.0)</sup><sup> • </sup><sup>[8](https://byteofdev.com/posts/what-is-bun/)</sup> 这种速度有一个有据可查的正确性取舍：运行 `bun install` 时，Bun 不会检查网络以确保本地缓存的包是正确的，即使指定了最新版本也是如此——与 npm 或 pnpm 相比，它用确定性换来了数秒的延迟节省。<sup>[6](https://blog.pragmaticengineer.com/bun-lessons-from-disrupting/)</sup>

**测试运行器和打包器。** 在一项针对 zod 测试套件的厂商基准测试中，Bun 的测试运行器速度是 Jest 的 13 倍、Vitest 的 8 倍；使用 esbuild 自身的基准测试，Bun 的打包器速度是 esbuild 的 1.75 倍、Parcel 2 的 150 倍、Rollup 加 [Terser](https://www.edgepedia.org/zh/terser) 的 180 倍、Webpack 的 220 倍。<sup>[1](https://bun.com/blog/bun-v1.0)</sup> 这些都是厂商公布的数据。在一个生产案例研究中，一家在所有服务中用 Bun 替换 Node.js 的公司发现，Bun 的原生打包取代了外部打包库，将三个单页应用（SPA）包的构建时间从 1.7 秒缩短到 650 毫秒。<sup>[12](https://engineering.oakoliver.com/articles/why-we-mass-replaced-nodejs-with-bun-in-production)</sup>

**脚本运行器。** 厂商数据显示，`bun run` 平均耗时 7 毫秒，而 `npm run` 为 176 毫秒、`yarn run` 为 131 毫秒、`pnpm run` 为 259 毫秒。<sup>[1](https://bun.com/blog/bun-v1.0)</sup> 独立的 hyperfine 热启动基准测试发现，在一个脚本上，`bun run` 的速度是 `deno run` 的 1.97 倍、`node` 的 2.41 倍（平均 22.2 毫秒）；在第二个脚本上分别是两者的 1.92 倍和 2.37 倍——差距真实存在，但更小。<sup>[13](https://www.peterbe.com/plog/comparing-deno-vs-node-vs-bun)</sup>

## 实践中的性能与兼容性

厂商的安装基准测试差距很大：在一个 T3 技术栈的 Next.js 项目上，无缓存、无锁文件的首次安装，bun 1.4 耗时 1.41 秒（376 MB），而 npm 12.0.2 为 18.1 秒（503 MB）、pnpm 11.21.0 为 13.5 秒（1.8 GB）、yarn 1.22.22 为 20.5 秒（498 MB）；在热缓存、无锁文件的情况下，`bun install` 耗时 251 毫秒，而 npm 为 7.61 秒。<sup>[5](https://bun.com/blog/bun-v1.4)</sup>

Node.js 兼容性是该项目宣称的目标，但据其自身所述并不完整：Bun 1.4 声明 Bun 尚未 100% 兼容 Node.js，尽管在实践中现有 JavaScript 生态的很大一部分无需修改即可运行。<sup>[5](https://bun.com/blog/bun-v1.4)</sup> 1.4 版本新增了 1,517 个来自 Node.js 测试套件的测试，每次提交都会运行，被称为自 1.0 以来最大的兼容性飞跃，并修复了超过 2,900 个问题。<sup>[5](https://bun.com/blog/bun-v1.4)</sup> 有记录的差距包括：node:v8 模块不受支持，因为 Bun 不使用 V8；直接使用 V8 C++ API 的包自 v1.1.25 起仅获得部分支持（bun:ffi 作为实验性替代方案存在）；node:vm 被标记为部分支持；node:worker_threads 缺少 stdin/stdout/stderr 和 resourceLimits 选项；node:inspector 除 Profiler API 外实现甚少。<sup>[1](https://bun.com/blog/bun-v1.0)</sup><sup> • </sup><sup>[2](https://www.nexifer.com/blog/bun-in-production)</sup>

生态中的包在实践中出现过问题。一位开发者迁移了一个包含 300 多个包、约 10 万行代码的单体仓库（monorepo），发现工作区解析无法正常工作，导致 node_modules 中出现重复的 React 版本和“无效的 Hook 调用”错误，需要数小时去重；并且 ts-json-schema-generator 在 Bun 下行为不同。<sup>[14](https://github.com/oven-sh/bun/discussions/3955)</sup> 在一次上手评估中，一个由 Bun 驱动的应用在打包、服务器、数据库、身份验证和 WebSocket 方面均正常工作，但使用 Cypress 进行端到端测试时因 HPE_INVALID_CONSTANT 错误而失败，原因是 Cypress 无法解析 Bun 的 HTTP 响应；同一评估报告称常见任务出现段错误，并得出结论：在测试时 Bun 尚未达到生产就绪状态。<sup>[15](https://labzero.com/blog/can-bun-eat-node-js-s-lunch-testing-the-trendy-toolkit)</sup> 一家较早的出版物指出，由于运行时缓存问题，Bun 完全不支持 Vite，不过支持工作正在进行中。<sup>[8](https://byteofdev.com/posts/what-is-bun/)</sup>

## 与 Node.js 和 Deno 的比较

| | Bun | Node.js | Deno |
|---|---|---|---|
| 创建时间 | 2021 | 2009 | 2018 |
| 引擎 | JavaScriptCore | V8 | V8 |
| 实现语言 | 直至 1.3 用 Zig，1.4 起用 Rust | C++ | Rust |
| 权限系统 | 无 | 无 | 有 |

<sup>[8](https://byteofdev.com/posts/what-is-bun/)</sup>

权限差异对某些用途具有决定性：与 Deno 的权限模型不同，Bun 没有权限沙箱，因此如果威胁模型包含运行不完全可信的代码，这一差异就比其他考虑因素更重要。<sup>[2](https://www.nexifer.com/blog/bun-in-production)</sup> Node.js 提供带有明确支持终止日期的长期支持（LTS）发布系列，而 Bun 没有提供可比的长期支持承诺，因此跟进新版本是保持更新的[唯一](https://www.edgepedia.org/zh/the-1)受支持方式。<sup>[2](https://www.nexifer.com/blog/bun-in-production)</sup> 在经同行评审的工作负载测试中，Bun 在同步计算中领先，Deno 在异步操作中表现出高性能（归功于其使用 Rust 和 Tokio 库），而 Node.js 在同步任务中保持稳定。<sup>[11](https://journals.rcsi.science/2454-0714/article/view/359397)</sup> Bun 采用 MIT 许可，旨在实现完整的 Node.js API 兼容性。<sup>[3](https://www.infoq.com/news/2023/09/bun-ga-nodejs-alternative/)</sup>

## 近期发展

Bun 1.0 于 2023 年 9 月发布，附带一个实验性的原生 Windows 构建，仅支持 JavaScript 运行时；包管理器、测试运行器和打包器被禁用，直至更加稳定。<sup>[1](https://bun.com/blog/bun-v1.0)</sup> 本文所记录的重大版本 Bun 1.4 将代码库从 Zig 重写为 Rust，新增了 1,517 个 Node.js 测试套件测试和超过 2,900 项修复，并新增了 Bun.WebView 无头浏览器自动化、Bun.Image、Bun.markdown、Bun.cron()、Bun.Terminal、`bun run --parallel`、`bun test --parallel`、`bun audit fix`、`bun dedupe` 和 `bun prune`。<sup>[5](https://bun.com/blog/bun-v1.4)</sup> 它将空闲 CPU 使用率降至原来的五分之一，内存使用量最多降低 35%，在 Linux 上启动速度提高 50%；HTTP 服务器应用的内存使用量减少了 13% 到 48%。<sup>[5](https://bun.com/blog/bun-v1.4)</sup> 在 Windows 上，Bun 1.4 启动 hello.js 耗时 15.5 毫秒，而 Node.js 26 为 40.1 毫秒，峰值内存为 16.8 MB 对 32.5 MB——与 Bun 1.3.14 的 39.0 毫秒和 46.5 MB 相比变化巨大。<sup>[5](https://bun.com/blog/bun-v1.4)</sup> 2025 年 12 月，Anthropic 宣布已收购 Bun，将这笔交易描述为加速 [Claude Code](https://www.edgepedia.org/zh/claude-code) 的一种方式，项目仍保持 MIT 许可。<sup>[2](https://www.nexifer.com/blog/bun-in-production)</sup>

## 采用与批评

已有生产环境迁移案例的记录。Trigger.dev 将一个生产服务从 Node.js 迁移到 Bun，报告吞吐量提升了 5 倍，实现方式是通过使用 Bun.serve 添加一个 Bun 入口点，并将其接入一个已经与传输层无关的连接层。<sup>[16](https://trigger.dev/blog/firebun)</sup> AWS 高级软件开发工程师 Mitchell Kossoris 在 [AWS Lambda](https://www.edgepedia.org/zh/aws-lambda) 上对 Bun 进行了基准测试：Node 的冷启动次数更少，但 Bun 在 API Gateway 响应时间上快 50%，AWS Lambda 正在考虑原生支持 Bun。<sup>[3](https://www.infoq.com/news/2023/09/bun-ga-nodejs-alternative/)</sup>

批评主要集中在兼容性声明和取舍上。Node.js 技术指导委员会成员 Matteo Collina 批评了 Bun 1.0 的兼容性声明，指出 [Fastify](https://www.edgepedia.org/zh/fastify) 和 Pino 在发布时不受支持，并称 Bun“不在乎与 npm 生态中相当一部分的向后兼容性”。<sup>[3](https://www.infoq.com/news/2023/09/bun-ga-nodejs-alternative/)</sup> 这与 Bun 自己 1.0 声明中“几乎可以运行任何现存的 Node.js 应用”直接矛盾；两种立场在同一版本发布时发表，至今仍未调和。<sup>[1](https://bun.com/blog/bun-v1.0)</sup> 安装速度与正确性之间的取舍，以及缺乏 LTS 承诺和沙箱，是反复出现的批评。<sup>[6](https://blog.pragmaticengineer.com/bun-lessons-from-disrupting/)</sup><sup> • </sup><sup>[2](https://www.nexifer.com/blog/bun-in-production)</sup>

## 在 Bun、Node.js 和 Deno 之间做选择

有记录的证据支持几个实际区别。Bun 最明显的可测量优势是启动时间、安装速度和同步计算工作负载；其最明显的代价是缺少沙箱、没有 LTS 系列，以及残留的 Node.js API 差距——这些差距会在特定包中显现，例如 Cypress、Vite（历史上）和使用 V8 C++ API 的原生插件。<sup>[5](https://bun.com/blog/bun-v1.4)</sup><sup> • </sup><sup>[2](https://www.nexifer.com/blog/bun-in-production)</sup><sup> • </sup><sup>[15](https://labzero.com/blog/can-bun-eat-node-js-s-lunch-testing-the-trendy-toolkit)</sup> 对于后端 HTTP 工作负载，独立分析发现与 Node.js 没有显著的性能差异，因此迁移的理由应该是工具集和启动优势，而不是假设的吞吐量提升。<sup>[9](https://evertheylen.eu/p/node-vs-bun/)</sup> 迁移成本差异很大：trigger.dev 的服务迁移主要是接线工作，因为其连接层已经与传输层无关；而 300 个包的单体仓库迁移则需要数小时的依赖去重。<sup>[16](https://trigger.dev/blog/firebun)</sup><sup> • </sup><sup>[14](https://github.com/oven-sh/bun/discussions/3955)</sup>

## References

1. [Bun 1.0, Bun Blog](https://bun.com/blog/bun-v1.0)
2. [Bun in production: an honest evaluation of the all-in-one runtime, Nexifer Labs](https://www.nexifer.com/blog/bun-in-production)
3. [Node.js Alternative Bun Now Generally Available, InfoQ](https://www.infoq.com/news/2023/09/bun-ga-nodejs-alternative/)
4. [Leveraging Bun on Vultr: A superior Node.js alternative, MDN Blog](https://developer.mozilla.org/en-US/blog/leveraging-bun-on-vultr-a-superior-node-js-alternative/)
5. [Bun 1.4, Bun Blog](https://bun.com/blog/bun-v1.4)
6. [Bun: lessons from disrupting a tech ecosystem, The Pragmatic Engineer](https://blog.pragmaticengineer.com/bun-lessons-from-disrupting/)
7. [An Analysis of Energy Consumption of JavaScript Interpreters with Evolutionary Algorithm Workloads, SCITEPRESS](https://www.scitepress.org/Papers/2023/121281/121281.pdf)
8. [What is Bun, and does it live up to the hype?, Byte of Dev](https://byteofdev.com/posts/what-is-bun/)
9. [Node vs Bun: no backend performance difference, Evertheylen](https://evertheylen.eu/p/node-vs-bun/)
10. [On JavaScript Performance, part 3: Command and Conquer, just.billywhizz.io](https://just.billywhizz.io/blog/on-javascript-performance-03/)
11. [A comparative analysis of the performance of JavaScript code execution environments: Node.js, Deno and Bun, RCSI Journals](https://journals.rcsi.science/2454-0714/article/view/359397)
12. [We Replaced Node.js With Bun Across Every Production Service, Oak Oliver Engineering](https://engineering.oakoliver.com/articles/why-we-mass-replaced-nodejs-with-bun-in-production)
13. [Comparing Deno vs Node vs Bun, Peterbe.com](https://www.peterbe.com/plog/comparing-deno-vs-node-vs-bun)
14. [Large Codebase Migration Story, oven-sh/bun Discussion #3955](https://github.com/oven-sh/bun/discussions/3955)
15. [Can Bun Eat Node.js's Lunch? Testing the Trendy Toolkit, Lab Zero](https://labzero.com/blog/can-bun-eat-node-js-s-lunch-testing-the-trendy-toolkit)
16. [We replaced Node.js with Bun and got 5x throughput, trigger.dev](https://trigger.dev/blog/firebun)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Named software products and platforms

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/bun-javascript-runtime

English original: https://www.edgepedia.org/bun-javascript-runtime
