1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

perf(ext/event): always set timeStamp to 0 (#20191)

```js
Deno.bench(function eventNew() {
  new Event("foo");
});
```

<b>main</b>
```
./target/release/deno bench event_bench.js
cpu: Apple M1 Max
runtime: deno 1.36.1 (aarch64-apple-darwin)

file:///Users/ib/dev/deno/event_bench.js
benchmark      time (avg)        iter/s             (min … max)       p75       p99      p995
--------------------------------------------------------------- -----------------------------
eventNew       36.43 ns/iter  27,451,874.9   (35.15 ns … 46.98 ns)  37.68 ns   40.7 ns  41.69 ns

```

<b>this PR</b>
```
./target/release/deno bench event_bench.js
cpu: Apple M1 Max
runtime: deno 1.36.1 (aarch64-apple-darwin)

file:///Users/ib/dev/deno/event_bench.js
benchmark      time (avg)        iter/s             (min … max)       p75       p99      p995
--------------------------------------------------------------- -----------------------------
eventNew       13.71 ns/iter  72,958,970.0   (12.85 ns … 31.79 ns)  15.11 ns  16.49 ns   17.5 ns

```

Towards #20167
This commit is contained in:
Bartek Iwańczuk 2023-08-20 12:02:47 +02:00 committed by GitHub
parent 7847de0974
commit 32bbba3db2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 1 additions and 23 deletions

View file

@ -21,7 +21,6 @@ const {
ArrayPrototypeSplice,
ArrayPrototypeUnshift,
Boolean,
DateNow,
Error,
FunctionPrototypeCall,
MapPrototypeGet,
@ -123,8 +122,6 @@ const _inPassiveListener = Symbol("[[inPassiveListener]]");
const _dispatched = Symbol("[[dispatched]]");
const _isTrusted = Symbol("[[isTrusted]]");
const _path = Symbol("[[path]]");
// internal.
const _skipInternalInit = Symbol("[[skipSlowInit]]");
class Event {
constructor(type, eventInitDict = {}) {
@ -138,21 +135,6 @@ class Event {
this[_isTrusted] = false;
this[_path] = [];
if (eventInitDict?.[_skipInternalInit]) {
this[_attributes] = {
type,
data: eventInitDict.data ?? null,
bubbles: eventInitDict.bubbles ?? false,
cancelable: eventInitDict.cancelable ?? false,
composed: eventInitDict.composed ?? false,
currentTarget: null,
eventPhase: Event.NONE,
target: null,
timeStamp: 0,
};
return;
}
webidl.requiredArguments(
arguments.length,
1,
@ -172,7 +154,7 @@ class Event {
currentTarget: null,
eventPhase: Event.NONE,
target: null,
timeStamp: DateNow(),
timeStamp: 0,
};
}
@ -1205,7 +1187,6 @@ class MessageEvent extends Event {
bubbles: eventInitDict?.bubbles ?? false,
cancelable: eventInitDict?.cancelable ?? false,
composed: eventInitDict?.composed ?? false,
[_skipInternalInit]: eventInitDict?.[_skipInternalInit],
});
this.data = eventInitDict?.data ?? null;
@ -1494,7 +1475,6 @@ function reportError(error) {
}
export {
_skipInternalInit,
CloseEvent,
CustomEvent,
defineEventHandler,

View file

@ -9,7 +9,6 @@ import * as webidl from "ext:deno_webidl/00_webidl.js";
import { HTTP_TOKEN_CODE_POINT_RE } from "ext:deno_web/00_infra.js";
import DOMException from "ext:deno_web/01_dom_exception.js";
import {
_skipInternalInit,
CloseEvent,
defineEventHandler,
dispatch,
@ -450,7 +449,6 @@ class WebSocket extends EventTarget {
const event = new MessageEvent("message", {
data,
origin: this[_url],
[_skipInternalInit]: true,
});
setIsTrusted(event, true);
dispatch(this, event);