fix(js): keep the performance time origin out of the future - #673
Open
aech wants to merge 1 commit into
Open
Conversation
The origin carried a two-sided jitter of [-50, +49] ms, so about half of all navigations placed it ahead of the wall clock. performance.now() computes Date.now() - timeOrigin and went negative for up to 50 ms, and so did the requestAnimationFrame timestamp, IntersectionObserverEntry.time, performance.timing.navigationStart and document.timeline.currentTime. Skew into the past only. The spread stays 100 ms, so the plausible deviation the jitter was added for is preserved. Headless Chromium places its origin 68 to 147 ms in the past and never ahead of the clock. The test builds a fresh runtime per draw because __obscura_init deletes itself after running, so one realm only ever yields a single draw of the jitter. Fixes h4ckf0r0day#672
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.
What changed
Fixes #672.
performance.timeOrigincarried a two-sided jitter of[-50, +49]ms, so about half of all navigations placed it ahead of the wall clock.performance.now()computesDate.now() - timeOriginand went negative for up to 50 ms after every such navigation, and four derived surfaces went with it: therequestAnimationFrametimestamp,IntersectionObserverEntry.time,performance.timing.navigationStartanddocument.timeline.currentTime.The jitter now skews into the past only:
The spread stays 100 ms, so the plausible deviation the jitter was added for in #218 is preserved. Headless Chromium 151 places its origin 68 to 147 ms in the past over six runs and never ahead of the clock, so the one-sided form is also the more faithful one.
The test builds a fresh runtime per draw.
__obscura_initdeletes itself at the end of its own run, so one realm only ever yields a single draw of the jitter, and a loop over one runtime silently samples the same value forty times.Validation
New test
time_origin_never_lands_in_the_futurefails before the change withperformance.timeOrigin is 40 ms ahead of Date.now()and passes after it. Over 40 draws theunpatched build placed 20 origins in the future, so the test does not depend on luck.
Behavioral check on the production path, ten runs each:
Before: 5 of 10 runs returned a negative
performance.now(). After: 0 of 10.Re-tested with
--stealthon a--features render,stealthbinary, twelve runs, no origin in the future.Rendering
Not applicable.
Performance
No expected impact. The change swaps one two-sided arithmetic expression for a one-sided one with the same operation count, executed once per navigation inside__obscura_init, outside any hot path.Observed alongside: obstacle course median latency 3027.9 ms before and 3025.7 ms after, one run of 33 stages each. That is a smoke check, not an interleaved measurement, and it only shows there is no gross regression.
Checklist