Raw Mode
Performance

Node.js deserves some respect

Ishtmeet Singh//19 min read
#nodejs#performance#benchmarks

I think we've become a little too comfortable treating Node.js as a punchline.

Take the argument that it is single-threaded, therefore it cannot scale. Or that it isn't the best choice for heavy computation, therefore it has no business running a serious backend. Or the suggestion that finding a faster Rust implementation settles whether someone should have written their application in JavaScript.

Those are enormous conclusions. We should probably ask them to carry some evidence.

There are good reasons to choose Rust. There are good reasons to choose Go. There are applications where I would want tighter control over memory, more predictable execution, or a very different concurrency model. We can discuss all of that. But when a specific limitation becomes permission to dismiss everything a tool does well, the discussion starts to look like a pile-on.

And Node does a lot of things well. An almost unreasonable amount, considering how little code you sometimes need to ask it to do them.

In my previous post, I built a link preview function and kept coming back to one question: what work is this code actually doing? This time I want to ask a related question. How much work can a small Node program get through, and what is happening underneath those few lines to make it possible?

So I wrote some servers and measured them. Plain Node. The node:http that comes with the runtime.

Let's give the little program a job

Here is the JSON endpoint from the Node implementation, on its own:

js
import { createServer } from 'node:http';

createServer((req, res) => {
  if (req.method !== 'GET' || req.url !== '/json') {
    res.writeHead(404).end();
    return;
  }

  const name = req.headers['x-name'] ?? 'world';
  const body = JSON.stringify({
    message: `Hello, ${name}!`,
    id: 42,
    ok: true,
  });

  res.writeHead(200, {
    'content-type': 'application/json',
    'content-length': Buffer.byteLength(body),
  });
  res.end(body);
}).listen(3000, '127.0.0.1');

Save it as server.mjs, run node server.mjs, and request /json. That's the whole setup.

Each request reads a header, constructs an object and serializes it. The greeting changes when the header changes. Handing back a response prepared before the test would skip part of the work we're trying to measure.

I gave the same job to Rust with Axum, Bun with Bun.serve, Go's standard net/http, and Go with Fiber. Fiber is a performance-focused contender; calling any framework "the fastest" without specifying the workload would get us right back into the problem this post is about.

The local machine was an Apple M1 Max with 10 CPU cores and 32 GiB of memory, running macOS. The versions were Node 24.13.1, Bun 1.3.2, Go 1.26.0, Rust 1.91.1, Axum 0.8.9 and Fiber 3.5.0. These are the versions tested, rather than a claim about the newest release of each project.

Each server ran in its own process. Node and Bun used one JavaScript main thread; Axum used Tokio's current-thread executor; Go used GOMAXPROCS=1. Runtime helper threads could still run, and these were not CPU-pinned or CPU-quota-controlled tests. The load generator ran on the same machine. Treat the numbers as a comparison of these implementations under this local setup, rather than a universal ranking or a per-core efficiency measurement.

For each test I used 64 HTTP/1.1 connections with keep-alive, a three-second warmup, and three ten-second measurements in shuffled order. Rust used a release build. There was no TLS, compression, request logging or HTTP pipelining. Before timing a server, the test runner checked response contents, escaping, checksums and error cases.

Here is the dynamic JSON result. Throughput is the median across the three measurements; the range includes every run. RSS is the largest sampled resident-memory value for the server process.

ImplementationRequests/secRun rangePeak sampled RSS, MiB
Node.js / node:http56,33150,043 - 57,34997.9
Bun / Bun.serve84,38876,899 - 85,40647.1
Rust / Axum89,08688,924 - 90,3405.9
Go / net/http73,47771,721 - 74,05616.7
Go / Fiber99,85297,571 - 108,92618.4

The complete implementations, dependency locks, commands, checks and raw measurements are in the benchmark download. The short measurement windows and shared laptop matter. Please keep them attached to these numbers if you quote them.

There's an entire runtime inside that short bar

Vanilla Node handled 56,331 requests per second at the median. That's 63.2% of Axum's throughput and 56.4% of Fiber's in this test. Both implementations have a meaningful capacity advantage, and their sampled memory use is much lower.

But pause on the absolute number for a moment. More than fifty-six thousand requests per second through this handler in the test server. JavaScript, an object, a call to JSON.stringify, and the built-in HTTP module. I think that's pretty fantastic.

The three Node runs ranged from about 50.0 thousand to 57.3 thousand requests per second. There is visible variation here, which is why I'm showing the range and keeping the claims local.

A request-per-second number is a capacity measurement for a particular job. It is not a count of customers, a prediction of your production traffic, or permission to multiply by the number of seconds in a month and announce that you've built the next enormous social network. This endpoint has no authentication, database or business logic.

But the work it does is real. Connections arrive. HTTP gets parsed. JavaScript runs. Objects are created. JSON is produced. Bytes go back to clients. Memory has to be managed while all of this continues.

Look back at that program. You can read the whole thing without scrolling very far. The gap between how much machinery is involved and how little machinery you have to manage is one of the things I love about Node.

Making a difficult thing approachable is an engineering achievement. It deserves some of the admiration we give to making a difficult thing faster.

JavaScript doesn't run on good intentions

There is a strange implication in the phrase "it's just JavaScript," as if the CPU reluctantly tolerates it while waiting for a proper language to arrive.

Node runs JavaScript through V8. V8 can compile JavaScript into machine code, and its optimizing compilers use information gathered while a program runs to improve execution. Dynamic language features make this work complicated. They don't make optimization disappear. Node's V8 introduction and V8's explanation of its optimizing JIT are good places to look at the machinery.

So "Node isn't CPU-optimized" is a poor description. There is a great deal of CPU optimization inside the thing.

There are still costs. Allocations, garbage collection, dynamic behavior and changes that invalidate optimization assumptions can all matter. A systems language gives you different ways to control the work. The useful question is how those costs show up in the program you are running.

And remember that Bun's row in the table is JavaScript too. It uses JavaScriptCore, while Node uses V8, and the two runtimes have different HTTP implementations. A comparison between them includes all of those choices. It cannot sensibly establish that JavaScript itself is incapable of serving requests quickly. We can welcome a faster JavaScript runtime and still appreciate the one already doing useful work. Somebody releasing a faster server doesn't suddenly make an unchanged Node application slower.

To make that question concrete, the next endpoint receives a 64 KiB body and computes a 32-bit FNV-1a checksum. The core JavaScript loop is this:

js
let hash = 2166136261;

for (let i = 0; i < bytes.length; i++) {
  hash = Math.imul(hash ^ bytes[i], 16777619) >>> 0;
}

The Rust and Go implementations perform the same byte-by-byte calculation with wrapping 32-bit arithmetic. Every server reads and buffers the request body and returns the checksum as JSON. The test runner also supplies different inputs and checks the answers independently. This is an HTTP upload-and-computation test, including its buffering costs, rather than a pure loop microbenchmark.

The p99 column describes the slower end of the requests: 99% completed within that time in a run. The values below are the medians of the three runs' p99 values.

ImplementationRequests/secRun rangep99, msPeak sampled RSS, MiB
Node.js / node:http7,8636,073 - 7,87415.32364.9
Bun / Bun.serve8,3138,190 - 8,31714.7069.7
Rust / Axum9,4569,365 - 9,4777.8534.6
Go / net/http7,6047,551 - 7,63080.1824.3
Go / Fiber9,7039,419 - 9,72710.2121.3

Node reached 7,863 requests per second, about 83.2% of Axum's throughput. Each request contains 64 KiB, so the median corresponds to about 491 MiB of input bodies processed per second. That's a substantial amount of byte-by-byte calculation for our little JavaScript loop, even with the HTTP and buffering work included.

There are costs alongside it. Node's median run p99 was 15.32 ms against Axum's 7.85 ms. Its largest RSS sample was about 365 MiB against 35 MiB. One Node run fell to about 6,073 requests/sec. Those observations are part of the result, too. They justify investigating memory, tail latency and variability; short RSS samples alone cannot diagnose a leak.

What this experiment does show is that the JavaScript calculation gets useful work done at a serious rate. An application with tighter memory limits or latency requirements may make a different trade, and the table gives it reasons to.

I would never use a single checksum loop to pronounce one language universally faster than another. The same restraint should apply when the result makes JavaScript look bad. A workload is evidence about that workload. We get a better engineering conversation when we leave the conclusion at the size the evidence can support.

The CPU criticism has a precise version

There is a criticism worth taking seriously here: while a JavaScript callback is doing a long synchronous calculation on the main thread, other callbacks on that thread have to wait.

If a request handler spends 200 ms crunching data without yielding, it delays unrelated work in the same event loop. Giving the function an async keyword doesn't move that calculation to another thread. A promise is not a second CPU. Node's guide to blocking the event loop explains this constraint directly.

That's a reason to design the application carefully. Depending on the job, you might partition the work, use a bounded worker pool, put it in a separate process or service, or choose a different implementation for that part of the system.

Node's worker threads can execute JavaScript in parallel. They come with startup, scheduling and data-transfer costs, so spawning a new worker for every tiny task can be a bad trade. A pool lets you reuse workers and control how much CPU work you admit. The worker-thread documentation explicitly describes CPU-intensive JavaScript as a use case.

A native addon is another option. Node-API supports addons written in several languages, including Rust through language bindings. There is something pleasing about a supposed language rivalry ending with the two languages doing useful work together.

None of these options removes the need to measure. They do make "Node cannot do CPU work" a pretty strange place to stop thinking.

Now give it something to wait for

The JSON endpoint spends very little time waiting on another service. That makes HTTP handling and response generation a large part of its job. Plenty of application endpoints spend their time differently.

For the next test, each server makes a real HTTP request to a separate local upstream process. That upstream waits about ten milliseconds and returns a small JSON response. The server reads the response and sends it back. Connections are reused. There are still only 64 concurrent incoming requests.

This is a controlled HTTP dependency, not a pretend database benchmark. It lets us study one specific change: what happens when a request includes waiting on another process?

ImplementationRequests/secp99, msProcess CPU, %Peak sampled RSS, MiB
Node.js / node:http5,40414.5836.2196.0
Bun / Bun.serve5,19614.0433.0132.5
Rust / Axum5,41713.4221.910.2
Go / net/http5,53313.1929.718.3
Go / Fiber5,50113.0627.320.1

CPU here is process CPU time divided by elapsed time; 100% means one CPU-second per wall-clock second. It includes runtime helper threads. The p99 and CPU columns use medians across runs, while RSS shows the largest sample.

The throughput results gather into a much narrower band. Node's median is 5,404 requests/sec; Axum's is 5,417. That is 99.8% of Axum's throughput in this configuration.

The reason to be careful is right there in the setup. With 64 requests in flight and a roughly ten-millisecond wait in each one, even an otherwise instantaneous server has a rough ceiling of 6,400 requests/sec. Waiting and the concurrency limit constrain this experiment. Increasing concurrency could expose different limits. The CPU and memory columns also show that similar throughput doesn't imply equal resource cost.

Still, compare the three jobs we've given the same runtimes.

Node throughput as a percentage of Axum throughput: 63.2% for dynamic JSON, 83.2% for a 64 KiB checksum POST, and 99.8% for an HTTP upstream with a ten-millisecond wait. Local M1 Max measurements.

The ratio changed with the work. That is why a claim such as "Node is one-quarter as fast as Rust" needs a much longer sentence around it.

Node doesn't need to keep a JavaScript callback occupied for the entire time a remote service is working. It can initiate network I/O, return control to the event loop, and run other callbacks. When an operation can make progress, execution continues. Underneath that interface, libuv works with the operating system's networking facilities. Ordinary socket I/O isn't implemented by assigning a libuv worker-pool thread to every waiting request. libuv's design documentation explains that distinction.

Other runtimes have effective ways to overlap I/O too. The thing worth appreciating about Node is how directly this model fits a JavaScript application: start some work, let other work proceed, and handle the result when it arrives.

It also helps explain why changing languages doesn't produce a fixed multiplier for an entire service. Consider a hypothetical request that spends 2 ms computing and 18 ms waiting. If the computation becomes five times faster, and everything else stays the same, the request takes 18.4 ms instead of 20 ms. That's an 8% reduction in latency.

The assumptions matter: no queueing, unchanged upstream time, and the same work being done. Near CPU saturation, reducing computation can improve queueing, capacity and latency much more. Less CPU work can also mean lower infrastructure cost. There is no need to deny those benefits to recognize that your users don't experience an isolated benchmark loop.

Make the servers answer the same amount of traffic

Maximum throughput is useful, but it gives each server a different amount of work per second. I also sent the JSON endpoint a target of 2,000 requests per second in each implementation.

For these runs the load generator used scheduled requests and latency correction, so delays relative to the intended schedule were included. The table shows the median of the three runs' p99 values: the latency below which 99% of measured requests in each run fell. That is different from pooling every request into one percentile.

Implementationp50, msp95, msp99, ms
Node.js / node:http0.201.043.10
Bun / Bun.serve0.170.752.42
Rust / Axum0.170.773.06
Go / net/http0.180.863.17
Go / Fiber0.160.773.20

Every implementation sustained approximately the requested rate. Node's median run p99 was 3.10 ms; Axum's was 3.06 ms. That closeness at this rate doesn't erase Axum's higher throughput ceiling or lower resource use. It tells us something else: well below saturation, the experience of this tiny endpoint is much closer than the maximum-throughput numbers might suggest. These percentiles include local scheduling effects, and the small differences here aren't a basis for declaring a latency winner.

Choosing a runtime for a service means deciding what latency, capacity and resource use you need, then finding out whether an implementation delivers them. A faster alternative can be valuable. Its existence alone doesn't tell you that your current system fails its requirements.

Watch what happens when the reader is slow

There is another capability I wish got as much attention as tiny JSON responses: moving data without having to keep all of it in memory.

The interesting moment comes when the destination is slower than the source. Maybe you're serving a download to a poor connection. Maybe you're processing a file and the next stage cannot keep up. Continuing to produce data as fast as possible means the waiting data has to accumulate somewhere.

Node streams have a way to communicate that pressure. A writable can signal that the producer should pause. A pipeline coordinates the flow and propagates stream failures. Here is the central operation in a file-copy example:

js
import { createReadStream, createWriteStream } from 'node:fs';
import { pipeline } from 'node:stream/promises';

await pipeline(
  createReadStream('large-file.bin'),
  createWriteStream('large-file-copy.bin'),
);

That small API carries an agreement about how the pieces cooperate. You still need suitable sources, sinks and buffer sizes; a stream API cannot prevent application code from collecting everything into an array. But when the participants respect backpressure, the program can process the file incrementally. The stream documentation describes both the buffering behavior and pipeline().

I ran a separate demonstration that reads a 256 MiB file in 64 KiB chunks and sends it to a writable that deliberately waits four milliseconds before accepting the next chunk. This is a paced stream experiment, rather than a disk-speed or HTTP-throughput comparison.

All three runs delivered the complete 256 MiB. The largest observed process RSS ranged from 77.1 to 96.7 MiB, including the runtime itself. The sampled readable and writable queues each stayed at or below 64 KiB. The process didn't need a 256 MiB buffer to handle a 256 MiB file.

These are sampled observations, not a guarantee that total memory equals two stream buffers: RSS includes other allocations, and a high-water mark is a backpressure threshold. What the demonstration makes visible is the cooperation. The slower destination gets a say in how quickly the source proceeds.

That is useful software engineering hiding inside an API you can explain in a few paragraphs. We ought to be allowed to find it impressive.

Read the program before blaming the runtime

The link preview from my previous post is a good example of why I care about this.

Suppose 300 people ask for the same preview while the first fetch is still running. A naive implementation might perform the same download and parsing work 300 times. Keeping the in-flight promise lets callers share that work. Reading only the part of the page we need removes more work. Giving requests a deadline stops waiting forever.

You can apply those ideas in Rust or Go too. That's part of the point. They are decisions about the application. A faster implementation of unnecessary work is still doing unnecessary work.

Node gives me a comfortable place to express those decisions. A map, a promise, a fetch, a stream. I can read the code and follow what happens when several requests arrive together. There are still races across asynchronous boundaries and shared-state problems to think about; an event loop does not make application logic automatically correct. But I can reason about the flow without first building a large amount of supporting machinery.

There is value in being able to inspect a feature, understand its behavior and change it confidently. There is value in a team sharing language knowledge across its client and server. Those benefits depend on the team and the project, so I can't honestly put them in a requests-per-second column. I still count them when choosing tools.

And when performance is wrong, the runtime gives you somewhere concrete to start. Node can collect CPU profiles, expose event-loop delay measurements and help you inspect memory. You can ask which function is expensive and whether the event loop is falling behind. CPU profiling and performance hooks are built in.

That feels like a more useful next step than declaring a language guilty because an endpoint is slow.

Give it a fair standard

Node has issues. Garbage collection costs time. Memory use can limit how many processes fit on a machine. Blocking work can hurt unrelated requests. Dependencies need care. Some applications would be better served by a different runtime, and some expensive components would benefit from being rewritten.

Saying that every tool has issues doesn't excuse any of those things. It asks us to apply the same standard: identify the constraint, measure its effect, and decide whether the tradeoff is acceptable for the job.

If the extra capacity from a Rust implementation changes the economics of your service, that's an excellent reason to use it. If Go's deployment model and concurrency tools suit your team, use them. If Bun improves your application on the dimensions you care about, measure that and take the win.

But a small Node program that meets its latency target, handles its workload and remains understandable to the people responsible for it is doing its job. Calling it unserious because a different program has a longer benchmark bar tells us very little about the quality of that decision.

I look at the little server near the top of this post and see an enormous amount of engineering made available through an ordinary JavaScript function. Then I look at the streams, the network I/O, the workers and the tools for finding out where the time went.

I think that is a remarkable thing to have on your computer. The code stays small because an enormous amount of careful work has already been done for you. I wish we were a little slower to sneer at that.

Node.js deserves some respect.