PERF-95: coalescing, concurrency-bounded node-position saves#131
Merged
Conversation
… parallel D1 writes) persistAllPositions (fired when the sim settles after a reflow) looped every moved node and called saveNodePosition in parallel — a large-graph reflow produced N simultaneous mutations, i.e. N parallel D1 writes (write-amplification spike). Now those writes go through a queue that (a) coalesces repeated writes per node (last position wins) and (b) drains with a hard cap of 4 in-flight writes, so a 500-node reflow does at most 4 writes at a time. Drag-end saves route through the same queue so a drag during a reflow doesn't add another parallel write. - New pure lib/positionSaveQueue.ts (5 unit tests): drainWithLimit (never exceeds the concurrency limit, runs every item) + createPositionSaveQueue (coalesce last-write-wins; cap in-flight; saves queued mid-flush aren't lost). - Queue bound to the latest saveNodePosition via a ref (created once). Verified: positionSaveQueue 5/5; web typecheck clean; THE GATE 5/5 incl. the layout-persistence test (an arranged node still survives a reload through the queue). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
🧪 Comprehensive Test Suite
Full-stack smoke gate runs in the CI workflow. |
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.
Closes the last backlog item. A reflow that moved N nodes fired N parallel position mutations (D1 write spike). Routed them through a coalescing (last-write-wins) queue that drains with a hard cap of 4 in-flight writes; drag-end saves share the queue. New pure
lib/positionSaveQueue.ts(5 tests). Verified: unit 5/5, typecheck clean, THE GATE 5/5 incl. layout-persistence.🤖 Generated with Claude Code