1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -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 Divy Srivastava
parent 627499177f
commit 698776f137
2 changed files with 1 additions and 23 deletions

View file

@ -21,7 +21,6 @@ const {
ArrayPrototypeSplice, ArrayPrototypeSplice,
ArrayPrototypeUnshift, ArrayPrototypeUnshift,
Boolean, Boolean,
DateNow,
Error, Error,
FunctionPrototypeCall, FunctionPrototypeCall,
MapPrototypeGet, MapPrototypeGet,
@ -123,8 +122,6 @@ const _inPassiveListener = Symbol("[[inPassiveListener]]");
const _dispatched = Symbol("[[dispatched]]"); const _dispatched = Symbol("[[dispatched]]");
const _isTrusted = Symbol("[[isTrusted]]"); const _isTrusted = Symbol("[[isTrusted]]");
const _path = Symbol("[[path]]"); const _path = Symbol("[[path]]");
// internal.
const _skipInternalInit = Symbol("[[skipSlowInit]]");
class Event { class Event {
constructor(type, eventInitDict = {}) { constructor(type, eventInitDict = {}) {
@ -138,21 +135,6 @@ class Event {
this[_isTrusted] = false; this[_isTrusted] = false;
this[_path] = []; 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( webidl.requiredArguments(
arguments.length, arguments.length,
1, 1,
@ -172,7 +154,7 @@ class Event {
currentTarget: null, currentTarget: null,
eventPhase: Event.NONE, eventPhase: Event.NONE,
target: null, target: null,
timeStamp: DateNow(), timeStamp: 0,
}; };
} }
@ -1205,7 +1187,6 @@ class MessageEvent extends Event {
bubbles: eventInitDict?.bubbles ?? false, bubbles: eventInitDict?.bubbles ?? false,
cancelable: eventInitDict?.cancelable ?? false, cancelable: eventInitDict?.cancelable ?? false,
composed: eventInitDict?.composed ?? false, composed: eventInitDict?.composed ?? false,
[_skipInternalInit]: eventInitDict?.[_skipInternalInit],
}); });
this.data = eventInitDict?.data ?? null; this.data = eventInitDict?.data ?? null;
@ -1494,7 +1475,6 @@ function reportError(error) {
} }
export { export {
_skipInternalInit,
CloseEvent, CloseEvent,
CustomEvent, CustomEvent,
defineEventHandler, 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 { HTTP_TOKEN_CODE_POINT_RE } from "ext:deno_web/00_infra.js";
import DOMException from "ext:deno_web/01_dom_exception.js"; import DOMException from "ext:deno_web/01_dom_exception.js";
import { import {
_skipInternalInit,
CloseEvent, CloseEvent,
defineEventHandler, defineEventHandler,
dispatch, dispatch,
@ -450,7 +449,6 @@ class WebSocket extends EventTarget {
const event = new MessageEvent("message", { const event = new MessageEvent("message", {
data, data,
origin: this[_url], origin: this[_url],
[_skipInternalInit]: true,
}); });
setIsTrusted(event, true); setIsTrusted(event, true);
dispatch(this, event); dispatch(this, event);