We all know that people like benchmarks. They love numbers. Comparing 50,000 requests per second with 100,000 is easy. Understanding exactly what is being measured, and what that means for your application, takes a bit more work.
A common Node.js benchmark serves a tiny, static JSON response. That is useful, but it only exercises a small part of the framework. It matches a route, runs a handler, and sends a response.
It does not tell you much about what happens when you add sessions, validation, security middleware, or server-side rendering. Frameworks also do different amounts of work out of the box. Extra features and safety checks have a cost, and a requests-per-second chart rarely explains what you get for it.
I wanted to get a better picture of where AdonisJS spends its time in those situations. So I started building a private benchmark suite around common application scenarios, comparing with other frameworks where the comparison made sense.
AI tools have made it easier to explore more scenarios, isolate expensive code paths, and test possible improvements. We have also used fuzzing to check that optimizations preserve existing behavior.
The goal is to make AdonisJS faster while keeping the features people use it for. Sometimes that means changing our own code. Sometimes it means following a bottleneck into Node.js itself.
What a Hello World hides
Before getting into the changes, I want to share a few examples from the benchmark suite. Each one shows why we needed to test more than a handler returning a string.
Reading the request changes the comparison
While comparing Bun's HTTP server with Node.js, I noticed how much the result depended on whether the handler actually read the request.
We compared a handler returning a fixed response with one that also checked the URL suffix and a request header. Both returned the same response.
Here are the median results from three runs, in requests per second.
| Runtime | Fixed response | URL + header |
|---|---|---|
| Node.js 26.12.0 | 87,237 | 86,800 |
| Bun 1.4.3 | 146,137 | 120,594 |
Bun's throughput fell by 17.5%, with a drop in all three runs. Node's results varied too much between runs to establish a small effect.
Bun was still faster in both scenarios. But the size of its lead changed once the handler inspected the request.
These measurements cover the complete handler and HTTP response. They do not isolate the cost of reading a property or prove when either runtime parses request data. Node and Bun also expose different URL representations, so this is not a comparison of identical parsing operations.
What we can say is simpler. A fixed-response benchmark does not tell us how the same servers will compare once handlers start using the request.
Middleware exposed a cost we were missing
The second example was in AdonisJS itself.
Our first middleware benchmarks showed a large drop in throughput as we added middleware. A handler without middleware could not expose that cost.
To measure the fix, we compared two builds of Fold, the AdonisJS dependency injection container, and kept the rest of the application unchanged.
| Scenario | Before, req/s | After, req/s | Change |
|---|---|---|---|
| 10 pass-through middleware | 34,126 | 52,661 | +54.3% |
| 10 middleware reading a header and updating request state | 33,060 | 50,165 | +51.7% |
| 4 global middleware, 1 named middleware, and a lazy-loaded controller | 43,474 | 61,644 | +41.8% |
The gains appeared in all three repetitions and were larger than the variation in our unchanged-build controls. All warmup and measured phases completed without errors or timeouts.
These are gains for the tested pipelines. They are not a promise that every AdonisJS application becomes 40 to 50% faster. A closure-only control did not show a consistent improvement.
That is why the suite includes more than minimal handlers. We use isolated benchmarks to investigate individual costs, then HTTP scenarios to check whether those changes improve request throughput.
One route tells us little about a routing table
A Hello World benchmark usually registers a single route. It tells us little about what happens when an application has hundreds of routes, or when a request matches none of them.
Our routing benchmarks varied the number of routes and where the requested route appeared in registration order. That exposed a cost a single-route benchmark could not show.
With 1,000 dynamic routes, switching from linear to tree-based matching increased HTTP throughput from 18,685 to 67,120 requests per second when requesting the last registered route. For a request matching none of those dynamic routes, throughput rose from 20,223 to 71,782 requests per second. Both fixtures also included a wildcard fallback.
But the tree did not win everywhere. With ten dynamic routes, requesting the last one was 8.2% slower with tree-based matching. We saw that slowdown in all three runs.
That result matters too. Testing only one route would have hidden the large-table gains. Testing only large tables would have hidden the small-table regression.
I'll explain the router changes in the next section. What matters here is why we needed these scenarios in the first place.
Routing with 1,000 routes
One benchmark registers 1,000 routes and sends requests to the last one.
That is a deliberately unfavorable case for our previous route matcher. It stored routes in a linear list, and each request walked that list until it found a match. The further down a route was registered, the more work it took to reach it.
We replaced that lookup with a route table from the new @boringnode/route-matcher package. It uses a map for static routes and a segment tree for dynamic routes.
Route precedence stays the same. The index skips routes that cannot match. It does not change which matching route wins.
In the isolated benchmark, matching the last of 1,000 dynamic routes is 18x faster, and checking a path that matches none of them is almost 23x faster. Over HTTP, the same last-route scenario goes from 18,685 to 67,120 requests per second, about 3.6x more.
Those are results for this particular scenario, not a promise that every application will see the same gain. But they remove a cost that grew with the number of routes in your application.
We checked the new matcher against the old one with millions of differential comparisons, running the same inputs through both implementations and comparing the results. Still, routing compatibility matters, so existing applications opt in through config/app.ts.
export const http = defineConfig({
router: {
matcher: 'tree',
},
})
The official starter kits now enable it by default. It will become the default in the next major release.
Fuzzing also caught a regular expression denial-of-service issue, or ReDoS, in the built-in slug matcher. A long, invalid slug could trigger excessive backtracking in its regular expression. We rewrote the expression and backported the fix.
Paying for tracing when nobody is listening
AdonisJS provides an optional telemetry provider based on OpenTelemetry. It helps you trace requests and see where your application spends its time. Under the hood, the framework uses Node.js diagnostics_channel.
During benchmarking, we noticed a performance hit of roughly 20% even with no subscribers listening to those channels.
That was surprising. With nobody listening, we expected tracing to add very little overhead.
The cause turned out to be in Node.js. Both traceSync() and tracePromise() created their context through a default parameter. JavaScript evaluates default parameters before entering the function body, so every call allocated a context object before the code could check whether anyone was subscribed.
The fix was to create the context only when needed. In benchmarks without subscribers, that makes traceSync() 60% faster and tracePromise() 42% faster.
The fix has landed and is available in Node.js releases ( nodejs/node#65513 ).
While working in Node.js, we found another avoidable allocation in the URLSearchParams constructor when given a plain object. It always created a map to detect key collisions, even though the keys of a plain object are already unique. The collision check is only needed when converting a key can change it.
The constructor now creates the map only when needed. In that benchmark, construction is about 10% faster, with 31% fewer allocations. That change has also been released ( nodejs/node#65801 ).
Faster JSON responses, with a V8 detour
Every JSON response sent by the AdonisJS HTTP server goes through safeStringify from @poppinss/utils.
Previously, it always used safe-stable-stringify to handle values such as circular references and bigints. Ordinary JSON data went through the more expensive serialization path too.
We changed it to try native JSON.stringify first, and fall back to safe-stable-stringify if it throws a TypeError.
For plain data, serialization is now 4x to 6x faster. In an HTTP benchmark returning a small list of objects, that translates to 55% more requests per second.
There is a catch. During testing, we found that on Node.js 25 and later, the V8 fast path for JSON.stringify takes several milliseconds to reject a circular plain object. On Node.js 24, the same rejection takes only a few microseconds.
On the affected versions, values with circular references are now slower than before, because we pay that cost before reaching the fallback. We reported the issue upstream ( Chromium issue 572287937 ).
Work we only needed to do once
Several improvements came from asking the same question. Why are we doing this on every request?
A full-stack request can pass through routing, sessions, Shield, Inertia, Edge, and Vite helpers. Re-reading configuration or rebuilding a small object may not look expensive in isolation. Repeating it across those layers adds up.
Shield
Shield registered its middleware with container.bind, so the container created a new instance on every request.
Each instance read the configuration, resolved the encryption service, dynamically imported Edge, and rebuilt the guards. Those guards do not hold per-request state, so there was no need to repeat that setup.
The middleware is now a singleton. In a benchmark using sessions and Shield, CPU time per request drops by 22%, and throughput increases by 26%.
Edge
AdonisJS creates an Edge renderer for each request. That should be cheap.
But a bug in how configure() handled the cache flag caused the components plugin to run on every createRenderer() call, even in production. Each call scanned the components directory of every mounted disk.
After the fix, creating a renderer takes constant time regardless of the number of components. In the hypermedia application we tested, which had 26 components, CPU time per request dropped by 32%.
Inertia
Inertia cached the assets version on its instance. The problem was that each request got a new instance, so the cache never survived long enough to help the next request.
Outside the Vite dev server, every render hashed the whole manifest again.
Inertia now computes the version once per process. Depending on the manifest size, this makes page() 4x to 9x faster.
Vite
Resolving CSS chunk integrity also involved repeated work. For each stylesheet, the helper scanned every entry in the manifest.
We now index the manifest by file when it is first read, so later lookups use that index directly.
Parsing request bodies
The bodyparser can normalize strings in JSON bodies by trimming whitespace and converting empty strings to null.
Previously, it did this through a JSON.parse reviver, a callback invoked as part of parsing. That is convenient, but much slower than parsing the JSON first and then walking the result.
Normalization now happens in a separate iterative traversal. In our benchmarks, parsing with normalization enabled is about 3x faster for both small and large payloads.
Because the traversal is iterative, deeply nested payloads no longer exhaust the JavaScript call stack during normalization.
We added an optional JSON nesting depth limit, json.maxDepth, along with a reproducible JSON benchmark in the bodyparser repository.
Validation with VineJS
VineJS already compiles schemas into functions to keep validation fast. Profiling still found some work we could avoid.
The alpha and alphaNumeric rules rebuilt their regular expressions on every validation. They now build them once, which makes validation of valid values about 2x faster for those rules.
ValidationError also captured its stack trace twice. Stack traces are expensive, and invalid input is a normal part of handling requests. Removing the duplicate capture makes invalid validations 21% to 24% faster on the modern Node.js versions we tested.
The distinct array rule created an intermediate array for every item, including when checking uniqueness on just one field. That common case now has a dedicated path, which is 11% faster with 27% fewer allocations.
We also added synchronous compilation to the VineJS compiler. When a schema has no asynchronous rules, the compiler can now turn it into a plain function without the promise overhead.
Skipping unnecessary filesystem checks
When enabled, the static middleware runs before your routes. Previously, even requests that did not target a static file still led to a filesystem check.
There is now a prefixes option for applications that serve static files under known URL prefixes. If the request path does not match any of them, the middleware moves on without asking the filesystem.
The option is explicit. If you do not configure it, the existing behavior stays the same.
Making development faster too
Production throughput is only part of the work. You also wait for the framework when you save a controller, start the dev server, or run an Ace command.
We spent time on those paths too, particularly in the assembler, which handles the dev server, hot module replacement, and type generation.
Parsing controllers once per save
When a controller changes in HMR mode, the route scanner re-analyzes its routes.
It used to create a fresh virtual file system for each route. A controller used by several routes could therefore be read and parsed several times after a single save.
It is now parsed once. For a controller with several routes, that step is up to 3.3x faster.
Scanning routes and generating indexes
To find validator calls in controllers, the scanner used to build six abstract syntax tree patterns for every method it inspected. It now walks the call expressions once, which makes a full route scan 16% to 21% faster.
We also found that naturalSort from @poppinss/utils created a new Intl.Collator on every comparison. Sorting a list can involve a lot of comparisons, so that setup cost quickly added up.
Reusing one collator makes index generation up to 3.6x faster on large projects. Other parts of AdonisJS that use naturalSort get the same benefit.
Loading less code for Ace commands
A lightweight command should not have to load the whole framework.
@adonisjs/core now exposes more focused entrypoints, including @adonisjs/core/ignitor and @adonisjs/core/generators. The starter kits use them now.
With those changes, ace --help starts 20% faster, loads roughly a third as many modules, and uses 10 MiB less memory.
We also fixed several development workflow issues along the way.
- The dev server now waits for index regeneration before restarting, and restarts when environment files change.
- The bundler reads
tsconfig.jsonthroughget-tsconfig, replacing a TypeScript API scheduled for removal in TypeScript 7. - Transmit no longer starts its ping interval when the application boots in warmup mode.
Where we go from here
A lot of this work came down to things that were easy to miss. A cache that lasted only one request. A directory scan that should not have happened in production. An object created before checking whether it was needed.
Those are the kinds of problems I wanted the benchmark suite to help us find. Router benchmarks remain useful, but we also need to measure what happens when the rest of the framework is involved.
The results above cover different workloads and different parts of the stack. They do not add up to a single percentage improvement for every AdonisJS application. Which changes matter most will depend on what your application does.
Two fixes also made it into Node.js itself, where they help applications beyond AdonisJS. And the V8 issue is a reminder that an optimization can improve the common case while exposing a problem elsewhere.
We will keep adding scenarios, profiling them, and fixing what we find. There is still work to do, and we now have a better way to see where it is.
- What a Hello World hides
- Routing with 1,000 routes
- Paying for tracing when nobody is listening
- Faster JSON responses, with a V8 detour
- Work we only needed to do once
- Parsing request bodies
- Validation with VineJS
- Skipping unnecessary filesystem checks
- Making development faster too
- Where we go from here