question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is not Hono fastest...?

See original GitHub issue

Shame 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:closed
  • Created a year ago
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
usualomacommented, Jun 1, 2022

@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.

0reactions
yusukebecommented, Jun 2, 2022

Hono is the fastest! Close the issue!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Isaiah 58:3-7 ERV - Bible.com
They say, “We fast to show honor to you. Why don't you see us? ... This is not the way to fast if...
Read more >
Best way to farm honor in WoW Shadowlands ... - YouTube
Using this trick you should be able to comfortably achieve 7000 honor per (somewhat dependent on gear) , this week only this is...
Read more >
Who is the fastest character in For Honor? : r/forhonor - Reddit
I'm not sure but I think gladiator is the fastest since he is an assassin and has "Roar of the crowd" that makes...
Read more >
honojs/hono: Ultrafast web framework for Cloudflare Workers ...
Hono is fastest, compared to other routers for Cloudflare Workers. Hono x 616,464 ops/sec ±4.76% (83 runs sampled) itty-router x 203,074 ops/sec ±3.66%...
Read more >
Hono - Ultrafast web framework for Cloudflare Workers, Deno ...
Hono - [炎] means flame in Japanese - is a small, simple, and ultrafast web framework for Cloudflare Workers, Deno, Bun,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found