perf(cli): cut wasted waits from the check browser gate - #2908
Open
xiayewang-heygen wants to merge 1 commit into
Open
perf(cli): cut wasted waits from the check browser gate#2908xiayewang-heygen wants to merge 1 commit into
xiayewang-heygen wants to merge 1 commit into
Conversation
Three independent costs in `hyperframes check`, none of which changed what the gate detects: 1. Motion-only grid times took the full audit settle. AUDIT_SEEK_OPTIONS pays an unconditional 120ms paint-flush sleep plus a glyph-subset font wait on every seek, but a time that only feeds collectMotionFrame needs neither — __hyperframesMotionSample reads computed transforms and opacity, which the ordered double-rAF already guarantees are committed. At 20fps the motion grid is up to 300 samples, so this sleep dominated any run carrying an index.motion.json. Times that measure text (layout), photograph the frame (contrast) or read caption/frame geometry keep the full settle. 2. `waitForCompositionSettle` slept a flat 1500ms on every page open, after __renderReady, shader pre-render and document.fonts.ready had all already resolved. Replaced with a poll that holds a 400ms floor, then exits on the first pair of consecutive frames with no font subset in flight, capped at the original 1500ms — worst case unchanged, common case ~1s faster. 3. `collectContrast` always took a second full-page screenshot to build the annotated overview, then the pipeline discarded it unless --snapshots was set. The bare `collectContrast(time)` call shape already meant "no snapshots", so that now skips the shot and its overlay entirely. collectGridSamples' per-time layout and contrast blocks are extracted to keep it under the complexity gate after the seek-profile branch. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Why
hyperframes checkp95 is ~37s in prod (p50 ~10s, min ~8s). This removes three waits that cost time without changing what the gate detects. No detection logic, thresholds, or sample counts change.What
1. Motion-only grid times skip the paint-flush settle
AUDIT_SEEK_OPTIONSpays an unconditionalsettleMs: 120sleep plus a glyph-subset font wait on every seek. A grid time that only feedscollectMotionFrameneeds neither —__hyperframesMotionSamplereads computed transforms and opacity, which the ordered double-rAF already guarantees are committed. The sleep exists to flush paint, which only matters before a screenshot.New
MOTION_SAMPLE_SEEK_OPTIONSkeeps the double-rAF and drops the rest. Times that measure text (layout), photograph the frame (contrast), or read caption/frame geometry keep the full settle. The dense content_overlap pass already does the same thing viaDENSE_GEOMETRY_SEEK_OPTIONS.At
MOTION_FPS = 20/MOTION_MAX_SAMPLES = 300, this is the dominant cost of any run carrying anindex.motion.json— a 10s composition is ~201 seeks × ~170ms ≈ 34s, of which ~120ms/seek was this sleep.2. Adaptive post-ready settle
waitForCompositionSettleslept a flat 1500ms on every page open — after__renderReady, shader pre-render, anddocument.fonts.readyhad all resolved. Replaced with a poll that holds a 400ms floor, then exits on the first pair of consecutive frames with no font subset in flight, capped at the original 1500ms.Worst case is unchanged. The floor is deliberate: work that lands after
__renderReadybut signals nothing observable (image decode, late layout) still gets a margin.3. Skip the discarded contrast overview screenshot
collectContrastalways took a second full-page screenshot to build the annotated overview, and the pipeline then discarded it unless--snapshotswas set. The barecollectContrast(time)call shape already meant "no snapshots", so that path now skips the shot and its overlay entirely.Scope note
Fix 1 is a no-op for Zephyr, which generates only
index.htmland no motion sidecar — so its motion grid never runs. It benefits callers that do ship a motion spec. Fixes 2 and 3 apply to every check.Per @xuanru, the larger Zephyr-specific wins are caller-side in
experiment-framework, not here:_build_check_argsnever passes--no-contrast, yetDROP_ERROR_SECTIONS = ("contrast",)throws the whole contrast section away. The CLI flag already exists — the contrast pass is currently pure waste for Zephyr.HYPERFRAMES_CHECK_MAX_CONCURRENCYis unset in prod, so the per-pod Chrome semaphore falls back to the CPU request.Testing
check.test.ts: motion-only times route toseekMotion; layout/contrast times keepseekoxlint/oxfmtclean;fallow auditclean on all 5 changed filesRisk
Fix 2 touches every
openSettledCompositionPagecaller (check, snapshot, compare, validate), not just check — it's the one worth a careful look. It can only return earlier than before, never later, and the 400ms floor plus the two-stable-frame requirement are the guardrails. If a composition turns out to need the full 1500ms, raisingCAPTURE_SETTLE_FLOOR_MSrestores the old behavior.Savings figures above are derived from the code paths and the measured 8s floor, not from a before/after benchmark — the check has no per-phase instrumentation today.
launch_settle_ms/seek_loop_ms/contrast_msare already emitted on thecheck_reporttelemetry event but not surfaced in Datadog; wiring those up would let us verify this directly.🤖 Generated with Claude Code