-
Notifications
You must be signed in to change notification settings - Fork 131
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
Potential performance improvements #371
Comments
This might be interesting. At the very least, IMHO, it's worth investigating. Thanks. |
Part of the reasons why we have stopped optimizing the router is that the bottlenecks of Fastify were elsewhere. The current code completely inlines when running on Fastify. On our "imprecise" benchmarks, this results in Fastify being one of the fastest solution you can use for Node.js: https://github.com/fastify/benchmarks. Note that the Hono benchmarks have a significant flaw: they bench creation time and lookup time together. This is necessary for Hono main target (CF), but I would expect different results if creation was taken into consideration: we never optimized it. I'll see if my hunch is true and there is a different story there ;). |
Maybe I misunderstood something but what I've seen is that all of the routers was initialized during import phase like for (const route of routes) {
router.on(route.method as HTTPMethod, route.path, handler)
}
export const findMyWayRouter: RouterInterface = {
name,
match: (route) => {
router.find(route.method as HTTPMethod, route.path)
},
} I didn't see any re-creation there, just |
Here the numbers I see:
Hono has a fast router that does not support all patterns and a slow router that supports all patterns. find-my-way supports all patterns. Now, if you add routes like these: router.add('GET', '/reg-exp/router', 'foo')
router.add('GET', '/reg-exp/:id', 'bar') Hono needs to revert to using the "slow" router, which is implemented in their "smart" router, tanking the performance. There are more of those here. (find-my-way is not affected by these problems). I personally don't like adding those kinds of traps in the source code of my libraries, because developers can easily fall into them and have really bad performance as a result. |
Amazing investigation, @mcollina |
Just found
hono
router benchmarks which shows thatfind-my-way
is 1.15x to 2.2x slower than hono's one in various scenarios.Could these benchmarks and hono router itself become a good material/background for future improvements?
Link for benchmarks:
https://github.com/honojs/hono/tree/main/benchmarks/routers
Link for hono routers codebase:
https://github.com/honojs/hono/tree/main/src/router
The text was updated successfully, but these errors were encountered: