Skip to content

perf(trie-router): improve performance (1.5x ~ 2.0x)#4724

Merged
yusukebe merged 4 commits intohonojs:nextfrom
EdamAme-x:perf/trie-router
Feb 19, 2026
Merged

perf(trie-router): improve performance (1.5x ~ 2.0x)#4724
yusukebe merged 4 commits intohonojs:nextfrom
EdamAme-x:perf/trie-router

Conversation

@EdamAme-x
Copy link
Copy Markdown
Contributor

How to improve

  1. Removed spread syntax to improve expansion time.
  2. Reduced time complexity of hasChildren from $O(N)$ to $O(1)$ to resolve a performance bottleneck.
  3. Implemented lazy evaluation to prevent unnecessary regular expression generation.
  4. Removed redundant processes to streamline execution.

Benchmark Results

imporved vs hono@latest in same process

Route Node.js 23.11 Deno 2.6.8 Bun 1.3.9
short static GET /user 1.70x 1.40x 1.34x
static with same radix GET /user/comments 1.34x 1.58x 1.36x
dynamic GET /user/lookup/username/hey 1.38x 1.69x 1.51x
mixed static dynamic GET /event/abcd1234/comments 1.65x 1.95x 1.48x
post POST /event/abcd1234/comment 1.64x 1.85x 1.65x
long static GET /very/deeply/nested/route/hello/there 1.77x 2.08x 1.14x
wildcard GET /static/index.html 1.51x 1.72x 1.43x
all together 1.58x 1.60x 1.82x

The author should do the following, if applicable

  • Run tests
  • bun run format:fix && bun run lint:fix to format the code

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 17, 2026

Codecov Report

❌ Patch coverage is 94.59459% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.43%. Comparing base (8b17935) to head (337d0fc).
⚠️ Report is 15 commits behind head on next.

Files with missing lines Patch % Lines
src/router/trie-router/node.ts 94.59% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             next    #4724      +/-   ##
==========================================
- Coverage   91.43%   91.43%   -0.01%     
==========================================
  Files         173      173              
  Lines       11382    11402      +20     
  Branches     3300     3307       +7     
==========================================
+ Hits        10407    10425      +18     
- Misses        974      976       +2     
  Partials        1        1              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Covers the constructor branch where method and handler are provided,
improving patch coverage to 100% line/statement.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@EdamAme-x
Copy link
Copy Markdown
Contributor Author

EdamAme-x commented Feb 17, 2026

@yusukebe Can you review this?
The bundle size change is approximately 0.1% of the total, which is negligible.

Copy link
Copy Markdown
Member

@yusukebe yusukebe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@yusukebe
Copy link
Copy Markdown
Member

Hey @EdamAme-x

This is awesome. You are great since you make my first router (TrieRouter) fast! The file size increases by 73 bytes with the Hello World application after minify.

CleanShot 2026-02-18 at 20 01 08@2x

But I think this is acceptable. Let's go with this!

I'll include this in the next minor release v4.12.0. Please wait a bit!

@EdamAme-x
Copy link
Copy Markdown
Contributor Author

Okay!

@yusukebe yusukebe changed the base branch from main to next February 19, 2026 10:16
@yusukebe yusukebe merged commit bd26c31 into honojs:next Feb 19, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants