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 ec63b36994
perf(ext/event): optimize Event constructor (#20181)
This PR optimizes `Event` constructor

- ~Added a fast path for empty `eventInitDict`~ Removed `EventInit`
dictionary converter
- Don't make `isTrusted` a
[LegacyUnforgeable](https://webidl.spec.whatwg.org/#LegacyUnforgeable)
property. Doing so makes it non-spec compliant but calling
`Object/Reflect.defineProperty` on the constructor is a big bottleneck.
Node did the same a few months ago
https://github.com/nodejs/node/pull/46974. In my opinion, the
performance gains are worth deviating from the spec for a
browser-related property.

**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
------------------------------------------------------------------------------- -----------------------------
event constructor no init      36.69 ns/iter  27,257,504.6   (33.36 ns … 42.45 ns)  37.71 ns  39.61 ns  40.07 ns
event constructor               36.7 ns/iter  27,246,776.6   (33.35 ns … 56.03 ns)  37.73 ns  40.14 ns  41.74 ns
```

**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
------------------------------------------------------------------------------- -----------------------------
event constructor no init     380.48 ns/iter   2,628,275.8 (366.66 ns … 399.39 ns) 384.58 ns 398.27 ns 399.39 ns
event constructor             480.33 ns/iter   2,081,882.6 (466.67 ns … 503.47 ns) 484.27 ns 501.28 ns 503.47 ns
```

```js
Deno.bench("event constructor no init", () => {
  const event = new Event("foo");
});

Deno.bench("event constructor", () => {
  const event = new Event("foo", { bubbles: true, cancelable: false });
});
```

towards https://github.com/denoland/deno/issues/20167
2023-08-17 10:35:18 +02:00
..
broadcast_channel chore: forward v1.36.1 to main (#20119) 2023-08-10 16:44:41 +03:00
cache chore: forward v1.36.1 to main (#20119) 2023-08-10 16:44:41 +03:00
console chore: forward v1.36.1 to main (#20119) 2023-08-10 16:44:41 +03:00
crypto chore: forward v1.36.1 to main (#20119) 2023-08-10 16:44:41 +03:00
fetch fix: release ReadeableStream in fetch (#17365) 2023-08-16 14:02:15 +02:00
ffi chore: forward v1.36.1 to main (#20119) 2023-08-10 16:44:41 +03:00
fs chore: forward v1.36.1 to main (#20119) 2023-08-10 16:44:41 +03:00
http perf(http): use Cow<[u8]> for setting header (#20112) 2023-08-10 15:35:01 -06:00
io chore: deno_core -> 0.201.0 (#20135) 2023-08-12 19:04:45 +00:00
kv chore: forward v1.36.1 to main (#20119) 2023-08-10 16:44:41 +03:00
napi chore: forward v1.36.1 to main (#20119) 2023-08-10 16:44:41 +03:00
net fix(ext/net): implement a graceful error on an invalid SSL certificate (#20157) 2023-08-15 00:11:12 +00:00
node fix(ext/node): allow for the reassignment of userInfo() on Windows (#20165) 2023-08-16 11:28:49 +02:00
tls chore: forward v1.36.1 to main (#20119) 2023-08-10 16:44:41 +03:00
url perf(ext/urlpattern): optimize URLPattern.exec (#20170) 2023-08-16 12:58:03 +02:00
web perf(ext/event): optimize Event constructor (#20181) 2023-08-17 10:35:18 +02:00
webidl chore: forward v1.36.1 to main (#20119) 2023-08-10 16:44:41 +03:00
websocket chore: forward v1.36.1 to main (#20119) 2023-08-10 16:44:41 +03:00
webstorage chore: forward v1.36.1 to main (#20119) 2023-08-10 16:44:41 +03:00