Skip to content

perf(engine): repositories write side by side - #287

Merged
sweepies merged 3 commits into
mainfrom
perf/parallel-writes
Nov 13, 2026
Merged

sweepies merged 3 commits into
mainfrom
perf/parallel-writes

Conversation

@sweepies

@sweepies sweepies commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Consult 7, PR 9. A batch wrote its repositories one after another, so each repository's lockfile tools and reads waited for every earlier repository's paced writes.

  • Write::repository returns its branch and pull request actions (Written) instead of pushing them onto shared state; Write is a shared context. run_at drives repositories through buffer_unordered(concurrency), re-sorts the results by repository (the order lookup_work_at produced) and merges the actions in that order, so the report is byte-identical.
  • One batch-wide semaphore of lockfile_concurrency() (cores, at most 4) on the Runner replaces the per-repository limit; lock_all loses its concurrency argument.
  • Writes stay one in flight at a time, paced by the shared governor.

State audit: sent sets, stats, timings and report rows were already per repository; the notes client and spinner are mutex-guarded; receipts and the cache are repository-scoped. Clone directories, the tool store, cache partitions and per-tool serial locks in crates/tools are flock-guarded, so tool runs may overlap: two Bun runs still serialize on their own lock, Bun and npm overlap.

Behaviour on a run-aborting error (a cache failure, an invalid maintenance plan): sequentially, repositories before the failing one were written and those after it never started. Now every repository runs to the end, so none is dropped half-written (a published branch without its pull request), and the run fails with the first error in repository order. Otherwise no behaviour change: the report is identical apart from stats, which measure the run.

Proof: repositories_write_side_by_side_with_an_identical_report writes three repositories (Bun, npm with npmEngine = "npm", and one with no lockfile work) both ways. Tool windows overlap side by side and not in sequence, paced writes interleave across all three, and the two complete reports serialize byte-identically. Transcripts and depth pins are unchanged.

Benchmark: on that fixture, where tool time and latency are virtual so only real work counts, the write phase took 234 ms in sequence and 172 ms side by side (medians of 5). With real tool runs the gain grows with min(repositories, lockfile_concurrency()); Fable's estimate for ten repositories with 20 s of tool time each is 200 s → about 50 s.

View guided diff Turn on auto-fix

sweepies and others added 3 commits November 12, 2026 23:51
Each repository's write ran one after another through a shared &mut Write
that collected its branch and pull-request actions, so a run's reads,
lockfile tool time and paced writes never overlapped.

Write::repository now borrows the shared context and hands back its
repository's actions; run_at drives the repositories through
buffer_unordered and merges their actions in the same sorted repository
order a sequential pass produced, so the report is byte-identical. The
shared client keeps write pacing one mutation in flight per client, the
lockfile runner carries one semaphore of lockfile_concurrency() across
the whole run instead of a per-repository cap inside lock_all, and every
piece of state a repository touched is either repository-local and merged
in order or already shared safely (the governor, the notes client, the
spinner). Receipts and the cache stay repository-scoped, and lockfile
tool state — unique run directories, flock-guarded clone, store and cache
partitions, per-bin serial locks — overlaps safely across repositories.

Proof: repositories_write_side_by_side_with_an_identical_report writes
three repositories with overlapping bun and npm lockfile generations,
asserts the tool windows and the governor-paced writes interleave, and
compares the whole report byte-for-byte against the sequential run.
transcripts.tsv gains only the new test's line. The tools Overlap test
parametrizes its barrier so it passes where lockfile_concurrency() < 3.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Dropping a repository mid-write could leave a published branch without
its pull request. Every repository runs to the end, and the run fails
with the first error in repository order, so the error does not depend
on timing.
@sweepies
sweepies force-pushed the perf/parallel-writes branch from 3f8ab15 to 83d2beb Compare November 12, 2026 23:56
@sweepies
sweepies merged commit 01687ed into main Nov 13, 2026
12 checks passed
@sweepies
sweepies deleted the perf/parallel-writes branch November 13, 2026 00:03
@sweepies-ops sweepies-ops Bot mentioned this pull request Nov 13, 2026
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