Skip to content

fix(perf_hooks): make Performance.measure() second and third params optional#6092

Merged
anonrig merged 4 commits intomainfrom
fix-performance-measure-optional-params
Feb 18, 2026
Merged

fix(perf_hooks): make Performance.measure() second and third params optional#6092
anonrig merged 4 commits intomainfrom
fix-performance-measure-optional-params

Conversation

@petebacondarwin
Copy link
Copy Markdown
Contributor

Summary

This PR aligns the Performance.measure() API with the Web Performance API specification and Node.js behavior by:

  • Making the second parameter (measureOptionsOrStartMark) optional so measure(name) works
  • Fixing the detail property to default to null instead of a synthetic {start, end} object

Changes

1. Optional Parameters

The measure() method now supports being called with just a name:

performance.measure('my-measure');  // Now works!

When called with only a name, it measures from timeOrigin (0) to the current time.

2. Detail Property Fix

Per the MDN spec and Node.js implementation, detail should be null when not explicitly provided.

Before: detail was set to {start: <startTime>, end: <endTime>} even when not requested
After: detail is null unless explicitly provided via options

Breaking Change Note

The change to detail defaulting to null is technically a breaking change for code that relied on the synthetic detail object. However, this aligns with the web standard and Node.js behavior.

Testing

  • Added new test testPerformanceMeasureNameOnly for single-parameter usage
  • Updated existing tests to verify detail is null when not provided
  • Updated JSON serialization test to expect no detail property when not provided

…ptional

This change aligns the Performance.measure() API with the Web Performance
API specification and Node.js behavior:

1. Make measureOptionsOrStartMark parameter optional (was required)
   - Calling measure(name) now works and measures from timeOrigin (0) to now
   - Previously this would fail due to the required second parameter

2. Fix detail property to default to null instead of synthetic object
   - Per MDN and Node.js, detail should be null when not explicitly provided
   - Previously we were creating a synthetic {start, end} object
   - This is technically a breaking change but aligns with the standard

References:
- MDN: https://developer.mozilla.org/en-US/docs/Web/API/Performance/measure
- Node.js: https://github.com/nodejs/node/blob/main/lib/internal/perf/usertiming.js
@petebacondarwin petebacondarwin requested review from a team as code owners February 17, 2026 18:07
@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 17, 2026

The generated output of @cloudflare/workers-types matches the snapshot in types/generated-snapshot 🎉

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.77778% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.54%. Comparing base (5361a73) to head (05f842f).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
src/workerd/api/performance.c++ 77.77% 0 Missing and 8 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6092      +/-   ##
==========================================
- Coverage   70.56%   70.54%   -0.02%     
==========================================
  Files         409      409              
  Lines      108957   108955       -2     
  Branches    18010    18013       +3     
==========================================
- Hits        76883    76866      -17     
- Misses      21269    21287      +18     
+ Partials    10805    10802       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@anonrig anonrig merged commit 7980c22 into main Feb 18, 2026
22 checks passed
@anonrig anonrig deleted the fix-performance-measure-optional-params branch February 18, 2026 00:10
logan-gatlin pushed a commit to logan-gatlin/workerd that referenced this pull request Feb 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants