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(trie-router): avoid calling spread operator for Object.create(null) #3735

Merged
merged 3 commits into from
Dec 9, 2024

Conversation

usualoma
Copy link
Member

@usualoma usualoma commented Dec 8, 2024

This optimization is based on the discussion in the following Pull Request.
Thanks to @EdamAme-x!
#3732

benchmarks

via benchmarks/routers

node

• all together
----------------------------------------------------------------------- -----------------------------
Hono RegExpRouter                   513 ns/iter       (490 ns … 715 ns)    524 ns    595 ns    715 ns
Hono TrieRouter(perf-trie-1208)   1'716 ns/iter   (1'652 ns … 1'895 ns)  1'723 ns  1'892 ns  1'895 ns
Hono TrieRouter(main)             2'203 ns/iter   (2'097 ns … 2'730 ns)  2'213 ns  2'709 ns  2'730 ns

summary for all together
  Hono RegExpRouter
   3.35x faster than Hono TrieRouter(perf-trie-1208)
   4.3x faster than Hono TrieRouter(main)

bun

• all together
----------------------------------------------------------------------- -----------------------------
Hono RegExpRouter                   393 ns/iter       (360 ns … 722 ns)    390 ns    594 ns    722 ns
Hono TrieRouter(perf-trie-1208)   3'191 ns/iter   (2'032 ns … 3'602 ns)  3'351 ns  3'595 ns  3'602 ns
Hono TrieRouter(main)             3'971 ns/iter   (3'732 ns … 4'293 ns)  4'065 ns  4'267 ns  4'293 ns

summary for all together
  Hono RegExpRouter
   8.12x faster than Hono TrieRouter(perf-trie-1208)
   10.1x faster than Hono TrieRouter(main)

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

usualoma and others added 2 commits December 8, 2024 17:27
…ull)`

This optimization is based on the discussion in the following Pull Request.
Thanks to @EdamAme-x!
honojs#3732

Co-authored-by: EdamAmex <[email protected]>
Copy link

codecov bot commented Dec 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.73%. Comparing base (50ff212) to head (eac0056).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3735      +/-   ##
==========================================
+ Coverage   91.72%   91.73%   +0.01%     
==========================================
  Files         159      159              
  Lines       10184    10176       -8     
  Branches     2990     2873     -117     
==========================================
- Hits         9341     9335       -6     
+ Misses        842      840       -2     
  Partials        1        1              

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

@usualoma
Copy link
Member Author

usualoma commented Dec 8, 2024

There was a slight performance drop due to the eac0056 bug fix commit, but I still think it's the fastest.

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

yusukebe commented Dec 9, 2024

I also like the not-magical way. This is simple and good!

Thanks, @usualoma @EdamAme-x !

@yusukebe yusukebe merged commit 47bb23c into honojs:main Dec 9, 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