Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
perf_hooks: make nodeTiming a first-class object
Render all properties configurable
(@addaleax review)

#35977
  • Loading branch information
mmomtchev committed Nov 6, 2020
commit 166f6b3b4c47933b13ac5fea8d49c1bcc5a3d922
26 changes: 15 additions & 11 deletions lib/perf_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,78 +165,82 @@ function getMilestoneTimestamp(milestoneIdx) {
return ns / 1e6 - timeOrigin;
}

const PerformanceNodeTimingProps = {
enumerable: true,
configurable: true
};
class PerformanceNodeTiming extends PerformanceEntry {
constructor() {
super();

ObjectDefineProperties(this, {
name: {
enumerable: true,
...PerformanceNodeTimingProps,
value: 'node'
},
Comment thread
addaleax marked this conversation as resolved.

entryType: {
enumerable: true,
...PerformanceNodeTimingProps,
value: 'node'
},

startTime: {
enumerable: true,
...PerformanceNodeTimingProps,
value: 0
},

duration: {
enumerable: true,
...PerformanceNodeTimingProps,
get() {
return now() - timeOrigin;
}
},

nodeStart: {
enumerable: true,
...PerformanceNodeTimingProps,
get() {
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_NODE_START);
}
},

v8Start: {
enumerable: true,
...PerformanceNodeTimingProps,
get() {
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_V8_START);
}
},

environment: {
enumerable: true,
...PerformanceNodeTimingProps,
get() {
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_ENVIRONMENT);
}
},

loopStart: {
enumerable: true,
...PerformanceNodeTimingProps,
get() {
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_LOOP_START);
}
},

loopExit: {
enumerable: true,
...PerformanceNodeTimingProps,
get() {
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_LOOP_EXIT);
}
},

bootstrapComplete: {
enumerable: true,
...PerformanceNodeTimingProps,
get() {
return getMilestoneTimestamp(
NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE);
}
},

idleTime: {
enumerable: true,
...PerformanceNodeTimingProps,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: I would just include the properties directly here (rather than use the repeated `...PerformanceNodeTimingProps) even if they're going to be duplicated just to save an unnecessary performance cost.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, do you think V8 keeps a reference to the initializing object when using the spread operator?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is ECMA specified in fact

get() {
return loopIdleTime();
}
Expand Down