3 comments

  • jauntywundrkind3 hours ago
    Great tool. So glad we have something!<p>Alas, also has mis-use. You don&#x27;t want to linearly parse urls, as a router! Addition was controversial because folks anticipated mis-use like this. <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=46043318">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=46043318</a>
    • tshaddox2 hours ago
      It would take a very large number of routes before linear search would become a noticeable performance problem.<p>At that point, you’d probably be splitting the router itself into multiple client bundles, with something at the root to quickly match the URL with a bundle of routes (maybe a hash table on the first URL segment, or even a trie).<p>This URLPattern library and linear search would still be a reasonable choice for implementing each individual route bundle. And in practice, just do it the naive way until it actually becomes a problem.
    • mdhb3 hours ago
      Can you talk more about this… I was under the impression that was the EXPLICIT reason [1] why it was added in the first place or did I misread your comment?<p>It’s also something the Lit team uses like here: <a href="https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;@lit-labs&#x2F;router" rel="nofollow">https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;@lit-labs&#x2F;router</a><p>I think maybe we are just debating the data structure the hold the patterns? Like it should be a trie rather than say a Set or Map.<p>[1] <a href="https:&#x2F;&#x2F;developer.chrome.com&#x2F;docs&#x2F;web-platform&#x2F;urlpattern" rel="nofollow">https:&#x2F;&#x2F;developer.chrome.com&#x2F;docs&#x2F;web-platform&#x2F;urlpattern</a>
    • BiteCode_dev2 hours ago
      I just tried to match a URL against about a hundred patterns of various types (thanks to Claude code), expecting it to be a non-issue.<p>A hundred regex tests, for example, is generally very fast. A quick Python script made them run in 0.85ms. A hundred Flask router tests is 2.64ms.<p>So I had no reason to think this API would be slow. Surely matching a URL is a subset of generalized regexes and can only be fast? And given that routing is not an activity you do a lot, why would it matter anyway?<p>But the performances were atrocious: it took 8 seconds to resolve the worst-case scenario on Firefox, and it locked the entire browser UI.<p>Ok, note to self, stay away from the URL Pattern API.
      • creatonez1 hour ago
        ...Eight seconds for a hundred matches? What does your code look like?
        • BiteCode_dev30 minutes ago
          My bad, I should not read AI generated code while drunk at a xmas party. That&#x27;s the total run time for 10000 iterations.<p>Average time for 100 tests is hence 0.8 ms. Completely normal, and absolutely acceptable, especially for an operation as rare as routing.<p>Letting my previous comment as-is for historical purposes. And to remind myself I&#x27;m a dumbass.
  • petesergeant2 hours ago
    &gt; Note: This feature is available in Web Workers.<p>... is _also_ available in Web Workers, or _only_ available in Web Workers?
  • socketcluster1 hour ago
    I don&#x27;t like this API.<p>Overall I dislike the shift away from a URL as a language-agnostic string primitive to some weird convoluted object which is limited to specific use cases.<p>URL literally stands for Universal Resource Locator... A string is Universal. It can be passed around easily between processes, it can be easily stored in a database, it can be easily shared online, it can be easily passed to an LLM... URLs were supported by LLMs before LLMs even existed! You&#x27;ve got to appreciate that!<p>This class they call URL is actually not a URL at all, it&#x27;s more like a bound URLParser or URLExtractor.<p>A URL is a string that&#x27;s a fact. Even ask Google; &quot;is a URL a string?&quot; it will say yes.<p>The idea of a URL instance as a language-specific construct is a bad idea. It&#x27;s one of the reasons why many people don&#x27;t like Java.<p>[EDIT] I don&#x27;t dislike this API though it initially triggered my Java PTSD as I mistakenly thought it built on TOP of the URL instance. It actually takes things in the opposite direction as I initially understood; it&#x27;s moving back towards URLs as string primitives which is what I advocate for. I do hope we don&#x27;t end up adding too much more complexity related to URL handling though.
    • echoangle1 hour ago
      The class isn’t called URL, it’s called URLPattern. Because it represents a pattern that URLs can be matched against.
      • socketcluster47 minutes ago
        I was aware of the first part though I foolishly assumed by the name that it was designed specifically to work with the existing URL object. I then experienced a bout of Java PTSD.<p>Upon further analysis of the full API, it&#x27;s not as bad as I initially thought.<p>My initial reaction was kind of surface-level eye-rolling &quot;Oh no, don&#x27;t tell me they managed to find a way to make URL parsing even more complicated than it needs to be.&quot;<p>But in a way, this is almost an attempt at rolling back the previous complexity introduced by the URL instance and acknowledging the utility of the URL as a string primitive.<p>It is additional complexity but I guess at least it might prevent the need for additional future complexity.<p>I hope that&#x27;s the idea.