Lesson 7 of 9 · 25m
Measuring Bun Performance Without Fooling Yourself
Separate startup, install, throughput, latency, memory, and dependency-dominated work before claiming Bun is faster for your service.
Bun is genuinely fast in several important places. That is why the worst performance claims around it are so sloppy: there is real signal underneath the hype. A senior engineer does not ask, 'Is Bun faster?' They ask, 'Faster at what phase, under what workload, measured how, and at what operational cost?'
Split performance into phases
install time dependency resolution, disk writes, network
startup time process launch, module loading, initialization
request throughput sustained concurrent work
tail latency p95/p99 behavior under saturation
memory footprint baseline and growth over time
developer iteration test startup, typecheck, rebuild loopBun often improves install and startup dramatically. Request throughput depends heavily on what your service actually does. If 90% of request time is PostgreSQL, object storage, or a downstream API, the JavaScript runtime is rarely the bottleneck.
Build a benchmark with real dependencies
Bad benchmark:
Bun.serve({
fetch() {
return new Response("hello");
},
});Useful benchmark shape:
Bun.serve({
async fetch(request) {
const session = await validateSession(request);
const rows = await db.query("select id,total from invoices where customer_id = $1 limit 20", [session.customerId]);
return Response.json({ rows });
},
});The second version includes parsing, async scheduling, driver behavior, serialization, backpressure, and realistic allocation. It is still not universal truth, but at least it measures a system resembling production.
Measure with controlled load
Use a repeatable load generator and record machine shape, runtime versions, connection counts, and duration:
oha -z 30s -c 100 --no-tui http://127.0.0.1:3000/invoicesCapture more than mean latency. Means hide queues. You want p50, p95, p99, error count, memory before/after, and CPU saturation. If the process is CPU-bound at 100%, throughput comparisons tell a different story than they do at 20% utilization.
JavaScriptCore versus V8 is not a slogan
Bun uses JavaScriptCore. Node uses V8. Different engines optimize allocation, JIT warmup, regular expressions, typed arrays, and object shapes differently. Small numerical or string-processing workloads can move in either direction. Never extrapolate from one microbenchmark to a heterogeneous service.
Watch memory and long-tail behavior
A runtime can win a 30-second throughput test and lose a week-long production deployment through fragmentation, leaks in native dependencies, or pathological GC behavior under a particular allocation pattern. Run a soak test before migrating important services:
oha -z 10m -c 50 http://127.0.0.1:3000/invoices
ps -o pid,rss,etime,cmd -p "$SERVER_PID"Memory slope matters more than the first reading.
Field notes
- Benchmark exact runtime versions. Bun performance characteristics change quickly across releases.
- Compare cold starts separately from warm throughput; they solve different problems.
- If a benchmark excludes the database but production includes it, the conclusion applies only to the benchmark.
- Publish the harness beside the result. A number without concurrency, duration, hardware, and payload shape is marketing, not engineering.
Was this lesson helpful?