Skip to content

Use a per-board save queue instead of a process-wide one - #391

Open
lovasoa wants to merge 1 commit into
masterfrom
ophir.lojkine/per-board-save-queue
Open

Use a per-board save queue instead of a process-wide one#391
lovasoa wants to merge 1 commit into
masterfrom
ophir.lojkine/per-board-save-queue

Conversation

@lovasoa

@lovasoa lovasoa commented May 28, 2026

Copy link
Copy Markdown
Owner

Use a per-board save queue instead of a process-wide one

saveBoard ran every board's save through a single global SerialTaskQueue, so a slow rewrite on one board blocked unrelated boards from persisting and delayed shutdown saves. Each board only ever writes its own files, so the lane only needs to be per board.

The queue now lives on each BoardData instance (data.mjs), so it is GC'd with the board (no global Map to clean up). saveBoard now uses board.saveQueue. File writes stay safe because the queue still serializes each board's own writes, and no two boards share a file.

Proof

The test blocks board A mid-save and shows board B completes anyway, then shows two saves of the same board stay serialized:

const firstSave = firstBoard.save();   // blocked on a gate
const secondSave = secondBoard.save();
assert.deepEqual(await secondSave, { status: "saved" });
assert.deepEqual(calls, ["first:start", "second:start", "second:end"]);
// same-board: second save starts only after the first ends
assert.deepEqual(calls, ["a:start", "a:end", "b:start"]);
$ npm run test-node
tests 311 / pass 311 / fail 0
$ npm run lint
Checked 202 files in 49ms. No fixes applied.
$ npm run typecheck   # tsc, no output = clean

Each board writes only its own files, so serializing saves process-wide
made a slow rewrite on one board block unrelated boards. Move the
SerialTaskQueue onto each BoardData instance so the concurrency lane is
per board (and GC'd with the board).
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