1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-22 15:06:54 -05:00
denoland-deno/ext
Marcos Casagrande 4e08665973 perf(ext/request): optimize validate and normalize HTTP method (#20143)
This PR optimizes `Request` constructor init method step. It doubles the
speed for known lowercased methods. I also added `PATCH` to known
methods

**this patch**

```
benchmark                   time (avg)        iter/s             (min … max)       p75       p99      p995
---------------------------------------------------------------------------- -----------------------------
method: GET                  1.49 µs/iter     669,336.9     (1.35 µs … 2.02 µs)   1.54 µs   2.02 µs   2.02 µs
method: PATCH                1.85 µs/iter     540,921.5     (1.65 µs … 2.02 µs)   1.91 µs   2.02 µs   2.02 µs
method: get                  1.49 µs/iter     669,067.9     (1.28 µs … 1.69 µs)   1.55 µs   1.69 µs   1.69 µ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
---------------------------------------------------------------------------- -----------------------------
method: GET                   1.5 µs/iter     665,232.3      (1.3 µs … 2.02 µs)   1.54 µs   2.02 µs   2.02 µs
method: PATCH                2.47 µs/iter     404,052.7     (2.06 µs … 4.05 µs)   2.51 µs   4.05 µs   4.05 µs
method: get                     3 µs/iter     333,277.2     (2.72 µs … 4.04 µs)   3.05 µs   4.04 µs   4.04 µs
```

```js
Deno.bench("method: GET", () => {
  const r = new Request("https://deno.land", {
    method: "GET",
  });
});

Deno.bench("method: PATCH", () => {
  const r = new Request("https://deno.land", {
    method: "PATCH",
    body: '{"foo": "bar"}',
  });
});

Deno.bench("method: get", () => {
  const r = new Request("https://deno.land", {
    method: "get",
  });
});
```
2023-08-21 18:23:27 +05:30
..
broadcast_channel 1.36.1 (#20221) 2023-08-21 18:08:38 +05:30
cache 1.36.1 (#20221) 2023-08-21 18:08:38 +05:30
console 1.36.1 (#20221) 2023-08-21 18:08:38 +05:30
crypto 1.36.1 (#20221) 2023-08-21 18:08:38 +05:30
fetch perf(ext/request): optimize validate and normalize HTTP method (#20143) 2023-08-21 18:23:27 +05:30
ffi 1.36.1 (#20221) 2023-08-21 18:08:38 +05:30
fs 1.36.1 (#20221) 2023-08-21 18:08:38 +05:30
http perf(http): use Cow<[u8]> for setting header (#20112) 2023-08-21 18:23:27 +05:30
io 1.36.1 (#20221) 2023-08-21 18:08:38 +05:30
kv 1.36.1 (#20221) 2023-08-21 18:08:38 +05:30
napi 1.36.1 (#20221) 2023-08-21 18:08:38 +05:30
net 1.36.1 (#20221) 2023-08-21 18:08:38 +05:30
node fix(node): implement TLSSocket._start (#20120) 2023-08-21 18:23:27 +05:30
tls 1.36.1 (#20221) 2023-08-21 18:08:38 +05:30
url 1.36.1 (#20221) 2023-08-21 18:08:38 +05:30
web 1.36.1 (#20221) 2023-08-21 18:08:38 +05:30
webidl 1.36.1 (#20221) 2023-08-21 18:08:38 +05:30
websocket 1.36.1 (#20221) 2023-08-21 18:08:38 +05:30
webstorage 1.36.1 (#20221) 2023-08-21 18:08:38 +05:30