perf(player): coalesce _mirrorParentMediaTime writes#396
perf(player): coalesce _mirrorParentMediaTime writes#396vanceingalls wants to merge 2 commits intoperf/p1-2-scope-media-mutation-observerfrom
Conversation
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
jrusso1020
left a comment
There was a problem hiding this comment.
Right design. Two-sample gate absorbs single-tick jitter (bridge interval, GC pause, throttled rAF) without thrashing currentTime, and the force: true escape hatch preserves zero-tolerance semantics at ownership promotion and proxy initialization — the two moments where a misaligned audible sample would be perceptually unacceptable.
Counter-reset-on-threshold-recovery is the critical invariant and it's exercised directly (a sample coming back within threshold clears the counter, so a later spike can't piggy-back on stale state). Similarly, out-of-range samples zero the counter — a proxy dropping out of its active window and returning later starts fresh.
The integration test (_promoteToParentProxy invokes _mirrorParentMediaTime with force: true) is the kind of call-site pin I'd want on a subtle perf contract like this: without it, a future refactor could remove { force: true } from the promotion path and every test still passes even though ownership flips would audibly drift.
Worth-calling-out-but-not-blocking: MIRROR_REQUIRED_CONSECUTIVE_DRIFT_SAMPLES = 2 is a constant — if bridge cadence ever changes (the comment cites bridgeMaxPostIntervalMs: 80, so worst-case correction latency is ~160ms), 2 may need to be re-tuned. Consider a doc-comment cross-reference so whoever touches the bridge cadence sees the coupling.
Approved.
— Rames Jusso
Require two consecutive readings above MIRROR_DRIFT_THRESHOLD_SECONDS before writing back to el.currentTime, eliminating seek thrash from transient jitter on the parent timeline. Each _parentMedia entry gains a driftSamples counter; promoteToParentProxy and _onIframeMediaAdded pass force:true to keep one-shot alignments immediate. Adds 11 unit/integration tests covering jitter, trending drift, force override, out-of-range proxies, multi-proxy independence, and _promoteToParentProxy alignment.
7600cd7 to
62e91f3
Compare
Per reviewer feedback on #396: surface the coupling between the mirror-loop's required-consecutive-drift-samples constant and the timeline-control bridge's max post interval, in both directions, so a future change to either side immediately points at the other. The coupling is: worst_case_correction_latency_ms ≈ MIRROR_REQUIRED_CONSECUTIVE_DRIFT_SAMPLES × bridgeMaxPostIntervalMs At today's values (2 × 80 ms = 160 ms) this stays under the perceptual A/V re-sync tolerance. Doc-only change — no behavior delta.

Summary
Coalesce writes to
el.currentTimeinside_mirrorParentMediaTimeso a single jitter sample no longer triggers a parent-media seek. A drift correction now requires two consecutive samples above the threshold (~MIRROR_DRIFT_THRESHOLD_SECONDS) before the player writes back. One-shot alignment paths (promoteToParentProxy,_onIframeMediaAdded) opt out viaforce: trueso initial alignment stays immediate.Why
Step
P1-4of the player perf proposal._mirrorParentMediaTimeis called every animation frame on parent media proxies. Even without true drift, browser internals report tiny jitter oncurrentTimereads — typically below 30 ms but occasionally crossing the threshold for a frame. Writing tocurrentTimetriggers a seek, which is expensive and invalidates pipeline buffers, which causes the next frame's reading to jitter further. The result was unnecessary seek thrash on otherwise-aligned media.By requiring two consecutive over-threshold samples, transient jitter is filtered out while real drift (a sustained offset) still corrects within ~1 frame of latency. This eliminates the most common cause of dropped frames on the studio thumbnail grid.
What changed
_parentMediaentry gains adriftSamplescounter that increments while the absolute drift is aboveMIRROR_DRIFT_THRESHOLD_SECONDSand resets to 0 on the first sample below._mirrorParentMediaTime(el, opts)only writes back whendriftSamples >= 2, except whenopts.force === true.promoteToParentProxyand_onIframeMediaAddedpassforce: trueso the first alignment after registration is still immediate (these are user-visible state transitions, not steady-state telemetry).Test plan
hyperframes-player.test.tscovering:force: trueoverride bypasses the sample requirement._promoteToParentProxyalignment is immediate.Stack
Step
P1-4of the player perf proposal. Builds onP1-1(shared adopted stylesheets) andP1-2(scoped media observer). Together these three target the studio multi-player render path —P0-1*perf gate scenarios will pick up the wins automatically.