Skip to content

PERF-95: coalescing, concurrency-bounded node-position saves#131

Merged
mvalancy merged 1 commit into
devfrom
perf/position-save-queue
Jun 19, 2026
Merged

PERF-95: coalescing, concurrency-bounded node-position saves#131
mvalancy merged 1 commit into
devfrom
perf/position-save-queue

Conversation

@mvalancy

Copy link
Copy Markdown
Member

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

… 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>
@mvalancy mvalancy merged commit 14172a1 into dev Jun 19, 2026
@mvalancy mvalancy deleted the perf/position-save-queue branch June 19, 2026 02:39
@github-actions

Copy link
Copy Markdown

🧪 Comprehensive Test Suite

  • Unit suites (Node 18.x & 20.x) — core, web, server, mcp-server: ✅ passed
  • Installer & deploy config: ✅ passed

Full-stack smoke gate runs in the CI workflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant