fix(Graph): auto-park physics loop when layout settles (0.5.15)#319
Merged
Conversation
The force-directed Graph's requestAnimationFrame loop ran forever — every frame re-ran the O(n²) force step AND re-reconciled the whole SVG, for the life of the page, even after the layout had visibly stopped moving. Three graphs mounted on one page (the landing fan-out) cold-start their sims on a single scroll frame and then never idle, which is what makes scrolling into that section lag. It now parks itself once every revealed, unpinned node falls below a sub-pixel velocity threshold and nothing is driving motion, and re-arms within a frame on drag, replay/reseed, or resize (a parked loop keeps an empty rAF scheduled, so there's no missed-wake risk). An idle graph costs no per-frame work. No API change; the settle look, BFS reveal (replays on replay()), and node dragging are all unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
|
Storybook Preview: https://mirrorstack-ai.github.io/web-ui-kit/pr/319/ |
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
The force-directed
Graph'srequestAnimationFrameloop ran forever — every frame re-ran the O(n²) force step and re-reconciled the whole SVG (every<line>/<circle>/<text>), for the life of the page, with no settle/convergence cutoff (damping only multiplies velocity by 0.85, never zeroes it). Mount several graphs on one page and they all churn the main thread indefinitely; cold-starting three of them on a single scroll frame is what makes scrolling into a multi-graph section lag.This adds a
settledpark: the loop skips the step + re-render once every revealed, unpinned node is below a sub-pixel velocity threshold (SETTLE_V2, ≈0.05 px/frame) and nothing is driving motion. It re-arms within one frame from each motion source —rebuildSim(mount/reseed/replay),ResizeObserver,startReveal, and nodepointerdown. A parked loop keeps an emptyrAFscheduled rather than cancelling, so there's no missed-wake risk at ~0 idle cost.The settle check runs after
step(), so a just-released node (velocity 0 at release, force applied that frame) keeps the loop awake until it actually comes to rest — nothing freezes mid-air.Intent preserved (no API change)
The live force-directed settle look, the BFS reveal (still replays on
replay()), and node dragging are all unchanged.meta.descriptionnow documents the auto-pause so consumers aren't surprised.Versioning
Patch bump 0.5.14 → 0.5.15 + CHANGELOG entry, in this PR (
releaselabel).Considered & deferred (not in this PR)
autoStopprop /pausedcontrol — an opt-out for a consumer that wants a perpetually-jittering ambient graph. Default-on is what every current consumer wants; can add on request.revealed-set-write). The current wake sites are covered in practice (pointerdown precedes drag-move; therevealTimerguard holds the loop awake through playback), so this is hardening, not a fix.Verification
tscbuild clean; validated live on the landing fan-out (three graphs) — graphs still settle into clusters, reveal replays on scroll, drag works, and idle graphs stop churning.🤖 Generated with Claude Code