We replaced Node.js with Bun for 5x throughput (trigger.dev)

by pier25 33 comments 59 points
Read article View on HN

33 comments

[−] fleebee 39d ago
I'm puzzled by the title of this post. From what I can gather most, if not all, of the performance improvements came from sacking SQLite and Zod.

They applied optimizations that cut CPU time by ~40% to the Bun version before comparing it with Node. Claiming 5x throughput from "replacing Node.js with Bun" is a wild misrepresentation of the findings.

[−] LaSombra 39d ago
Don’t let facts get in the way of a catchy headline
[−] mannycalavera42 39d ago
:love
[−] whizzter 39d ago
And they include "phase 3 opts" in the phase2 benchmark, so the move to Bun also includes improvements from removing "safeParse". So Node might've been at more than 40% of the performance.

It's sad since these kinds of numbers are interesting, but when there's blatant misrepresentations it just create a stink.

[−] dcre 40d ago
I was curious why bun build --compile would be faster. The docs say:

“Compiled executables reduce memory usage and improve Bun’s start time.

Normally, Bun reads and transpiles JavaScript and TypeScript files on import and require. This is part of what makes so much of Bun “just work”, but it’s not free. It costs time and memory to read files from disk, resolve file paths, parse, transpile, and print source code.

With compiled executables, you can move that cost from runtime to build-time.”

https://bun.com/docs/bundler/executables#deploying-to-produc...

[−] nlehuen 39d ago
The SQL query they replaced was extremely cringe and amateurish ("let's sprinkle DISTINCT until all those pesky redundant rows that come from our inefficient KV metadata schema go away"). The fact they did not acknowledge that and somehow blame it on SQlite made me stop reading on the spot, and be very worried for whoever depends on their products.
[−] mdavid626 39d ago
It's not about Bun, but more about sqlite and zod replacements. Why interpret this as "Bun is faster"?
[−] nikanj 39d ago
Gets more reactions that way
[−] ksec 40d ago

>Next: the runtime itself. Bun has a bun build --compile flag that produces a single self-contained executable. No runtime, no node_modules, no source files needed in the container.

I didn't know that. So Bun is basically a whole runtime + framework all in one with little to no deployment headaches?

[−] jamsinclair 40d ago
The bun build creates a large self-contained executable with no optimisations. Almost like a large electron build.

Deno also provides the same functionality, but with a smaller optimized binary.

Appreciate Bun helping creating healthy competition. I feel like Deno falls under most people's radar often. More security options, faster than Node, built on web standards.

[−] matorl 39d ago
Deno's security options are very useful for AI sandboxes. Broader than node's permissions. Bun badly needs the same.

There's a PR for Bun that gives the same security but it's been sitting for months https://github.com/oven-sh/bun/pull/25911

I want to migrate an existing project to Bun but cannot until it has a security permission system in place.

[−] dsissitka 39d ago
I was curious:

  $ cat app.ts
  console.log("Hello, world!");
  $ cat build
  #!/usr/bin/env bash
  
  bun build --compile --outfile bun-darwin-arm64         --target bun-darwin-arm64         app.ts
  bun build --compile --outfile bun-darwin-x64           --target bun-darwin-x64           app.ts
  bun build --compile --outfile bun-darwin-x64-baseline  --target bun-darwin-x64-baseline  app.ts
  bun build --compile --outfile bun-linux-arm64          --target bun-linux-arm64          app.ts
  bun build --compile --outfile bun-linux-arm64-musl     --target bun-linux-arm64-musl     app.ts
  bun build --compile --outfile bun-linux-x64            --target bun-linux-x64            app.ts
  bun build --compile --outfile bun-linux-x64-baseline   --target bun-linux-x64-baseline   app.ts
  bun build --compile --outfile bun-linux-x64-modern     --target bun-linux-x64-modern     app.ts
  bun build --compile --outfile bun-linux-x64-musl       --target bun-linux-x64-musl       app.ts
  bun build --compile --outfile bun-windows-arm64        --target bun-windows-arm64        app.ts
  bun build --compile --outfile bun-windows-x64          --target bun-windows-x64          app.ts
  bun build --compile --outfile bun-windows-x64-baseline --target bun-windows-x64-baseline app.ts
  bun build --compile --outfile bun-windows-x64-modern   --target bun-windows-x64-modern   app.ts
  
  deno compile --output deno-x86_64-pc-windows-msvc    --target x86_64-pc-windows-msvc    app.ts
  deno compile --output deno-x86_64-apple-darwin       --target x86_64-apple-darwin       app.ts
  deno compile --output deno-aarch64-apple-darwin      --target aarch64-apple-darwin      app.ts
  deno compile --output deno-x86_64-unknown-linux-gnu  --target x86_64-unknown-linux-gnu  app.ts
  deno compile --output deno-aarch64-unknown-linux-gnu --target aarch64-unknown-linux-gnu app.ts
  $ ls -1hs
  total 1.6G
  4.0K app.ts
  4.0K build
   59M bun-darwin-arm64
   64M bun-darwin-x64
   64M bun-darwin-x64-baseline
   95M bun-linux-arm64
   89M bun-linux-arm64-musl
   95M bun-linux-x64
   94M bun-linux-x64-baseline
   95M bun-linux-x64-modern
   90M bun-linux-x64-musl
  107M bun-windows-arm64.exe
  110M bun-windows-x64-baseline.exe
  111M bun-windows-x64.exe
  111M bun-windows-x64-modern.exe
   77M deno-aarch64-apple-darwin
   87M deno-aarch64-unknown-linux-gnu
   84M deno-x86_64-apple-darwin
   92M deno-x86_64-pc-windows-msvc.exe
   93M deno-x86_64-unknown-linux-gnu
  $
Maybe I'm missing some flags? Bun's docs say --compile implies --production. I don't see anything in Deno's docs.
[−] pjmlp 39d ago
Ideally we would still only use JavaScript on the browser, personally I don't care about about the healthy competition, rather that npm actually works when I am stuck writing server side code I didn't ask for.
[−] thewarman 40d ago
This (single executable) is available in node.js now too as SEA mode.
[−] mememememememo 40d ago
How much would you get by moving to Go, Rust or C++?
[−] abustamam 40d ago
I use bun for everything except for monorepos with isolated deployment targets and shared packages. I use yarn or pnpm for monorepos. Maybe it's changed in the last six months but I could never get docker to properly resolve my dependencies when I only want to build the web app, for example, since the bun lock is deterministic based off of all the packages in the repo so isolating a single leaf makes it error.

Maybe I'm doing something wrong but I scoured docs and online and asked multiple AI agents to no avail.

[−] mordae 39d ago
I cringed at those "aaa\0bbb\0ccc\0ddd" Map keys. That's much slower than nested maps and requires allocating the strings, giving GC more work to do.
[−] azinman2 39d ago
So is Bun saying that JSC is much better than v8?
[−] aoeusnth1 39d ago
Why is a map lookup measured in ms instead of us? Something is seriously wrong with these benchmarks.
[−] denys_potapov 40d ago
tl;dr replace SQLite with Map ~ 2x speed up, replace zod validation with ifs ~ 2x speed up. Bun had a memory leak on unresolved promises - now fixed
[−] LeonTing1010 40d ago
[flagged]