Is not Hono fastest...?
See original GitHub issueShame on me, the benchmark scores may not be correct.
First, I say Hono is the fastest compared to other routers. The score of the benchmark is below:
hono - trie-router(default) x 724,143 ops/sec ±3.63% (80 runs sampled)
hono - regexp-router x 1,236,810 ops/sec ±6.77% (72 runs sampled)
itty-router x 161,786 ops/sec ±2.28% (97 runs sampled)
sunder x 312,262 ops/sec ±2.59% (85 runs sampled)
worktop x 224,979 ops/sec ±1.13% (96 runs sampled)
Fastest is hono - regexp-router
✨ Done in 95.05s.
But, isn’t it too fast? I wrote the minimal handler to compare it. It should be the fastest.
const minimalHandler = async () => {
return new Response('foo')
}
The score is below:
minimal handler x 392,854 ops/sec ±3.23% (90 runs sampled)
hono - trie-router(default) x 720,882 ops/sec ±3.23% (84 runs sampled)
hono - regexp-router x 1,195,783 ops/sec ±6.53% (70 runs sampled)
itty-router x 160,515 ops/sec ±2.68% (91 runs sampled)
sunder x 303,981 ops/sec ±3.09% (86 runs sampled)
worktop x 211,622 ops/sec ±3.71% (83 runs sampled)
Fastest is hono - regexp-router
✨ Done in 101.34s.
In this benchmark, the score of minimal handler is not the fastest, and hono - regexp-router
is still the fastest. Why??
As an experiment, I remove async/await
for matchRoute
in hono.ts
.
diff --git a/src/hono.ts b/src/hono.ts
index f3bc3d8..41a0ba7 100644
--- a/src/hono.ts
+++ b/src/hono.ts
@@ -173,10 +173,7 @@ export class Hono<E = Env, P extends string = '/'> extends defineDynamicClass()<
this.routes.push(r)
}
- private async matchRoute(
- method: string,
- path: string
- ): Promise<Result<Handler<string, E>> | null> {
+ private matchRoute(method: string, path: string): Result<Handler<string, E>> | null {
return this.router.match(method, path)
}
@@ -184,7 +181,7 @@ export class Hono<E = Env, P extends string = '/'> extends defineDynamicClass()<
const path = getPathFromURL(request.url, { strict: this.strict })
const method = request.method
- const result = await this.matchRoute(method, path)
+ const result = this.matchRoute(method, path)
request.param = ((key?: string): string | Record<string, string> | null => {
if (result) {
And, run the benchmark again, the score is below:
minimal handler x 399,400 ops/sec ±2.98% (90 runs sampled)
hono - trie-router(default) x 215,606 ops/sec ±3.56% (85 runs sampled)
hono - regexp-router x 257,114 ops/sec ±2.81% (85 runs sampled)
itty-router x 157,411 ops/sec ±3.81% (87 runs sampled)
sunder x 327,332 ops/sec ±1.24% (97 runs sampled)
worktop x 220,831 ops/sec ±1.92% (92 runs sampled)
Fastest is minimal handler
✨ Done in 47.57s.
minimal handler has been the fastest. It seems to be correct. But, unfortunately, hono regexp-router loses to Sunder. For sure, our Hono’s routers are smart, but the functions of compose
and context
are a little bit complex.
Does anyone know this benchmark is correct or not? If Hono is not fastest, I believe we have chance to make it fast by refactoring, and we have some functional advantage to other routers.
Issue Analytics
- State:
- Created a year ago
- Comments:13 (8 by maintainers)
Top GitHub Comments
@yusukebe
I determined that 2e2d443 and ca92ca9 are unnecessary because their performance improvement effects are negligible relative to the increase in complexity.
If #292, or even #293, were included, the performance would be adequate for the current situation.
Hono is the fastest! Close the issue!