Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed
MCP
code on this site's /mcp
CLI
none: the JSON below is the answer
JSON
/christopher/abso-core/files/worker/project/test/bench.ts?format=json
72 linesFirst import 99% · pinch 1%Last change pinch in version 78, 2 versions changed it
1// Times the project's calls on a project of a given size, in this process
2// (no network, no storage). Run: node worker/project/test/bench.ts [files] [lines] [defs|body]
3// "defs" (the default) makes every line a definition, the worst case for the
4// changed-definition rule; "body" makes them plain statements.
5
6import { type Entry, MemoryStore, Project } from "../project.ts";
7
8const fileCount = Number(process.argv[2] ?? 100);
9const linesPer = Number(process.argv[3] ?? 200);
10const kind = process.argv[4] === "body" ? "body" : "defs";
11const lineOf = (f: number, i: number, extra = ""): string =>
12 kind === "defs" ? `const v${f}_${i} = ${i}${extra};` : ` total${f} += ${i}${extra};`;
13const agents = ["a", "b", "c", "d", "e"];
14const rounds = 40;
16const files: Record<string, string> = {};
17for (let f = 0; f < fileCount; f++) {
18 files[`src/f${f}.ts`] = `${Array.from({ length: linesPer }, (_, i) => lineOf(f, i)).join("\n")}\n`;
21const store = new MemoryStore();
22const project = new Project(store);
23let t = performance.now();
24project.init(files, 0);
25const initMs = performance.now() - t;
26for (const a of agents) project.sync(a);
28const times: Record<string, number[]> = { edit: [], publish: [], sync: [], record: [] };
29const time = (name: string, fn: () => void): void => {
30 const t0 = performance.now();
31 fn();
32 times[name]!.push(performance.now() - t0);
33};
35let n = 0;
36let outOfStep = 0;
37for (let r = 0; r < rounds; r++) {
38 for (const [i, a] of agents.entries()) {
39 const f = (r * agents.length + i) % fileCount;
40 const line = (r * 7) % linesPer;
41 n++;
42 time("edit", () => {
43 const answer = project.edit(
44 a,
45 { file: `src/f${f}.ts`, old: lineOf(f, line), new: lineOf(f, line, ` + ${n}`) },
46 n,
47 );
48 if (!answer.ok) outOfStep++;
49 });
50 }
51 for (const a of agents) time("publish", () => project.publish(a, `round ${r}`, n));
52 for (const a of agents) time("sync", () => project.sync(a));
55const stats = (xs: number[]): string => {
56 const s = [...xs].sort((p, q) => p - q);
57 return `median ${s[Math.floor(s.length / 2)]!.toFixed(1)} ms, p90 ${s[Math.floor(s.length * 0.9)]!.toFixed(1)} ms, max ${s[s.length - 1]!.toFixed(1)} ms (${s.length})`;
58};
60t = performance.now();
61const again = Project.load(store.entries as Entry[], new MemoryStore());
62const loadMs = performance.now() - t;
63again.status();
65console.log(
66 `${fileCount} files x ${linesPer} lines = ${fileCount * linesPer} lines (${kind}), ${agents.length} agents, ${rounds} rounds`,
67);
68console.log(`edits out of step: ${outOfStep}`);
69console.log(
70 `init ${initMs.toFixed(0)} ms; reload of ${store.entries.length} entries ${loadMs.toFixed(0)} ms; log ${(JSON.stringify(store.entries).length / 1e6).toFixed(1)} MB`,
71);
72for (const [name, xs] of Object.entries(times)) if (xs.length) console.log(`${name}: ${stats(xs)}`);