1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00
denoland-deno/ext
Marcos Casagrande bf9ddb7c2e perf(ext/request): optimize Request constructor (#20141)
This PR optimizes `Request` constructor when `init` is not empty. This
path is also used by `fetch` when `options` argument is used
```js
fetch("https://deno.land", {
  method: "POST",
  body: 'land'
});
```

- Removed 3 extra calls to `headerListFromHeaders`
- Avoid `Object.keys` & `headerList` clone if `init.headers` is set
- Only empty `headersList` (`.splice`) if it's not already empty. 

## Benchmarks

**this patch**
```
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
----------------------------------------------------------------------------- -----------------------------
Request without headers       1.86 µs/iter     536,440.7     (1.67 µs … 2.76 µs)   1.89 µs   2.76 µs   2.76 µs
Request with headers          1.96 µs/iter     509,440.5     (1.83 µs … 2.17 µs)   1.99 µs   2.17 µs   2.17 µ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
----------------------------------------------------------------------------- -----------------------------
Request without headers       1.96 µs/iter     510,201.5     (1.81 µs … 2.64 µs)      2 µs   2.64 µs   2.64 µs
Request with headers          2.03 µs/iter     493,526.6     (1.84 µs … 2.31 µs)   2.08 µs   2.31 µs   2.31 µs
```

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

Deno.bench("Request with headers", () => {
  const r = new Request("https://deno.land", {
    method: "POST",
    body: '{"foo": "bar"}',
    headers: {
      "Content-Type": "application/json",
    },
  });
});
```
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 Request constructor (#20141) 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