Performance: keep the time origin per environment - #240
Open
matthargett wants to merge 2 commits into
Open
matthargett wants to merge 2 commits into
matthargett wants to merge 2 commits into
Conversation
performance.now() measured from one process-wide start time that every Initialize() rewrote. With Workers each runtime initializes the polyfill on its own thread, so ThreadSanitizer reports the write race, and every new worker also moved the main realm's clock backwards. Capture the origin per environment in the now() closure, as each realm has its own time origin on the web, and use steady_clock, which cannot step. (cherry picked from commit 2391b0d)
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The implementation resolves the timing isolation issue; the remaining regression-test request is a minor, non-blocking enhancement.
Pull request overview
Updates performance.now() to maintain an independent, monotonic time origin for each runtime environment.
Changes:
- Replaces process-wide timing state with per-environment closure state.
- Uses
std::chrono::steady_clockfor elapsed-time measurement.
File summaries
| File | Summary |
|---|---|
Polyfills/Performance/Source/Performance.cpp |
Implements per-environment monotonic timing. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Two runtimes: after the second initializes the polyfill, the first one's performance.now() must not go backwards. Fails against the process-wide origin (the second Initialize reset it to zero).
Author
|
Regression test added in 5c6cd00 (fails against the previous implementation: after 0.02 ms vs before 55 ms). Fork twin rebeckerspecialties#25 at that head: 24/24 green — https://github.com/rebeckerspecialties/JsRuntimeHost/actions/runs/34841426895 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
performance.now()measured from a single process-wide start time that everyPerformance::Initializerewrote. Any host that runs more than oneAppRuntime(a second runtime, or a worker) therefore moves the first realm's clock backwards on each initialization, and with concurrent runtimes the write is a data race (ThreadSanitizer reports it once workers exist).Each realm has its own time origin on the web, so capture it per environment in the
now()closure, and measure withsteady_clock, which cannot step.Verified on macOS (JavaScriptCore): full
UnitTestsgreen. Fork twin: rebeckerspecialties#25.