4 ms·
Writing a fast router can be surprisingly difficult if you are trying to cover the edges. The state of the art is not trivial: https://github.com/dotnet/aspnet
by bob1029 11mo ago
Writing a fast router can be surprisingly difficult if you are trying to cover the edges. The state of the art is not trivial:
https://github.com/dotnet/aspnetcore/blob/main/src/Http/Routing/src/Matching/DfaMatcher.cs https://github.com/dotnet/aspnetcore/blob/main/src/Http/Rout...
- embedding-shape 11mo agoThe thing is, performance in that particular context hardly matters, unless you're forcing users to switch pages faster than 1 page per second. Even if each resolving takes 0.1 seconds (which be bad, don't get me wrong), 99% of users wouldn't notice a thing, and if you're a small agency/shop/company/team, focusing on more general things tends to be time spent better.
- recursive 11mo agoI have a hard time imagining how one would implement a router that took a full millisecond to resolve a path in a typical case.
- embedding-shape 11mo agoImagine doing a call to a remote authentication service to check who has access to what :) Regardless, performance is usually not the biggest problem in those types of routers.
- recursive 11mo agoAuthorization seems different from route resolution to me. But I guess I wouldn't be surprised if someone was doing it that way.
- jazzypants 11mo agoYou're assuming that URLPattern is performant... That doesn't seem to be the case currently. https://adventures.nodeland.dev/archive/you-should-not-use-urlpattern-to-route-http/ https://adventures.nodeland.dev/archive/you-should-not-use-u... https://github.com/denoland/deno/issues/19861 https://github.com/denoland/deno/issues/19861
- embedding-shape 11mo ago> assuming that URLPattern is performant Whose implementation, specifically? I don't think as specified URLPattern has any inherent performance drawbacks compared to the alternatives, but it seems like V8/NodeJS/Deno definitely didn't thought closely and/or clearly about performance when they did theirs.
- jazzypants 11mo agoAll three of those use the same implementation. I would hope that this will be improved over time, but it's not a guarantee by any stretch of the imagination.
- embedding-shape 11mo agoThanks, I wasn't sure, as I thought Deno used V8 but then the issue linked earlier shared "The implementation of URLPattern in Deno is super non-performant" so it seemed to me like Deno maybe had their own implementation instead of using the V8 one.
- spankalee 11mo agoURLPattern can be plenty fast if you use them in a fast data structure, like a prefix tree as pointed out in that first link. And there's no reason why URLPattern can't do that. So I went and made an implementation of URLPatternList that uses a prefix tree and is 20-30x faster than a linear scan for large lists of URLPatterns: https://github.com/justinfagnani/url-pattern-list https://github.com/justinfagnani/url-pattern-list