Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/Aquaticat/Monochromatic. TypeScript and Rust monorepo: Claude Code and Pi coding-agent plugins, a m
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364/** One measured batch per scenario shape for the concurrent-commit benchmark.
A concurrent batch starts every commit together; its paired serialized batch runs the same commits one after another.
@module */import { appendFile, writeFile,} from 'node:fs/promises';import { join, } from 'node:path';import { type BatchSample, type CommitObservation, FIRST_EDIT_LINE, SECOND_EDIT_LINE,} from './concurrent-commit-latency-contracts.ts';import { startPausedCommit, type StartedCommit, withPausedCommit,} from './concurrent-commit-latency-pause.ts';import { disjointFile, SHARED_FILE, sharedBaselineLines,} from './concurrent-commit-latency-repositories.ts';import { commitArgs, nowMs, observeLocks, runCommit,} from './concurrent-commit-latency-process.ts';
/** One commit to run: its arguments and extra environment. */export type CommitPlan = Readonly<{ /** Wrapper arguments. */ args: readonly string[]; /** Executable when not the packed wrapper. */ command?: string;}>;
/** Runs plans together or one after another while observing the locks.
@example ```ts await runPlans({ repository, plans: [{ args: ['commit', '-m', 'x', '--', 'a.txt'] }], serialized: true }); ```
@param repository - repository path
@param plans - commits to run
@param serialized - whether to run one after another
@returns measured batch */export async function runPlans({ repository, plans, serialized,}: Readonly<{ repository: string; plans: readonly CommitPlan[]; serialized: boolean;}>,): Promise<BatchSample> { /** Lock observer for the batch. */ const observer = await observeLocks(repository,); /** Batch start. */ const startedAt = nowMs(); /** Commits in plan order. */ const commits = serialized ? await plans.reduce<Promise<readonly CommitObservation[]>>( async function runAfter( previous, plan, ) { return [ ...await previous, await runCommit({ repository, ...plan, },), ]; }, Promise.resolve([],), ) : await Promise.all(plans.map(async function runTogether(plan,) { return await runCommit({ repository, ...plan, },); },),); /** Batch wall time. */ const wallMs = nowMs() - startedAt; return { wallMs, commits, ...observer.stop(), };}
/** Runs one disjoint-path batch.
@param repository - repository path
@param concurrency - commits in the batch
@param sequence - unique batch number
@param serialized - whether to run the commits one after another
@param command - executable, for the direct-Git baseline
@returns measured batch
@example ```ts await disjointBatch({ repository, concurrency: 4, sequence: 1, serialized: false }); ``` */export async function disjointBatch({ repository, concurrency, sequence, serialized, command,}: Readonly<{ repository: string; concurrency: number; sequence: number; serialized: boolean; command?: string;}>,): Promise<BatchSample> { /** Commit slots. */ const slots = Array.from( { length: concurrency, }, function slot( _unused, index, ): number { return index; }, ); await Promise.all(slots.map(async function edit(slot,): Promise<void> { await appendFile( join( repository, disjointFile(slot,), ), `batch ${String(sequence,)}\n`, ); },),); return await runPlans({ repository, serialized, plans: slots.map(function plan(slot,): CommitPlan { return { args: commitArgs({ path: disjointFile(slot,), message: `disjoint ${String(sequence,)} ${String(slot,)}`, },), ...(command === undefined ? {} : { command, }), }; },), },);}
/** Writes the shared file with the given lines replaced.
@param repository - repository path
@param edits - line index to text
@returns written text
@example ```ts await writeShared({ repository, edits: { 4: 'first 1' } }); ``` */export async function writeShared({ repository, edits,}: Readonly<{ repository: string; edits: Readonly<Record<number, string>>;}>,): Promise<string> { /** Complete file text. */ const text = `${sharedBaselineLines() .map(function edited( line, index, ): string { return edits[index] ?? line; },) .join('\n',)}\n`; await writeFile( join( repository, SHARED_FILE, ), text, ); return text;}
/** Runs one same-file non-overlapping pair: far-apart lines of one file, the second captured while the first is prepared, both released together.
@param repository - repository path
@param sequence - unique batch number
@param serialized - whether to run the commits one after another
@param markerRoot - directory for phase markers
@returns measured batch
@example ```ts await sameFileBatch({ repository, sequence: 1, serialized: false, markerRoot: '/work/markers' }); ``` */export async function sameFileBatch({ repository, sequence, serialized, markerRoot,}: Readonly<{ repository: string; sequence: number; serialized: boolean; markerRoot: string;}>,): Promise<BatchSample> { /** First edit alone. */ const firstEdits = { [FIRST_EDIT_LINE]: `first ${String(sequence,)}`, }; /** Both edits. */ const bothEdits = { ...firstEdits, [SECOND_EDIT_LINE]: `second ${String(sequence,)}`, }; if (serialized) { await writeShared({ repository, edits: firstEdits, },); /** First commit. */ const first = await runPlans({ repository, serialized, plans: [{ args: commitArgs({ path: SHARED_FILE, message: `first ${String(sequence,)}`, },), },], },); await writeShared({ repository, edits: bothEdits, },); /** Second commit. */ const second = await runPlans({ repository, serialized, plans: [{ args: commitArgs({ path: SHARED_FILE, message: `second ${String(sequence,)}`, },), },], },); return { wallMs: first.wallMs + second.wallMs, commits: [ ...first.commits, ...second.commits, ], landingLockHoldMs: [ ...first.landingLockHoldMs, ...second.landingLockHoldMs, ], indexLockHoldMs: [ ...first.indexLockHoldMs, ...second.indexLockHoldMs, ], }; } await writeShared({ repository, edits: firstEdits, },); /** Lock observer for the batch. */ const observer = await observeLocks(repository,); /** Batch start. */ const startedAt = nowMs(); /** Both commits. */ const commits = await withPausedCommit({ repository, markerDirectory: join( markerRoot, `same-file-${String(sequence,)}`, ), path: SHARED_FILE, message: `first ${String(sequence,)}`, whilePaused: async function startSecond(): Promise<StartedCommit> { await writeShared({ repository, edits: bothEdits, },); // Pausing the second commit too makes both prepared before either lands, so one replays. return await startPausedCommit({ repository, markerDirectory: join( markerRoot, `same-file-${String(sequence,)}-second`, ), path: SHARED_FILE, message: `second ${String(sequence,)}`, },); }, },); return { wallMs: nowMs() - startedAt, commits, ...observer.stop(), };}