首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >vercel runtime node、bun、rust 对比

vercel runtime node、bun、rust 对比

原创
作者头像
TomoriNao
发布2026-04-03 17:30:05
发布2026-04-03 17:30:05
1250
举报
文章被收录于专栏:每月技术成长每月技术成长

vercel 已于 October 28, 2025 官方支持 bun runtime,于Dec 8, 2025 官方支持 rust runtime。本文将从 cold start、mem usage 两个角度对 node、bun、rust 三个 runtime 进行分析比较。

测试结果

vercel bun runtime cold start
vercel bun runtime cold start
vercel node runtime cold start
vercel node runtime cold start
vercel rust runtime cold start
vercel rust runtime cold start
  1. 由上图可知,从 Cold start time 角度来说,$bun >> node >> rust$ , rust 的 cold start time 远小于 bun && node 是理所应当的,奇怪之处在于 bun 的 cold start time 是 node 的三倍,这与众多测评中 bun 与 node 的性能不符,应当是 vercel 对于 bun 的优化不到位所致。
  2. 同样由上图可知,从 mem usage 角度来说,$bun \approx node > rust$, bun runtime 的内存占用略大于 node runtime, rust runtime 相较于 bun 和 node 能够节约 30MB ~ 40MB 内存,这在内存价格飞速上涨的 2026 年,实在是难能可贵。

总结

  • 在大部分人印象中 bun 性能及内存占用要优于 node,但由于 vercel 的适配不到位,node 仍然是 在vercel 上更优的 runtime,而 rust runtime 在 cold start time 和 mem usage 上都优于 node,对于追求性能的开发者来说,值得一试(截止目前,在 vercel 上使用 rust runtime 的文档仍然极少,需要谨慎考虑)
  • TODO:对于重负载下 bun, node, rust 在 vercel 的表现,仍然需要进行更多测试

FAQ

  1. 为什么仅测试 cold start? 由于仅使用简易代码(返回“hello”字符串)进行测试,因此三个 runtime 的 hot start 差异较小,无分析价值
  2. 如何进行测试? 通过在 vercel.json 中设置 "bunVersion": "1.x" ,即可启用 bun runtime,不进行 runtime 配置,则启用默认 node runtime(22.X),在 cargo.toml 中设置vercel_runtime = { version = "2" },即可启用 rust runtime。

测试代码

  1. bun && node runtime 测试代码
代码语言:ts
复制
import { VercelRequest, VercelResponse } from "@vercel/node";

module.exports = (request: VercelRequest, response: VercelResponse) => {

  let who = 'anonymous';

  response.status(200).send(`Hello ${who}!`);

};
  1. rust runtime 测试代码
代码语言:toml
复制
# 配置文件 
[package]
name = "rust-hello-world"
version = "0.1.0"
edition = "2024"

[dependencies]
tokio = { version = "1", features = ["full"] }
vercel_runtime = { version = "2" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

[[bin]]
name = "hello"
path = "api/hello.rs"
代码语言:rust
复制
// 测试代码 
use serde_json::{Value, json};
use vercel_runtime::{Error, Request, run, service_fn};

#[tokio::main]
async fn main() -> Result<(), Error> {
    let service = service_fn(handler);
    run(service).await
}

async fn handler(_req: Request) -> Result<Value, Error> {
    Ok(json!({
        "message": "Hello, world!",
    }))
}

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 测试结果
  • 总结
  • FAQ
  • 测试代码
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档