-
-
Notifications
You must be signed in to change notification settings - Fork 579
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
PoC: Introduce FilePatternRouter #1805
base: main
Are you sure you want to change the base?
Conversation
@yusukebe How about a router like this? |
Added basic tests by 8270f04 Now the performance of initialization is degrading.
|
Hi @usualoma ! To ensure I understand correctly, I want to know the advantages of using FilePatternRouter for file-based routing. I think marking Btw, I'm currently working on changing the API of Sonik to make it simpler by using Hono's core features. |
6e504c7 changes made it a little faster.
|
@yusukebe Supported Path Patterns
The following are not supported
Other Restrictions
There are no other restrictions and FilePatternRouter can be used just like any other router. At 41bbe94
|
Hi @usualoma, Thank you for explaining the details. I fully understand now. It's great to have a router specialized for file-based routing. As you mentioned, the patterns used in file-based routing are fewer than in normal Hono usage. Currently, for my plan to release the file-based routing feature, I'm not sure if it will be Sonik, separate from this Hono repo, or another framework structure, but it will be released as v4. So, I think we should consider including this FilePatternRouter in v4. Until then, how about we keep this open? |
I agree 👍
|
Sorry, I submitted once to #1850 by mistake. ConsI did not mention the cons of this router, so I will add them here. The regex generated is largeThe RegExpRouter compiled the regexes to be as small as possible, but the FilePatternRouter does not make that effort, so they become large for many routing registrations. For example
RegExpRouter: The current implementation is a PoC, so no effort has been made to make it smaller, but I think it could be made smaller by adding a few lines and allowing for a little overhead. Additional implementation would be necessary depending on the number of routings envisioned. |
@usualoma that's exciting! I'm wondering how you can address a proper doc page with examples and tips on how to organize code. Would you be able to provide some examples on this PR? I've used routing-controllers in the past which uses fancy よくやった 🚀 |
I've implemented another router!
It is debatable whether it is appropriate to add even more new routers, but I think this router has enough characteristics to merit discussion.
What features does this router have?
This is a router for file-based routing. Performance tuning was done by reducing the number of routing format patterns supported.
I haven't written a test yet, so it doesn't work properly, but it works on almost the same principle as RegExpRouter, so I think it will work if fixed bugs.
Benchmark
Nearly the same performance as RegExpRouter
Initialization performance is not as good as LinearRouter, but fast enough.
The bundle size of the application created with
sonik
on my environment was reduced as follows71.27 kB
->56.25 kB
Author should do the followings, if applicable
yarn denoify
to generate files for Deno