Repository navigation
[profiler] Wait for cytoscape to draw before the pixel tests read the canvas - #7840
Conversation
… canvas `settle()` waited a fixed 150 ms, but cytoscape draws on animation frames. On a busy CI runner a frame can come later, and the pixel probes in diagramShadows and diagramText read the previous frame. `settle()` now also waits until a frame passes without a cytoscape `render` event. Fixes #7767 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| // Cytoscape requests its frame callback during the previous frame, so its callback runs before | ||
| // this one. Cytoscape emits `render` after each draw, so a frame without `render` had no draw | ||
| // pending. | ||
| let hasDrawn = false | ||
| const onRender = () => { | ||
| hasDrawn = true | ||
| } | ||
| mountedCy.on('render', onRender) | ||
| do { | ||
| hasDrawn = false | ||
| await nextFrame() | ||
| } while (hasDrawn) | ||
| mountedCy.off('render', onRender) |
There was a problem hiding this comment.
bug (medium): a frame with no render does not mean no draw is pending. Cytoscape's texture caches dequeue in beforeRenderCallbacks on frames that do not draw. They then request the redraw through a lodash debounce set to deqRedrawThreshold, which is 50–100 ms (setupDequeueing in cytoscape 3.33.1). The LayeredTextureCache works the same way.
I tested this. A probe stayed inside settle() for 400 ms after the loop exited and counted render events. I also delayed animation frames by a random 0–400 ms, the same way your PR testing did.
- Idle machine: no late draws in the pixel tests.
- Late frames: in ~20 of ~70 settles per run, cytoscape drew again after the "quiet" frame. This included
node text > draws the text itself…andthe selection glow > paints nothing…. Wrappingrenderer().redrawshowed the callers weretrailingEdge(debounce) →LayeredTextureCache, plus someBRp.notify.
The tests still passed, so these redraws seem to be mostly texture refinement. Still, the comment states something that is not true, and the probes can still read a frame that is about to change. One fix is to also require a quiet stretch longer than the debounce:
let last = performance.now()
const onRender = () => { last = performance.now() }
mountedCy.on('render', onRender)
// A frame with no draw is not enough: the texture caches ask for their redraw
// from a 50-100 ms debounce, so also wait out that delay.
let frames = 0
do {
frames++
await nextFrame()
} while (frames < 2 || performance.now() - last < 150)
mountedCy.off('render', onRender)Also consider try/finally around the off, and resetting mountedCy in cleanup, so a later settle() does not wait on a removed instance.
There was a problem hiding this comment.
Agreed, fixed in 0f12d9c. I traced the late draws to the same chain: element texture refinement, then scheduleElementRefinement (50 ms), then the LayeredTextureCache dequeue and its redraw debounce (50 ms).
I did not use the suggested condition (150 ms since the last render). With late frames it can still exit too early: if the last draw was 400 ms ago and the next frame starts a refinement, the loop exits and the debounced redraw comes after. A refinement step only advances in a frame, so the condition counts frames:
settle()returns after 3 frames without a draw, each at least 120 ms after the one before (longer than the longest debounce).offis infinally, andcleanup()resetsmountedCy.
|
Review of the test-harness-only fix for #7767
The other gates (docs, deps, breaking changes, unsafe, CI) don't apply to a test-only change. |
|
Addressed the review in 0f12d9c:
Cost: the browser suite takes about 28 s instead of 20 s locally, because each |
0f12d9c to
a721263
Compare
Fixes #7767.
Cause
settle()inmountDiagram.tswaited a fixed 150 ms. Cytoscape draws on animation frames, so on a busy CI runner a frame can come later and the pixel probes read the previous frame.Fix
settle()waits 150 ms, then waits on animation frames until one frame passes without a cytoscaperenderevent (public API). Cytoscape requests its frame callback during the previous frame, so its callback runs first in each frame.mountDiagramrecords the new instance before its firstsettle(). Only the test harness changed.Testing
A temporary
test/setup.tschange delayed whole animation frames by a random 0-400 ms and kept the callback order: