Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/fresh/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,14 @@ export class UrlPatternRouter<T> implements Router<T> {
for (let i = 0; i < this.#dynamicArr.length; i++) {
const route = this.#dynamicArr[i];

const match = route.pattern.exec(url);
// Pass `url.href` instead of the `URL` object: ~13-21x faster.
// Deno's URLPattern is a pure JS implementation. Given a `URL` object,
// `webidl.converters["URLPatternInput"]` walks and converts its
// properties on every call, and this happens *before* the internal
// match cache is consulted — so the cache never helps. A string skips
// that conversion entirely. `URL` objects cache their serialization,
// so reading `.href` here costs ~3ns.
const match = route.pattern.exec(url.href);
if (match === null) continue;

result.pattern = route.pattern.pathname;
Expand Down
Loading