2023-01-02 16:00:42 -05:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
2021-09-08 05:14:29 -04:00
|
|
|
|
|
|
|
// @ts-check
|
|
|
|
/// <reference path="../../core/internal.d.ts" />
|
|
|
|
/// <reference path="../../core/lib.deno_core.d.ts" />
|
|
|
|
/// <reference path="../webidl/internal.d.ts" />
|
|
|
|
/// <reference path="./internal.d.ts" />
|
|
|
|
/// <reference path="./lib.deno_url.d.ts" />
|
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
const core = globalThis.Deno.core;
|
|
|
|
const ops = core.ops;
|
2023-03-08 06:44:54 -05:00
|
|
|
import * as webidl from "ext:deno_webidl/00_webidl.js";
|
2023-11-19 03:13:38 -05:00
|
|
|
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
|
2023-02-07 14:22:46 -05:00
|
|
|
const primordials = globalThis.__bootstrap.primordials;
|
|
|
|
const {
|
2023-05-01 09:30:02 -04:00
|
|
|
ArrayPrototypePop,
|
2023-02-07 14:22:46 -05:00
|
|
|
RegExpPrototypeExec,
|
|
|
|
RegExpPrototypeTest,
|
2023-11-19 03:13:38 -05:00
|
|
|
ObjectPrototypeIsPrototypeOf,
|
2023-02-28 18:14:16 -05:00
|
|
|
SafeRegExp,
|
2023-02-07 14:22:46 -05:00
|
|
|
Symbol,
|
|
|
|
SymbolFor,
|
|
|
|
TypeError,
|
|
|
|
} = primordials;
|
|
|
|
|
perf(ext/urlpattern): optimize URLPattern.exec (#20170)
This PR optimizes `URLPattern.exec`
- Use component keys from constructor instead of calling it on every
`.exec`. AFAIK keys should always be
`protocol`,`username`,`password`,`hostname`,`port`,`pathname`,`search`,`hash`.
Haven't looked much into it but I think it's safe to define these
outside the constructor as well.
- Add a fast path for `/^$/u` (default regexp) and empty input
- Replaced `ArrayPrototypeMap` & `ObjectFromEntries` with a `for` loop.
**this PR**
```
cpu: 13th Gen Intel(R) Core(TM) i9-13900H
runtime: deno 1.36.1 (x86_64-unknown-linux-gnu)
benchmark time (avg) iter/s (min … max) p75 p99 p995
--------------------------------------------------------------- -----------------------------
exec 1 2.17 µs/iter 461,022.8 (2.14 µs … 2.27 µs) 2.18 µs 2.27 µs 2.27 µs
exec 2 4.13 µs/iter 242,173.4 (4.08 µs … 4.27 µs) 4.15 µs 4.27 µs 4.27 µs
exec 3 2.55 µs/iter 391,508.1 (2.53 µs … 2.68 µs) 2.56 µs 2.68 µs 2.68 µs
```
**main**
```
cpu: 13th Gen Intel(R) Core(TM) i9-13900H
runtime: deno 1.36.1 (x86_64-unknown-linux-gnu)
benchmark time (avg) iter/s (min … max) p75 p99 p995
--------------------------------------------------------------- -----------------------------
exec 1 2.45 µs/iter 408,092.4 (2.41 µs … 2.55 µs) 2.46 µs 2.55 µs 2.55 µs
exec 2 4.41 µs/iter 226,706.0 (3.49 µs … 399.56 µs) 4.39 µs 5.49 µs 6.07 µs
exec 3 2.99 µs/iter 334,833.4 (2.94 µs … 3.21 µs) 2.99 µs 3.21 µs 3.21 µs
```
2023-08-16 06:58:03 -04:00
|
|
|
const EMPTY_MATCH = [""];
|
2023-02-07 14:22:46 -05:00
|
|
|
const _components = Symbol("components");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @typedef Components
|
|
|
|
* @property {Component} protocol
|
|
|
|
* @property {Component} username
|
|
|
|
* @property {Component} password
|
|
|
|
* @property {Component} hostname
|
|
|
|
* @property {Component} port
|
|
|
|
* @property {Component} pathname
|
|
|
|
* @property {Component} search
|
|
|
|
* @property {Component} hash
|
|
|
|
*/
|
perf(ext/urlpattern): optimize URLPattern.exec (#20170)
This PR optimizes `URLPattern.exec`
- Use component keys from constructor instead of calling it on every
`.exec`. AFAIK keys should always be
`protocol`,`username`,`password`,`hostname`,`port`,`pathname`,`search`,`hash`.
Haven't looked much into it but I think it's safe to define these
outside the constructor as well.
- Add a fast path for `/^$/u` (default regexp) and empty input
- Replaced `ArrayPrototypeMap` & `ObjectFromEntries` with a `for` loop.
**this PR**
```
cpu: 13th Gen Intel(R) Core(TM) i9-13900H
runtime: deno 1.36.1 (x86_64-unknown-linux-gnu)
benchmark time (avg) iter/s (min … max) p75 p99 p995
--------------------------------------------------------------- -----------------------------
exec 1 2.17 µs/iter 461,022.8 (2.14 µs … 2.27 µs) 2.18 µs 2.27 µs 2.27 µs
exec 2 4.13 µs/iter 242,173.4 (4.08 µs … 4.27 µs) 4.15 µs 4.27 µs 4.27 µs
exec 3 2.55 µs/iter 391,508.1 (2.53 µs … 2.68 µs) 2.56 µs 2.68 µs 2.68 µs
```
**main**
```
cpu: 13th Gen Intel(R) Core(TM) i9-13900H
runtime: deno 1.36.1 (x86_64-unknown-linux-gnu)
benchmark time (avg) iter/s (min … max) p75 p99 p995
--------------------------------------------------------------- -----------------------------
exec 1 2.45 µs/iter 408,092.4 (2.41 µs … 2.55 µs) 2.46 µs 2.55 µs 2.55 µs
exec 2 4.41 µs/iter 226,706.0 (3.49 µs … 399.56 µs) 4.39 µs 5.49 µs 6.07 µs
exec 3 2.99 µs/iter 334,833.4 (2.94 µs … 3.21 µs) 2.99 µs 3.21 µs 3.21 µs
```
2023-08-16 06:58:03 -04:00
|
|
|
const COMPONENTS_KEYS = [
|
|
|
|
"protocol",
|
|
|
|
"username",
|
|
|
|
"password",
|
|
|
|
"hostname",
|
|
|
|
"port",
|
|
|
|
"pathname",
|
|
|
|
"search",
|
|
|
|
"hash",
|
|
|
|
];
|
2023-02-07 14:22:46 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @typedef Component
|
|
|
|
* @property {string} patternString
|
|
|
|
* @property {RegExp} regexp
|
|
|
|
* @property {string[]} groupNameList
|
|
|
|
*/
|
|
|
|
|
|
|
|
class URLPattern {
|
|
|
|
/** @type {Components} */
|
|
|
|
[_components];
|
2021-09-08 05:14:29 -04:00
|
|
|
|
|
|
|
/**
|
2023-02-07 14:22:46 -05:00
|
|
|
* @param {URLPatternInput} input
|
|
|
|
* @param {string} [baseURL]
|
2021-09-08 05:14:29 -04:00
|
|
|
*/
|
2023-02-07 14:22:46 -05:00
|
|
|
constructor(input, baseURL = undefined) {
|
|
|
|
this[webidl.brand] = webidl.brand;
|
|
|
|
const prefix = "Failed to construct 'URLPattern'";
|
2023-04-12 15:58:57 -04:00
|
|
|
webidl.requiredArguments(arguments.length, 1, prefix);
|
2023-05-01 06:47:13 -04:00
|
|
|
input = webidl.converters.URLPatternInput(input, prefix, "Argument 1");
|
2023-02-07 14:22:46 -05:00
|
|
|
if (baseURL !== undefined) {
|
2023-05-01 06:47:13 -04:00
|
|
|
baseURL = webidl.converters.USVString(baseURL, prefix, "Argument 2");
|
2023-02-07 14:22:46 -05:00
|
|
|
}
|
2021-09-08 05:14:29 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
const components = ops.op_urlpattern_parse(input, baseURL);
|
2021-09-08 05:14:29 -04:00
|
|
|
|
perf(ext/urlpattern): optimize URLPattern.exec (#20170)
This PR optimizes `URLPattern.exec`
- Use component keys from constructor instead of calling it on every
`.exec`. AFAIK keys should always be
`protocol`,`username`,`password`,`hostname`,`port`,`pathname`,`search`,`hash`.
Haven't looked much into it but I think it's safe to define these
outside the constructor as well.
- Add a fast path for `/^$/u` (default regexp) and empty input
- Replaced `ArrayPrototypeMap` & `ObjectFromEntries` with a `for` loop.
**this PR**
```
cpu: 13th Gen Intel(R) Core(TM) i9-13900H
runtime: deno 1.36.1 (x86_64-unknown-linux-gnu)
benchmark time (avg) iter/s (min … max) p75 p99 p995
--------------------------------------------------------------- -----------------------------
exec 1 2.17 µs/iter 461,022.8 (2.14 µs … 2.27 µs) 2.18 µs 2.27 µs 2.27 µs
exec 2 4.13 µs/iter 242,173.4 (4.08 µs … 4.27 µs) 4.15 µs 4.27 µs 4.27 µs
exec 3 2.55 µs/iter 391,508.1 (2.53 µs … 2.68 µs) 2.56 µs 2.68 µs 2.68 µs
```
**main**
```
cpu: 13th Gen Intel(R) Core(TM) i9-13900H
runtime: deno 1.36.1 (x86_64-unknown-linux-gnu)
benchmark time (avg) iter/s (min … max) p75 p99 p995
--------------------------------------------------------------- -----------------------------
exec 1 2.45 µs/iter 408,092.4 (2.41 µs … 2.55 µs) 2.46 µs 2.55 µs 2.55 µs
exec 2 4.41 µs/iter 226,706.0 (3.49 µs … 399.56 µs) 4.39 µs 5.49 µs 6.07 µs
exec 3 2.99 µs/iter 334,833.4 (2.94 µs … 3.21 µs) 2.99 µs 3.21 µs 3.21 µs
```
2023-08-16 06:58:03 -04:00
|
|
|
for (let i = 0; i < COMPONENTS_KEYS.length; ++i) {
|
|
|
|
const key = COMPONENTS_KEYS[i];
|
2023-02-07 14:22:46 -05:00
|
|
|
try {
|
2023-02-28 18:14:16 -05:00
|
|
|
components[key].regexp = new SafeRegExp(
|
2023-02-07 14:22:46 -05:00
|
|
|
components[key].regexpString,
|
|
|
|
"u",
|
|
|
|
);
|
perf(ext/urlpattern): optimize URLPattern.exec (#20170)
This PR optimizes `URLPattern.exec`
- Use component keys from constructor instead of calling it on every
`.exec`. AFAIK keys should always be
`protocol`,`username`,`password`,`hostname`,`port`,`pathname`,`search`,`hash`.
Haven't looked much into it but I think it's safe to define these
outside the constructor as well.
- Add a fast path for `/^$/u` (default regexp) and empty input
- Replaced `ArrayPrototypeMap` & `ObjectFromEntries` with a `for` loop.
**this PR**
```
cpu: 13th Gen Intel(R) Core(TM) i9-13900H
runtime: deno 1.36.1 (x86_64-unknown-linux-gnu)
benchmark time (avg) iter/s (min … max) p75 p99 p995
--------------------------------------------------------------- -----------------------------
exec 1 2.17 µs/iter 461,022.8 (2.14 µs … 2.27 µs) 2.18 µs 2.27 µs 2.27 µs
exec 2 4.13 µs/iter 242,173.4 (4.08 µs … 4.27 µs) 4.15 µs 4.27 µs 4.27 µs
exec 3 2.55 µs/iter 391,508.1 (2.53 µs … 2.68 µs) 2.56 µs 2.68 µs 2.68 µs
```
**main**
```
cpu: 13th Gen Intel(R) Core(TM) i9-13900H
runtime: deno 1.36.1 (x86_64-unknown-linux-gnu)
benchmark time (avg) iter/s (min … max) p75 p99 p995
--------------------------------------------------------------- -----------------------------
exec 1 2.45 µs/iter 408,092.4 (2.41 µs … 2.55 µs) 2.46 µs 2.55 µs 2.55 µs
exec 2 4.41 µs/iter 226,706.0 (3.49 µs … 399.56 µs) 4.39 µs 5.49 µs 6.07 µs
exec 3 2.99 µs/iter 334,833.4 (2.94 µs … 3.21 µs) 2.99 µs 3.21 µs 3.21 µs
```
2023-08-16 06:58:03 -04:00
|
|
|
// used for fast path
|
|
|
|
components[key].matchOnEmptyInput =
|
|
|
|
components[key].regexpString === "^$";
|
2023-02-07 14:22:46 -05:00
|
|
|
} catch (e) {
|
|
|
|
throw new TypeError(`${prefix}: ${key} is invalid; ${e.message}`);
|
|
|
|
}
|
2021-09-08 05:14:29 -04:00
|
|
|
}
|
2023-02-07 14:22:46 -05:00
|
|
|
this[_components] = components;
|
|
|
|
}
|
2021-09-08 05:14:29 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
get protocol() {
|
|
|
|
webidl.assertBranded(this, URLPatternPrototype);
|
|
|
|
return this[_components].protocol.patternString;
|
|
|
|
}
|
2021-09-08 05:14:29 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
get username() {
|
|
|
|
webidl.assertBranded(this, URLPatternPrototype);
|
|
|
|
return this[_components].username.patternString;
|
|
|
|
}
|
2021-09-08 05:14:29 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
get password() {
|
|
|
|
webidl.assertBranded(this, URLPatternPrototype);
|
|
|
|
return this[_components].password.patternString;
|
|
|
|
}
|
2021-09-08 05:14:29 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
get hostname() {
|
|
|
|
webidl.assertBranded(this, URLPatternPrototype);
|
|
|
|
return this[_components].hostname.patternString;
|
|
|
|
}
|
2021-09-08 05:14:29 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
get port() {
|
|
|
|
webidl.assertBranded(this, URLPatternPrototype);
|
|
|
|
return this[_components].port.patternString;
|
|
|
|
}
|
2021-09-08 05:14:29 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
get pathname() {
|
|
|
|
webidl.assertBranded(this, URLPatternPrototype);
|
|
|
|
return this[_components].pathname.patternString;
|
|
|
|
}
|
2021-09-08 05:14:29 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
get search() {
|
|
|
|
webidl.assertBranded(this, URLPatternPrototype);
|
|
|
|
return this[_components].search.patternString;
|
|
|
|
}
|
|
|
|
|
|
|
|
get hash() {
|
|
|
|
webidl.assertBranded(this, URLPatternPrototype);
|
|
|
|
return this[_components].hash.patternString;
|
|
|
|
}
|
2021-09-08 05:14:29 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
/**
|
|
|
|
* @param {URLPatternInput} input
|
|
|
|
* @param {string} [baseURL]
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
test(input, baseURL = undefined) {
|
|
|
|
webidl.assertBranded(this, URLPatternPrototype);
|
|
|
|
const prefix = "Failed to execute 'test' on 'URLPattern'";
|
2023-04-12 15:58:57 -04:00
|
|
|
webidl.requiredArguments(arguments.length, 1, prefix);
|
2023-05-01 06:47:13 -04:00
|
|
|
input = webidl.converters.URLPatternInput(input, prefix, "Argument 1");
|
2023-02-07 14:22:46 -05:00
|
|
|
if (baseURL !== undefined) {
|
2023-05-01 06:47:13 -04:00
|
|
|
baseURL = webidl.converters.USVString(baseURL, prefix, "Argument 2");
|
2023-02-07 14:22:46 -05:00
|
|
|
}
|
2021-09-08 05:14:29 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
const res = ops.op_urlpattern_process_match_input(
|
|
|
|
input,
|
|
|
|
baseURL,
|
|
|
|
);
|
|
|
|
if (res === null) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-09-08 05:14:29 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
const values = res[0];
|
2021-09-08 05:14:29 -04:00
|
|
|
|
perf(ext/urlpattern): optimize URLPattern.exec (#20170)
This PR optimizes `URLPattern.exec`
- Use component keys from constructor instead of calling it on every
`.exec`. AFAIK keys should always be
`protocol`,`username`,`password`,`hostname`,`port`,`pathname`,`search`,`hash`.
Haven't looked much into it but I think it's safe to define these
outside the constructor as well.
- Add a fast path for `/^$/u` (default regexp) and empty input
- Replaced `ArrayPrototypeMap` & `ObjectFromEntries` with a `for` loop.
**this PR**
```
cpu: 13th Gen Intel(R) Core(TM) i9-13900H
runtime: deno 1.36.1 (x86_64-unknown-linux-gnu)
benchmark time (avg) iter/s (min … max) p75 p99 p995
--------------------------------------------------------------- -----------------------------
exec 1 2.17 µs/iter 461,022.8 (2.14 µs … 2.27 µs) 2.18 µs 2.27 µs 2.27 µs
exec 2 4.13 µs/iter 242,173.4 (4.08 µs … 4.27 µs) 4.15 µs 4.27 µs 4.27 µs
exec 3 2.55 µs/iter 391,508.1 (2.53 µs … 2.68 µs) 2.56 µs 2.68 µs 2.68 µs
```
**main**
```
cpu: 13th Gen Intel(R) Core(TM) i9-13900H
runtime: deno 1.36.1 (x86_64-unknown-linux-gnu)
benchmark time (avg) iter/s (min … max) p75 p99 p995
--------------------------------------------------------------- -----------------------------
exec 1 2.45 µs/iter 408,092.4 (2.41 µs … 2.55 µs) 2.46 µs 2.55 µs 2.55 µs
exec 2 4.41 µs/iter 226,706.0 (3.49 µs … 399.56 µs) 4.39 µs 5.49 µs 6.07 µs
exec 3 2.99 µs/iter 334,833.4 (2.94 µs … 3.21 µs) 2.99 µs 3.21 µs 3.21 µs
```
2023-08-16 06:58:03 -04:00
|
|
|
for (let i = 0; i < COMPONENTS_KEYS.length; ++i) {
|
|
|
|
const key = COMPONENTS_KEYS[i];
|
2023-02-07 14:22:46 -05:00
|
|
|
if (!RegExpPrototypeTest(this[_components][key].regexp, values[key])) {
|
|
|
|
return false;
|
2021-09-08 05:14:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {URLPatternInput} input
|
|
|
|
* @param {string} [baseURL]
|
|
|
|
* @returns {URLPatternResult | null}
|
|
|
|
*/
|
|
|
|
exec(input, baseURL = undefined) {
|
|
|
|
webidl.assertBranded(this, URLPatternPrototype);
|
|
|
|
const prefix = "Failed to execute 'exec' on 'URLPattern'";
|
2023-04-12 15:58:57 -04:00
|
|
|
webidl.requiredArguments(arguments.length, 1, prefix);
|
2023-05-01 06:47:13 -04:00
|
|
|
input = webidl.converters.URLPatternInput(input, prefix, "Argument 1");
|
2023-02-07 14:22:46 -05:00
|
|
|
if (baseURL !== undefined) {
|
2023-05-01 06:47:13 -04:00
|
|
|
baseURL = webidl.converters.USVString(baseURL, prefix, "Argument 2");
|
2023-02-07 14:22:46 -05:00
|
|
|
}
|
2021-09-08 05:14:29 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
const res = ops.op_urlpattern_process_match_input(
|
|
|
|
input,
|
|
|
|
baseURL,
|
|
|
|
);
|
|
|
|
if (res === null) {
|
|
|
|
return null;
|
|
|
|
}
|
2021-09-08 05:14:29 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
const { 0: values, 1: inputs } = res;
|
|
|
|
if (inputs[1] === null) {
|
2023-05-01 09:30:02 -04:00
|
|
|
ArrayPrototypePop(inputs);
|
2023-02-07 14:22:46 -05:00
|
|
|
}
|
2021-09-08 05:14:29 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
/** @type {URLPatternResult} */
|
|
|
|
const result = { inputs };
|
|
|
|
|
perf(ext/urlpattern): optimize URLPattern.exec (#20170)
This PR optimizes `URLPattern.exec`
- Use component keys from constructor instead of calling it on every
`.exec`. AFAIK keys should always be
`protocol`,`username`,`password`,`hostname`,`port`,`pathname`,`search`,`hash`.
Haven't looked much into it but I think it's safe to define these
outside the constructor as well.
- Add a fast path for `/^$/u` (default regexp) and empty input
- Replaced `ArrayPrototypeMap` & `ObjectFromEntries` with a `for` loop.
**this PR**
```
cpu: 13th Gen Intel(R) Core(TM) i9-13900H
runtime: deno 1.36.1 (x86_64-unknown-linux-gnu)
benchmark time (avg) iter/s (min … max) p75 p99 p995
--------------------------------------------------------------- -----------------------------
exec 1 2.17 µs/iter 461,022.8 (2.14 µs … 2.27 µs) 2.18 µs 2.27 µs 2.27 µs
exec 2 4.13 µs/iter 242,173.4 (4.08 µs … 4.27 µs) 4.15 µs 4.27 µs 4.27 µs
exec 3 2.55 µs/iter 391,508.1 (2.53 µs … 2.68 µs) 2.56 µs 2.68 µs 2.68 µs
```
**main**
```
cpu: 13th Gen Intel(R) Core(TM) i9-13900H
runtime: deno 1.36.1 (x86_64-unknown-linux-gnu)
benchmark time (avg) iter/s (min … max) p75 p99 p995
--------------------------------------------------------------- -----------------------------
exec 1 2.45 µs/iter 408,092.4 (2.41 µs … 2.55 µs) 2.46 µs 2.55 µs 2.55 µs
exec 2 4.41 µs/iter 226,706.0 (3.49 µs … 399.56 µs) 4.39 µs 5.49 µs 6.07 µs
exec 3 2.99 µs/iter 334,833.4 (2.94 µs … 3.21 µs) 2.99 µs 3.21 µs 3.21 µs
```
2023-08-16 06:58:03 -04:00
|
|
|
for (let i = 0; i < COMPONENTS_KEYS.length; ++i) {
|
|
|
|
const key = COMPONENTS_KEYS[i];
|
2023-02-07 14:22:46 -05:00
|
|
|
/** @type {Component} */
|
|
|
|
const component = this[_components][key];
|
|
|
|
const input = values[key];
|
perf(ext/urlpattern): optimize URLPattern.exec (#20170)
This PR optimizes `URLPattern.exec`
- Use component keys from constructor instead of calling it on every
`.exec`. AFAIK keys should always be
`protocol`,`username`,`password`,`hostname`,`port`,`pathname`,`search`,`hash`.
Haven't looked much into it but I think it's safe to define these
outside the constructor as well.
- Add a fast path for `/^$/u` (default regexp) and empty input
- Replaced `ArrayPrototypeMap` & `ObjectFromEntries` with a `for` loop.
**this PR**
```
cpu: 13th Gen Intel(R) Core(TM) i9-13900H
runtime: deno 1.36.1 (x86_64-unknown-linux-gnu)
benchmark time (avg) iter/s (min … max) p75 p99 p995
--------------------------------------------------------------- -----------------------------
exec 1 2.17 µs/iter 461,022.8 (2.14 µs … 2.27 µs) 2.18 µs 2.27 µs 2.27 µs
exec 2 4.13 µs/iter 242,173.4 (4.08 µs … 4.27 µs) 4.15 µs 4.27 µs 4.27 µs
exec 3 2.55 µs/iter 391,508.1 (2.53 µs … 2.68 µs) 2.56 µs 2.68 µs 2.68 µs
```
**main**
```
cpu: 13th Gen Intel(R) Core(TM) i9-13900H
runtime: deno 1.36.1 (x86_64-unknown-linux-gnu)
benchmark time (avg) iter/s (min … max) p75 p99 p995
--------------------------------------------------------------- -----------------------------
exec 1 2.45 µs/iter 408,092.4 (2.41 µs … 2.55 µs) 2.46 µs 2.55 µs 2.55 µs
exec 2 4.41 µs/iter 226,706.0 (3.49 µs … 399.56 µs) 4.39 µs 5.49 µs 6.07 µs
exec 3 2.99 µs/iter 334,833.4 (2.94 µs … 3.21 µs) 2.99 µs 3.21 µs 3.21 µs
```
2023-08-16 06:58:03 -04:00
|
|
|
|
|
|
|
const match = component.matchOnEmptyInput && input === ""
|
|
|
|
? EMPTY_MATCH // fast path
|
|
|
|
: RegExpPrototypeExec(component.regexp, input);
|
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
if (match === null) {
|
|
|
|
return null;
|
2021-09-08 05:14:29 -04:00
|
|
|
}
|
perf(ext/urlpattern): optimize URLPattern.exec (#20170)
This PR optimizes `URLPattern.exec`
- Use component keys from constructor instead of calling it on every
`.exec`. AFAIK keys should always be
`protocol`,`username`,`password`,`hostname`,`port`,`pathname`,`search`,`hash`.
Haven't looked much into it but I think it's safe to define these
outside the constructor as well.
- Add a fast path for `/^$/u` (default regexp) and empty input
- Replaced `ArrayPrototypeMap` & `ObjectFromEntries` with a `for` loop.
**this PR**
```
cpu: 13th Gen Intel(R) Core(TM) i9-13900H
runtime: deno 1.36.1 (x86_64-unknown-linux-gnu)
benchmark time (avg) iter/s (min … max) p75 p99 p995
--------------------------------------------------------------- -----------------------------
exec 1 2.17 µs/iter 461,022.8 (2.14 µs … 2.27 µs) 2.18 µs 2.27 µs 2.27 µs
exec 2 4.13 µs/iter 242,173.4 (4.08 µs … 4.27 µs) 4.15 µs 4.27 µs 4.27 µs
exec 3 2.55 µs/iter 391,508.1 (2.53 µs … 2.68 µs) 2.56 µs 2.68 µs 2.68 µs
```
**main**
```
cpu: 13th Gen Intel(R) Core(TM) i9-13900H
runtime: deno 1.36.1 (x86_64-unknown-linux-gnu)
benchmark time (avg) iter/s (min … max) p75 p99 p995
--------------------------------------------------------------- -----------------------------
exec 1 2.45 µs/iter 408,092.4 (2.41 µs … 2.55 µs) 2.46 µs 2.55 µs 2.55 µs
exec 2 4.41 µs/iter 226,706.0 (3.49 µs … 399.56 µs) 4.39 µs 5.49 µs 6.07 µs
exec 3 2.99 µs/iter 334,833.4 (2.94 µs … 3.21 µs) 2.99 µs 3.21 µs 3.21 µs
```
2023-08-16 06:58:03 -04:00
|
|
|
|
|
|
|
const groups = {};
|
|
|
|
const groupList = component.groupNameList;
|
|
|
|
for (let i = 0; i < groupList.length; ++i) {
|
|
|
|
groups[groupList[i]] = match[i + 1] ?? "";
|
|
|
|
}
|
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
result[key] = {
|
|
|
|
input,
|
|
|
|
groups,
|
|
|
|
};
|
2021-09-08 05:14:29 -04:00
|
|
|
}
|
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
return result;
|
2021-09-08 05:14:29 -04:00
|
|
|
}
|
|
|
|
|
2023-11-19 03:13:38 -05:00
|
|
|
[SymbolFor("Deno.privateCustomInspect")](inspect, inspectOptions) {
|
|
|
|
return inspect(
|
|
|
|
createFilteredInspectProxy({
|
|
|
|
object: this,
|
|
|
|
evaluate: ObjectPrototypeIsPrototypeOf(URLPatternPrototype, this),
|
|
|
|
keys: [
|
|
|
|
"protocol",
|
|
|
|
"username",
|
|
|
|
"password",
|
|
|
|
"hostname",
|
|
|
|
"port",
|
|
|
|
"pathname",
|
|
|
|
"search",
|
|
|
|
"hash",
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
inspectOptions,
|
|
|
|
);
|
2023-02-07 14:22:46 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-09 23:01:01 -04:00
|
|
|
webidl.configureInterface(URLPattern);
|
2023-02-07 14:22:46 -05:00
|
|
|
const URLPatternPrototype = URLPattern.prototype;
|
|
|
|
|
|
|
|
webidl.converters.URLPatternInit = webidl
|
|
|
|
.createDictionaryConverter("URLPatternInit", [
|
|
|
|
{ key: "protocol", converter: webidl.converters.USVString },
|
|
|
|
{ key: "username", converter: webidl.converters.USVString },
|
|
|
|
{ key: "password", converter: webidl.converters.USVString },
|
|
|
|
{ key: "hostname", converter: webidl.converters.USVString },
|
|
|
|
{ key: "port", converter: webidl.converters.USVString },
|
|
|
|
{ key: "pathname", converter: webidl.converters.USVString },
|
|
|
|
{ key: "search", converter: webidl.converters.USVString },
|
|
|
|
{ key: "hash", converter: webidl.converters.USVString },
|
|
|
|
{ key: "baseURL", converter: webidl.converters.USVString },
|
|
|
|
]);
|
|
|
|
|
2023-05-01 06:47:13 -04:00
|
|
|
webidl.converters["URLPatternInput"] = (V, prefix, context, opts) => {
|
2023-02-07 14:22:46 -05:00
|
|
|
// Union for (URLPatternInit or USVString)
|
|
|
|
if (typeof V == "object") {
|
2023-05-01 06:47:13 -04:00
|
|
|
return webidl.converters.URLPatternInit(V, prefix, context, opts);
|
2023-02-07 14:22:46 -05:00
|
|
|
}
|
2023-05-01 06:47:13 -04:00
|
|
|
return webidl.converters.USVString(V, prefix, context, opts);
|
2023-02-07 14:22:46 -05:00
|
|
|
};
|
2021-09-08 05:14:29 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
export { URLPattern };
|