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

Versions 32 to 318

Compare

+123 −0 in 1 place
new file, 123 lines
1+// Time and memory of a local project's commands (abso init --local) on a small and a large history:
2+//
3+// node scripts/local-measure.ts [versions ...] (default: 20 1000)
4+//
5+// Each history is built in this process through the client's main(); then every command is run as its own
6+// `node client/abso.ts` process, the way a person or an agent runs it, five times. It prints the median and slowest
7+// wall time, and the largest peak memory (maxRSS) of those runs, with the store's size on disk.
8+
9+import { spawnSync } from "node:child_process";
10+import { mkdtempSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
11+import { tmpdir } from "node:os";
12+import { join, resolve } from "node:path";
13+import { fileURLToPath, pathToFileURL } from "node:url";
14+import { main } from "../client/src/main.ts";
16+const ROOT = resolve(fileURLToPath(new URL("..", import.meta.url)));
17+const ENTRY = join(ROOT, "client", "abso.ts");
18+const FILES = 40;
19+const RUNS = 5;
21+const sizes = process.argv.slice(2).map(Number);
22+const histories = sizes.length > 0 ? sizes : [20, 1000];
24+function sizeOf(dir: string): number {
25+ let total = 0;
26+ for (const name of readdirSync(dir)) {
27+ const path = join(dir, name);
28+ const s = statSync(path);
29+ total += s.isDirectory() ? sizeOf(path) : s.size;
30+ }
31+ return total;
32+}
34+const lines = (file: number, version: number) =>
35+ Array.from({ length: 30 }, (_, i) =>
36+ i === version % 30 ? `line ${i} of file ${file}, version ${version}` : `line ${i} of file ${file}`,
37+ )
38+ .join("\n")
39+ .concat("\n");
41+async function build(versions: number): Promise<{ store: string; alice: string; bob: string }> {
42+ const store = mkdtempSync(join(tmpdir(), "abso-measure-store-"));
43+ const alice = mkdtempSync(join(tmpdir(), "abso-measure-alice-"));
44+ const bob = mkdtempSync(join(tmpdir(), "abso-measure-bob-"));
45+ const env = { ABSO_STORE: store, ABSO_SERVERS_FILE: "no-servers.json" };
46+ const run = async (cwd: string, ...argv: string[]) => {
47+ const r = await main(argv, { cwd, env, write: () => {} });
48+ if (r.exit !== 0) throw new Error(`${argv.join(" ")}: ${r.stdout}${r.stderr}`);
49+ };
50+ for (let f = 0; f < FILES; f++) writeFileSync(join(alice, `f${f}.txt`), lines(f, 0));
51+ await run(alice, "init", "--local", "--project", "measure", "--agent", "alice", "--as-is");
52+ for (let v = 1; v < versions; v++) {
53+ // Each version changes three files, as a small piece of work does.
54+ for (const f of [v % FILES, (v * 7) % FILES, (v * 13) % FILES])
55+ writeFileSync(join(alice, `f${f}.txt`), lines(f, v));
56+ await run(alice, "push", "-m", `Version ${v}`);
57+ }
58+ await run(bob, "join", "measure", "--local", "--agent", "bob", "--dir", bob);
59+ return { store, alice, bob };
60+}
62+function measure(cwd: string, store: string, argv: string[]): { median: number; slowest: number; rss: number } {
63+ const times: number[] = [];
64+ let rss = 0;
65+ const preload = join(tmpdir(), `abso-measure-rss-${process.pid}.mjs`);
66+ const out = join(tmpdir(), `abso-measure-rss-${process.pid}.json`);
67+ writeFileSync(
68+ preload,
69+ `import { writeFileSync } from "node:fs";\nprocess.on("exit", () => writeFileSync(${JSON.stringify(out)}, String(process.resourceUsage().maxRSS)));\n`,
70+ );
71+ for (let i = 0; i < RUNS; i++) {
72+ const started = performance.now();
73+ const r = spawnSync(process.execPath, ["--import", pathToFileURL(preload).href, ENTRY, ...argv], {
74+ cwd,
75+ env: { ...process.env, ABSO_STORE: store, ABSO_SERVERS_FILE: "no-servers.json" },
76+ encoding: "utf8",
77+ });
78+ times.push(performance.now() - started);
79+ if (r.status !== 0 && argv[0] !== "push") throw new Error(`${argv.join(" ")}: ${r.stdout}${r.stderr}`);
80+ rss = Math.max(
81+ rss,
82+ Number(
83+ spawnSync(
84+ process.execPath,
85+ ["-e", `process.stdout.write(require("fs").readFileSync(${JSON.stringify(out)}, "utf8"))`],
86+ { encoding: "utf8" },
87+ ).stdout,
88+ ),
89+ );
90+ }
91+ times.sort((a, b) => a - b);
92+ return { median: times[Math.floor(RUNS / 2)]!, slowest: times[RUNS - 1]!, rss };
93+}
95+const kb = (n: number) => `${(n / 1024).toFixed(0)} MB`;
96+const ms = (n: number) => `${n.toFixed(0)} ms`;
97+console.log(
98+ `Node ${process.versions.node}, ${FILES} files of 30 lines, three files changed per version, ${RUNS} runs each.`,
99+);
100+console.log("history | command | median | slowest | peak memory");
101+for (const versions of histories) {
102+ const started = performance.now();
103+ const { store, alice, bob } = await build(versions);
104+ const built = performance.now() - started;
105+ const steps: [string, string, string[]][] = [
106+ ["status", alice, ["status"]],
107+ ["log", alice, ["log"]],
108+ ["blame", alice, ["blame", "f0.txt"]],
109+ ["pull (no change)", bob, ["pull"]],
110+ ["record + push", alice, ["push", "-m", "One more"]],
111+ ];
112+ for (const [name, cwd, argv] of steps) {
113+ if (argv[0] === "push") writeFileSync(join(cwd, "f1.txt"), lines(1, versions + Math.random()));
114+ const m = measure(cwd, store, argv);
115+ console.log(
116+ `${String(versions).padStart(5)} v | ${name.padEnd(20)} | ${ms(m.median).padStart(8)} | ${ms(m.slowest).padStart(8)} | ${kb(m.rss)}`,
117+ );
118+ }
119+ console.log(
120+ `${String(versions).padStart(5)} v | store on disk ${(sizeOf(store) / 1048576).toFixed(1)} MB, built in-process in ${(built / 1000).toFixed(1)} s`,
121+ );
122+ for (const d of [store, alice, bob]) rmSync(d, { recursive: true, force: true, maxRetries: 5 });
123+}
MCP
compare on this site's /mcp
CLI
abso diff 32 318 scripts/local-measure.ts --json
JSON
/christopher/abso-core/compare/32..318?file=scripts%2Flocal-measure.ts&format=json