Repository navigation
Accept any user-timing detail and use measure()'s end mark without a start - #8769
Conversation
The User Timing spec types `detail` in `PerformanceMarkOptions` and `PerformanceMeasureOptions` as `any`, but workerd took it as an object, so `performance.mark('a', { detail: null })`, a number or a string threw a TypeError.
In this patch `mark()`, `measure()` and the `PerformanceMark` constructor keep any value as `detail`. An undefined or missing `detail` still reads back as null. The two WPT subtests that check this finish from a PerformanceObserver callback, and `observe()` is a no-op, so they are disabled instead of expected to fail.
There was a problem hiding this comment.
Superseded by the review of
696b1cc4.
This review, of dae3f7c4
💬 Approved with comments — The change is correct and tested. One WARNING: the measure() end-mark fix changes results for existing Workers, and the commits don't say whether a compatibility flag is needed or the risk is accepted.
Findings: 1 warning (1 is an inline comment on the diff)
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
🔧 Fix with your agent
Paste the following into your coding agent to investigate and fix these issues.
Fix the following code review issues found in pull request #8769.
Before making changes, review each issue and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification
- If you disagree (e.g., the fix would require disproportionate changes
for minimal ROI, or the finding is factually incorrect), explain why
- If you need to clarify something before deciding, ask those questions
- Then share your plan for which issues to tackle and in what order
## WARNING (1)
### [Code Quality] `measure()` now returns a different duration for existing calls that pass an end mark without a start, and no compatibility flag or accepted-risk note is recorded.
- **File:** src/workerd/api/performance.c++:278
📋 Code Quality: ⚠️ 1 warning
One compatibility note on the measure() end-mark change
Recommendation: 📝 Minor Comments
- [WARNING]
measure()now returns a different duration for existing calls that pass an end mark without a start, and no compatibility flag or accepted-risk note is recorded. (src/workerd/api/performance.c++:278)
View full review
The detail type change and the findMarkTime refactor are correct, and the new tests cover both behaviours.
The measure() change alters what existing Workers observe. Today, performance.measure(name, undefined, endMark) and measure(name, {}, endMark) measure from 0 to now, and with this change they measure from 0 to the end mark. That matches the spec. However, the repository's backward-compatibility rules ask for the decision to be recorded in the commit message: either gate the change behind a compatibility flag or state that the risk is accepted.
✅ All other checks passed
🔒 Security: ✅ LGTM
No security issues. detail is only stored and handed back through getHandle(js), and it is traced for GC.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md updates needed.
⚡ Performance: ✅ LGTM
No performance issues. findMarkTime avoids allocating the filtered arrays that getEntriesByName built.
📝 Documentation: ✅ LGTM
No documentation issues.
Reviewed commit: dae3f7c4
`performance.measure('a', undefined, 'end')` ignored the end mark and measured from 0 to now, because the end mark was only read when the start was a mark name.
In this patch the end mark is also used when the start is missing or an options object without `start`, `end` or `duration`. A mark that does not exist still falls back to the default time, and an options object with those fields keeps today's behaviour.
This changes the duration of measures that pass an end mark without a start, without a compatibility flag. We accept the risk: the old result ignored an argument the caller passed, the new one is what the spec and browsers return, and no call that works today starts throwing.
dae3f7c to
696b1cc
Compare
There was a problem hiding this comment.
💬 Approved with comments — The change is correct and tested. One WARNING: the measure() end-mark fix changes results for existing Workers, and the commits don't say whether a compatibility flag is needed or the risk is accepted.
Findings: 1 warning
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
🔧 Fix with your agent
Paste the following into your coding agent to investigate and fix these issues.
Fix the following code review issues found in pull request #8769.
Before making changes, review each issue and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification
- If you disagree (e.g., the fix would require disproportionate changes
for minimal ROI, or the finding is factually incorrect), explain why
- If you need to clarify something before deciding, ask those questions
- Then share your plan for which issues to tackle and in what order
## WARNING (1)
### [Code Quality] `measure()` now returns a different duration for existing calls that pass an end mark without a start, and no compatibility flag or accepted-risk note is recorded.
- **File:** src/workerd/api/performance.c++:278
📋 Code Quality: ⚠️ 1 warning
One compatibility note on the measure() end-mark change
Recommendation: 📝 Minor Comments
- [WARNING]
measure()now returns a different duration for existing calls that pass an end mark without a start, and no compatibility flag or accepted-risk note is recorded. (src/workerd/api/performance.c++:278)
View full review
The detail type change and the findMarkTime refactor are correct, and the new tests cover both behaviours.
The measure() change alters what existing Workers observe. Today, performance.measure(name, undefined, endMark) and measure(name, {}, endMark) measure from 0 to now, and with this change they measure from 0 to the end mark. That matches the spec. However, the repository's backward-compatibility rules ask for the decision to be recorded in the commit message: either gate the change behind a compatibility flag or state that the risk is accepted.
✅ All other checks passed
🔒 Security: ✅ LGTM
No security issues. detail is only stored and handed back through getHandle(js), and it is traced for GC.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md updates needed.
⚡ Performance: ✅ LGTM
No performance issues. findMarkTime avoids allocating the filtered arrays that getEntriesByName built.
📝 Documentation: ✅ LGTM
No documentation issues.
Reviewed commit: 696b1cc4 — same changes as dae3f7c4, so this is that commit's review (no new review was run; line numbers are as of dae3f7c4)
The User Timing spec types
detailasany, but workerd took it as an object, soperformance.mark('a', { detail: null }), or a number or stringdetail, threw a TypeError.performance.measure('a', undefined, 'end')also ignored the end mark and measured from 0 to now, because the end mark was only read when the start was a mark name.In this patch
mark(),measure()and thePerformanceMarkconstructor keep any value asdetail, and an undefineddetailstill reads back as null.measure()also uses the end mark when the start is missing or an options object withoutstart,endorduration. A mark that doesn't exist still falls back to the default time, and options with those fields behave as before, so no call that works today starts throwing.The
measure()change gives a different duration for measures that pass an end mark without a start, and it has no compatibility flag. We accept that risk: the old result ignored an argument the caller passed, and the new one is what the spec and browsers return.The measure-l3 WPT subtest now passes. The mark-l3 and measure-with-dict subtests that check
detailfinish from a PerformanceObserver callback, andobserve()is a no-op, so they are now disabled instead of expected to fail. New tests inperf-hooks-nodejs-test.jscover both changes.//src/wpt:user-timing@,//src/wpt:user-timing@all-autogates,//src/workerd/api/node/tests:perf-hooks-nodejs-test@and//src/workerd/api/node/tests:perf-hooks-nodejs-test@all-compat-flagseach passed 100 of 100 runs with--runs_per_test=100.