Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Is this really that much easier than matching paths and query strings yourself? I'm glad that there is an official API now, but this article didn't really show me anything to get excited about as someone who has built several client-side routers from scratch.




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/Rout...


You're assuming that URLPattern is performant... That doesn't seem to be the case currently.

https://adventures.nodeland.dev/archive/you-should-not-use-u...

https://github.com/denoland/deno/issues/19861


URLPattern 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


> 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.


All 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.

Thanks, 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.

The 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.

I have a hard time imagining how one would implement a router that took a full millisecond to resolve a path in a typical case.

Imagine 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.

Authorization seems different from route resolution to me. But I guess I wouldn't be surprised if someone was doing it that way.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: