Open a fresh web server benchmark table, and your eyes jump straight to the big numbers. One runtime easily clears 100,000 requests per second while another trails behind. The choice seems obvious. Then you add one tiny thing to that handler: read the tail of the URL and a single HTTP header. The response stays identical, with no database or business logic inside. Suddenly, the leader loses nearly a sixth of its throughput out of nowhere.
That observation kicked off a major performance cleanup in AdonisJS. Romain Lanz from the core team built a private suite of realistic benchmarks. Instead of an empty stub, it runs real-world scenarios: middleware chains, a thousand dynamic routes, sessions, validation, template rendering, JSON parsing, and telemetry. To find bottlenecks and verify that optimizations didn't break existing behavior, the team used AI tools and fuzzing. In the end, the framework got faster, a ReDoS vulnerability was found in a regex, two patches landed directly in Node.js core, and an unpleasant regression surfaced in the V8 engine.
Making AdonisJS faster — official banner of the AdonisJS blog post (Source: adonisjs.com)
Why 'Hello World' benchmarks hide real bottlenecks
A typical JavaScript backend benchmark is painfully simple: one route, an empty handler, and a static string or tiny JSON response. Comparing two columns of numbers is easy, but it tells you very little. A real app always runs sessions, security checks, input validation, template rendering, and logging on top of the raw HTTP server. Different frameworks also do different amounts of work out of the box, so a raw requests-per-second number never shows what the CPU actually spent time on.
The first eye-opening test compared the HTTP servers of Node.js 26.12.0 and Bun 1.4.3. First, the handler simply returned a fixed response. Then it returned the same response after reading the URL suffix and one request header. Both cases used the median across three runs.
Node.js 26.12.0 vs. Bun 1.4.3 when reading a request
The picture changes immediately. Bun stays faster in both scenarios, but as soon as the handler actually inspects the request, its lead shrinks noticeably. That drop reproduced across all three runs. On Node.js, the variance between runs was wider than the difference itself, so there was no clear drop there. Of course, this is an end-to-end measurement of the whole handler, not the exact cost of reading a single field, since Node.js and Bun represent URLs differently internally. Still, the practical takeaway is clear: a fixed-response test poorly predicts how a server behaves in a real app.
The second surprise appeared inside AdonisJS itself when a middleware chain was attached to the handler. As soon as several intermediate layers were added, throughput dropped sharply. A bare handler without middleware didn't show this drop at all.
The culprit was Fold, the built-in AdonisJS DI container (a dependency injection system that creates and wires up controllers, services, and middleware). To test the fixes fairly, the team took two builds of Fold (before and after optimization) and ran them on the exact same app with no other changes.
| Middleware chain scenario | Before, req/s | After, req/s | Gain |
|---|---|---|---|
| 10 pass-through middleware | 34,126 | 52,661 | +54.3% |
| 10 middleware reading a header and mutating state | 33,060 | 50,165 | +51.7% |
| 4 global + 1 named + lazy controller | 43,474 | 61,644 | +41.8% |
The gain repeated consistently across all three runs and easily beat normal measurement noise. Meanwhile, in a control test that used plain closures instead of container-managed classes, there was no consistent speedup. That proved the container optimization itself worked, rather than warmup luck. One fair caveat: these numbers apply to specific middleware chains and don't promise that every AdonisJS app will suddenly run 1.5x faster.
A thousand routes, a segment tree, and ReDoS in the slug regex
"Hello World" benchmarks almost always register a single route. They never test how a server behaves when a project has hundreds of routes or receives a request for a non-existent URL.
Previously, the AdonisJS router stored routes in a plain linear list. On every incoming request, it walked the array from top to bottom until it found a match. The lower a route sat in the table, the more wasted work the server did. For a stress test, the team loaded 1,000 dynamic routes plus a fallback wildcard handler and hit both the very last route and paths that matched nothing.
Linear scanning was replaced by a new package, @boringnode/route-matcher (current version 0.1.2). Internally, it splits the work into two layers: static paths live in a standard Map for instant lookup, while dynamic routes are indexed in a segment tree (a prefix tree over URL path segments). This tree immediately prunes branches that cannot match, while strictly preserving the old priority order so the exact same route wins as before.
In an isolated microbenchmark, finding the last of 1,000 dynamic routes got 18x faster, and checking a non-matching path got nearly 23x faster. The gap is also huge across the full HTTP stack.
HTTP throughput on a 1,000 dynamic routes table
On a large table, the tree pulls ahead by multiples for both the last route and misses. Here's the catch: the tree doesn't win everywhere. When the table has only 10 dynamic routes, hitting the last one with the new matcher was 8.2% slower, and that drop also repeated across all three runs. On a short list, the tree's overhead outweighs a simple linear scan. Had the team measured only one route, they would have missed the gain at a thousand. Had they measured only a thousand, they would have missed the dip at ten.
To make sure the new router never diverges from the old one, they ran differential testing—passing millions of identical paths through both implementations and comparing every result. Still, they chose not to break compatibility in existing projects. Starting with @adonisjs/http-server@9.3.1 (current release is 9.4.0, and @adonisjs/core updated to 7.7.1), the new engine is enabled manually in config/app.ts.
// config/app.ts — enable the tree router manually
// Works starting with @adonisjs/http-server@9.3.1
import { defineConfig } from '@adonisjs/core/http'
export const http = defineConfig({
router: {
// Existing projects keep linear matching by default
matcher: 'tree',
},
})
Official AdonisJS starter kits already enable this setting out of the box, and it will become the default in the next major release. If your service has dozens or hundreds of dynamic endpoints, switching gives you room to grow without rewriting routes.
Along the way, fuzzing (feeding millions of random and malformed strings) turned up an unexpected security catch. The built-in slug parameter matcher had a ReDoS (Regular Expression Denial of Service) vulnerability. A carefully crafted string could force the regex engine into exponential backtracking and freeze the event loop. A single long invalid slug could stall a core worker. The regex was rewritten, and the fix was backported to supported branches.
Two patches to Node.js core: tracing into the void and an extra Map in URLSearchParams
Next, the hunt for bottlenecks moved outside the framework itself. AdonisJS includes an optional OpenTelemetry provider to inspect where request time goes. Under the hood, it relies on diagnostics_channel, Node.js's built-in tracing event bus.
You'd expect that when nothing is subscribed to those channels, the wrapper costs almost nothing. Measurements showed the opposite: even with zero subscribers, server throughput dropped by roughly 20%. A fifth of the server's capacity was disappearing into thin air.
Digging deeper revealed the cause inside Node.js itself. The traceSync() and tracePromise() methods created a context object using a default parameter value. In JavaScript, default parameters are evaluated before entering the function body. As a result, the runtime allocated a brand-new context object on every call, only to check one line later whether anyone was actually listening to the channel.
// Before: the context object was created on every call,
// even before checking if the channel had subscribers
function traceSync(fn, context = {}, thisArg, ...args) {
if (!this.hasSubscribers) {
return Reflect.apply(fn, thisArg, args)
}
// Publish events to the channel
}
// After: fast exit with zero extra allocations,
// context object is created only when listeners exist
function traceSync(fn, context, thisArg, ...args) {
if (!this.hasSubscribers) {
return Reflect.apply(fn, thisArg, args)
}
context ??= {}
// Publish events to the channel
}
The idea fits in a couple of lines, yet the impact is huge. In microbenchmarks with no subscribers, traceSync() sped up by 60% and tracePromise() by 42%. The AdonisJS team submitted pull request nodejs/node#65513, and the fix is already included in Node.js v26.9.0.
While digging through the runtime source, they spotted another unnecessary allocation in the URLSearchParams constructor. When passed a plain JavaScript object, the constructor always created an internal Map to check for key collisions. Yet keys on a plain object are unique by definition, and collisions only happen in the rare case where converting a key to a string changes it. Lazily creating that Map sped up the constructor by about 10% and cut allocations by 31%. Patch nodejs/node#65801 was also accepted—it shipped in Node.js v26.11.0 and now speeds up any app on recent Node.js, regardless of framework.
Fast JSON responses and an unexpected V8 trap
Every JSON response in the AdonisJS HTTP server goes through the safeStringify helper from @poppinss/utils. Previously, it always called the safe-stable-stringify library so the server wouldn't crash on circular references or BigInt values. Safe, yes, but expensive: 99% of real API responses are plain flat or nested objects without cycles, so paying for that safety net on every request hurts.
The solution was obvious: try the fast native JSON.stringify first (which is heavily optimized in V8), and fall back to safe-stable-stringify only in a catch block if a TypeError is thrown.
// Simplified fast path in safeStringify
import safeStableStringify from 'safe-stable-stringify'
export function safeStringify(value: unknown): string {
try {
// Fast path for normal objects without cycles or BigInt
return JSON.stringify(value)
} catch (error) {
// Fall back to safe serialization on TypeError
if (error instanceof TypeError) {
return safeStableStringify(value)
}
throw error
}
}
On normal data, serialization immediately became 4–6x faster, and an end-to-end HTTP benchmark returning a small list of objects gained 55% more requests per second. It looked like a clean win—until an unpleasant catch showed up right inside the V8 engine.
Starting in Node.js 25, V8's fast path for JSON.stringify takes several milliseconds to detect and reject a plain object with a circular reference, whereas Node.js 24 took microseconds for the same error. Because of this, serializing circular objects through the new safeStringify on recent Node.js versions temporarily became slower than before the optimization. The team filed a Chromium bug (572287937), so until a fix lands in V8, accidentally leaking circular references into HTTP responses on Node 25+ is especially costly.
This story shows why you can't test optimizations only on the happy path. Normal responses got multiples faster, while an edge case unexpectedly hit the JavaScript engine's own behavior.
Work silently repeated on every request: Shield, Edge, Inertia, and Vite
Once the core HTTP layer was clean, the profiler began highlighting a classic big-framework problem: heavy work accidentally redone on every incoming request instead of once at startup.
Shield—the package for CSRF, XSS, and security headers—was first. Its middleware was registered with container.bind, meaning the DI container built a new instance on every HTTP request: reading config, resolving the encryption service, dynamically importing the Edge template engine, and rebuilding all guard checks. Simply switching this middleware to a singleton cut CPU load by 22% per request and boosted throughput by 26% when combined with sessions.
Isometric diagram of AdonisJS DI container optimization moving from per-request rebuilding of services to a persistent in-memory node
Next came the Edge template engine. A single bug with a caching flag in configure() caused the component plugin to rescan component directories across all mounted disks on every createRenderer() call—right in production, on every request. Fixing the flag made lookups constant-time and cut CPU usage by 32% in a test app with 26 components.
An equally funny bug turned up in the Inertia adapter. Client asset versions were supposedly cached, but on an instance that was recreated on every HTTP request. Outside Vite's dev server, the app faithfully re-hashed the manifest file on every page render. Moving the cache to the process level sped up page() calls by 4–9x.
Finally, in the Vite integration, looking up integrity hashes for CSS chunks linearly scanned the entire manifest for every stylesheet. Now the manifest is indexed once by filename on first read, so repeated lookups no longer slow down large frontend builds.
JSON parsing, VineJS validation, and faster dev mode
They also tackled incoming data parsing. In Bodyparser, normalizing strings inside JSON (trimming whitespace and turning empty strings into null) used to run through a reviver function in JSON.parse. In V8, passing a reviver disables the parser's fast path. Switching to a separate iterative pass over the parsed object sped up processing by about 3x for both small and large request bodies. As a bonus, it removed stack overflow risks on deeply nested JSON and added an explicit json.maxDepth option to limit nesting depth.
The VineJS validation package got four targeted speedups. Regular expressions in the alpha and alphaNumeric rules are now cached, doubling validation speed for valid strings. Removing a double stack-trace capture in ValidationError sped up invalid input handling by 21–24%. The distinct rule gained a dedicated fast path for single-field checks without creating intermediate arrays, yielding 11% more speed and 27% fewer allocations. Finally, schemas without async rules now compile synchronously without wrapping every check in extra Promise objects.
In Static middleware, they added an explicit prefixes option. If an incoming URL doesn't start with an allowed static prefix, the server skips this layer immediately without touching the filesystem. It's a small change, but it eliminates unnecessary disk checks on API requests.
The final batch of fixes targets everyday developer life: Assembler, HMR, and the Ace CLI. In hot reload mode, a controller serving multiple routes is now parsed once per file save instead of rebuilding the virtual filesystem for each route individually, giving up to a 3.3x speedup on large controllers. The route scanner now walks calls in a single AST pass instead of building six separate patterns per method, adding 16–21% more speed.
A particularly nice fix landed in naturalSort inside @poppinss/utils: previously, the sorter created a new Intl.Collator object for every pair of strings compared, and now it reuses one instance. Index generation in large projects sped up by up to 3.6x. Finally, @adonisjs/core split out narrow entry points @adonisjs/core/ignitor and @adonisjs/core/generators, making ace --help start 20% faster, load roughly three times fewer modules, and use 10 MiB less RAM. On top of that, the bundler switched to get-tsconfig (replacing an API being removed in TypeScript 7), the dev server now waits for index rebuilds before restarting, and Transmit's extra ping interval was disabled during warmup.

