Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(router): sort handlers by score only when necessary #3697

Merged
merged 3 commits into from
Nov 23, 2024

Conversation

EdamAme-x
Copy link
Contributor

@EdamAme-x EdamAme-x commented Nov 21, 2024

Sorting was also done when number of handlers was 0 or 1, so it is no longer done.
Also, there is no need to create a new variable.

Benchmarks

In Node

summary for all together
  Hono RegExpRouter
   1.39x faster than Memoirist
   1.5x faster than koa-tree-router
   1.66x faster than @medley/router
   2.15x faster than rou3
   2.33x faster than trek-router
   2.97x faster than find-my-way
   4.28x faster than Hono PatternRouter
   5.43x faster than radix3
   8.01x faster than koa-router
   8.96x faster than Hono TrieRouter
   9.13x faster than Hono BeforeTrieRouter
   39.24x faster than express (WARNING: includes handling)

In Bun

summary for all together
  Hono RegExpRouter
   1.01x faster than Memoirist
   1.23x faster than @medley/router
   2.12x faster than koa-tree-router
   2.13x faster than rou3
   2.19x faster than radix3
   2.33x faster than find-my-way
   3.87x faster than trek-router
   4.06x faster than Hono PatternRouter
   5.43x faster than koa-router
   10.29x faster than Hono TrieRouter
   10.45x faster than Hono BeforeTrieRouter
   11.37x faster than express (WARNING: includes handling)

There is some improvement in performance, though not significantly.

The author should do the following, if applicable

  • Add tests
  • Run tests
  • bun run format:fix && bun run lint:fix to format the code
  • Add TSDoc/JSDoc to document the code

Copy link

codecov bot commented Nov 21, 2024

Codecov Report

Attention: Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.

Project coverage is 91.69%. Comparing base (44a50bd) to head (8abc420).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/router/trie-router/node.ts 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3697      +/-   ##
==========================================
- Coverage   91.70%   91.69%   -0.01%     
==========================================
  Files         159      159              
  Lines       10145    10148       +3     
  Branches     2879     2873       -6     
==========================================
+ Hits         9303     9305       +2     
- Misses        840      841       +1     
  Partials        2        2              

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


🚨 Try these New Features:

Copy link
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
Member

@EdamAme-x

Thanks! I'll merge it.

@yusukebe yusukebe merged commit 3059741 into honojs:main Nov 23, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants