1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00
denoland-deno/ext/web
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
..
benches refactor: update core extension api usage (#19952) 2023-07-31 18:19:15 +00:00
00_infra.js fix(core): Use safe primordials wrappers (#18687) 2023-04-14 22:23:28 +02:00
01_dom_exception.js refactor(webidl): move prefix & context out of converters options bag (#18931) 2023-05-01 10:47:13 +00:00
01_mimesniff.js perf: optimize RegExp usage in JS (#19364) 2023-06-05 10:52:40 +02:00
02_event.js perf(ext/event): optimize Event constructor (#20181) 2023-08-17 10:35:18 +02:00
02_structured_clone.js fix(core): Use safe primordials wrappers (#18687) 2023-04-14 22:23:28 +02:00
02_timers.js fix(ext/timers): some timers are not resolved (#20055) 2023-08-10 04:01:35 +00:00
03_abort_signal.js fix(ext/abort): trigger AbortSignal events in correct order (#20095) 2023-08-08 12:05:42 +02:00
04_global_interfaces.js refactor: rename InternalModuleLoader to ExtModuleLoader, use ext: scheme for snapshotted modules (#18041) 2023-03-08 12:44:54 +01:00
05_base64.js refactor(webidl): move prefix & context out of converters options bag (#18931) 2023-05-01 10:47:13 +00:00
06_streams.js fix(ext/fetch): clone second branch chunks in Body.clone() (#20057) 2023-08-15 09:21:02 +02:00
06_streams_types.d.ts chore: update copyright year to 2023 (#17247) 2023-01-02 21:00:42 +00:00
08_text_encoding.js refactor(webidl): move prefix & context out of converters options bag (#18931) 2023-05-01 10:47:13 +00:00
09_file.js fix(ext/file): resolve unresolved Promise in Blob.stream (#20039) 2023-08-04 13:57:54 +02:00
10_filereader.js refactor(webidl): move prefix & context out of converters options bag (#18931) 2023-05-01 10:47:13 +00:00
12_location.js chore: fix typos (#19572) 2023-06-26 09:10:27 -04:00
13_message_port.js fix: call setIsTrusted for generated events (MessageEvent) (#19919) 2023-07-31 23:22:07 +02:00
14_compression.js refactor(webidl): move prefix & context out of converters options bag (#18931) 2023-05-01 10:47:13 +00:00
15_performance.js refactor(webidl): move prefix & context out of converters options bag (#18931) 2023-05-01 10:47:13 +00:00
blob.rs Reland "fix(cli): don't store blob and data urls in the module cache" (#18581) 2023-07-02 00:52:30 +02:00
Cargo.toml chore: forward v1.36.1 to main (#20119) 2023-08-10 16:44:41 +03:00
compression.rs fix(ext/compression): throw TypeError on corrupt input (#19979) 2023-07-30 09:15:29 -04:00
hr_timer_lock.rs chore: update to Rust 1.71 (#19822) 2023-07-13 15:16:24 -06:00
internal.d.ts refactor: rename InternalModuleLoader to ExtModuleLoader, use ext: scheme for snapshotted modules (#18041) 2023-03-08 12:44:54 +01:00
lib.deno_web.d.ts fix(dts): make globals available on globalThis (#19438) 2023-07-03 14:36:55 -04:00
lib.rs Reland "fix(cli): don't store blob and data urls in the module cache" (#18581) 2023-07-02 00:52:30 +02:00
message_port.rs chore: use rustfmt imports_granularity option (#17421) 2023-01-14 23:18:58 -05:00
README.md Rename extensions/ directory to ext/ (#11643) 2021-08-11 12:27:05 +02:00
timers.rs chore: fix typos (#19572) 2023-06-26 09:10:27 -04:00

deno web

Op crate that implements Event, TextEncoder, TextDecoder and File API (https://w3c.github.io/FileAPI).

Testing for text encoding is done via WPT in cli/.