-
-
Notifications
You must be signed in to change notification settings - Fork 624
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): optimize and remove unnecessary processes #3647
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3647 +/- ##
==========================================
+ Coverage 91.68% 91.69% +0.01%
==========================================
Files 159 159
Lines 10135 10138 +3
Branches 2878 2880 +2
==========================================
+ Hits 9292 9296 +4
+ Misses 841 840 -1
Partials 2 2 ☔ View full report in Codecov by Sentry. |
Hi @EdamAme-x ! It looks awesome! I'd like to know how much this change affects performance. Did you benchmark it? And how much did you reduce the bundle size? PS. To benchmark the req/res performance, you can follow the method used in this repo: https://github.com/SaltyAom/bun-http-framework-benchmarkhttps://github.com/SaltyAom/bun-http-framework-benchmark |
ReportRevert (4): The bundle size is smaller, but we got strange benchmark results that one index access is slower than multiple index accesses, so I reverted. runtime: deno 2.0.5 (x86_64-pc-windows-msvc)
benchmark avg (min … max) p75 p99 (min … top 1%)
-------------------------------------- -------------------------------
Once 193.31 ps/iter 195.31 ps ▇ █
(170.90 ps … 70.87 ns) 341.80 ps █▁▁█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁
Multi 136.00 ps/iter 146.48 ps █
(97.66 ps … 22.39 ns) 219.73 ps ▁▁▁▁█▁▁▁▄▁▁▁▂▁▁▁▂▁▁▁▁ Bundle Size19.34kb => 19.28kb (1kb = 1024b) gitpod@honojs-hono-0oouxesc90f:/workspace/hono/sandbox$ ls compare -l
total 40
-rw-r--r-- 1 gitpod gitpod 19288 Nov 9 07:09 after.js
-rw-r--r-- 1 gitpod gitpod 19344 Nov 9 07:11 before.js BenchmarkIn DenoThere was not much change. | Framework | Runtime | Average | Ping | Query | Body |
| ---------------- | ------- | ------- | ---------- | ---------- | ---------- |
| after | deno | 41,225.407 | 50,386.78 | 38,903.5 | 34,385.94 |
| before | deno | 41,079.073 | 50,923.38 | 39,116.56 | 33,197.28 | |
Have you ever tried to benchmark frameworks on Bun, not only Deno? |
I'll benchmark with several approaches. |
I measured the performance of router itself using node, bun, and mitata, but did not see any significant performance improvement that we could see. In Deno sample clk: ~3.03 GHz
cpu: AMD EPYC 7B13
runtime: deno 2.0.5 (x86_64-unknown-linux-gnu)
benchmark avg (min … max) p75 p99 (min … top 1%)
-------------------------------------- -------------------------------
Before Trie 3.55 µs/iter 3.57 µs ▅ █▅██ ▅
(3.47 µs … 3.70 µs) 3.68 µs ▄▇█▄████▄▄▄█▁▄▇▁▁▁▄▁▁
After Trie 3.51 µs/iter 3.52 µs ▄▆▂█▂▄
(3.45 µs … 3.71 µs) 3.67 µs ▇▅██████▃▃▁▁▁▃▁▁▁▁▁▁▁ |
Thanks. Anyway, this is a good improvement. I'll merge this now. |
https://github.com/honojs/hono/pull/3647/files#diff-bf1549ba9405f87c376d2d338883f54bfeb6a91f40b28e62dd2ce5e9d4edd4e5L66-L69
Related: #3596
https://github.com/honojs/hono/pull/3647/files#diff-bf1549ba9405f87c376d2d338883f54bfeb6a91f40b28e62dd2ce5e9d4edd4e5L85
Object.create(null)
. It is faster and smaller.Node and Bun (8x~ faster)
In Bun, the speed of both is almost the same.
https://github.com/honojs/hono/pull/3647/files#diff-bf1549ba9405f87c376d2d338883f54bfeb6a91f40b28e62dd2ce5e9d4edd4e5L95
4. Multiple index accesses are eliminated and the size is reduced.https://github.com/honojs/hono/pull/3647/files#diff-bf1549ba9405f87c376d2d338883f54bfeb6a91f40b28e62dd2ce5e9d4edd4e5R130https://github.com/honojs/hono/pull/3647/files#diff-bf1549ba9405f87c376d2d338883f54bfeb6a91f40b28e62dd2ce5e9d4edd4e5L178
The author should do the following, if applicable
bun run format:fix && bun run lint:fix
to format the code