Skip to content

perf(runtime): commit runtime database writes in a pipelined persist fiber - #78

Merged
kyscott18 merged 1 commit into
mainfrom
perf/persist-fiber
Oct 26, 2026
Merged

kyscott18 merged 1 commit into
mainfrom
perf/persist-fiber

Conversation

@kyscott18

@kyscott18 kyscott18 commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

Supersedes #61.

Summary

Accepted batches, force-included mutations, and inclusion updates were committed inline, mostly under the speculative-state lock, so execution, submit, and watch waited on Postgres. One persist fiber now does every runtime database write.

  • Group commit. The fiber takes everything that queued during the previous commit and writes it in one transaction. The batch loop never waits on Postgres, so batch N+1 executes while batch N commits.
  • Ordering. Inserts are queued under the lock right after executing, so they commit in execution order. Restart resumes after the highest committed execution index without checking for gaps, so a later insert must not land before an earlier one.
  • execute fails fast on a rejection. An accepted mutation's caller then waits, outside any lock, for its own batch's commit.
  • submit executes force-included mutations and queues their insert under the lock, then simulates. After the lock it waits for the commits of exactly the batches and force-included mutations it settles, then broadcasts. Nothing settles onchain before it is committed.
  • The inclusion update is not awaited. Nothing reads it, and the rows it updates are already committed.
  • Failure. A failed commit fails the persist fiber, which stops the program, and waiting callers get TypewriterStoppedError.

🤖 Generated with Claude Code

…fiber

Accepted batches, force-included mutations, and inclusion updates were
committed inline, mostly under the speculative-state lock, so execution,
submit, and watch waited on Postgres. One persist fiber now commits every
runtime write. It groups everything that queued during the previous
commit into one transaction, so batch N+1 executes while batch N commits.

Inserts are queued under the lock right after executing, so they commit
in execution order. Restart resumes after the highest committed execution
index, so a later insert must not land before an earlier one.

Callers of execute get a response only after their batch commits. Submit
waits for the commits of the batches and force-included mutations it
settles, outside the lock, before it broadcasts. The inclusion update is
not awaited: nothing reads it, and the rows it updates are already
committed. A failed commit stops the program, which fails waiting callers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kyscott18
kyscott18 merged commit 67a1548 into main Oct 26, 2026
7 checks passed
@kyscott18
kyscott18 deleted the perf/persist-fiber branch October 26, 2026 20:20
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