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
show on this site's /mcp
CLI
abso show 228 --json
JSON
/christopher/abso-core/versions/228?format=json

Lamport numbers 256 to a row, and movers read once per graph (disk-first 2; abso Capacity).

of shared·capacity··Not checked

After 226, where on typescript-rs still read about 12,000 lamport rows (one per atom, for ordering a file's lines) and the movers list (1,024 rows, one per atom that moves lines) nine times over.

  • A stored graph keeps its atoms' lamport numbers in pages of 256 (lamport-pages), from a fresh graph on. A graph that already keeps them a row each goes on doing so. The choice is made when a number is first needed, so opening still reads nothing.
  • A stored graph reads its movers once and keeps them, checked against the stored list's length and last mover on each use so a rolled-back add can't leave one behind.

On typescript-rs adopted fresh, cold: where 59,000 reads to 39,000. Its time locally is now mostly work, not reads (5.2 s). 26 of 27 answers match replay; collisions still runs past 60 s.

New test lamport-pages: a fresh graph keeps pages and reopens with them; a graph with a row each reads them and writes the next atom as a row. Named tests: every engine test (288 of 288), membership-pages, stored-closure, draft-reads-stored, version-files, packed-crossings, project-writer-storage, writer-adoption, moves, view-cache (36 of 36); tsc and biome clean.

Version 227 · Files at version 228

2 files, 82 lines added, 8 removed.

--- a/src/engine/graph.ts
+++ b/src/engine/graph.ts
@@ -273,6 +273,18 @@
273273 readonly #childCounts?: ChildCounts;
274274 #atoms: Atom[] = [];
275275 #lamport: number[] = [];
276+ /**
277+ * A stored graph's lamport numbers, 256 to a row (abso Capacity). A graph that already has them a row each (#lamport)
278+ * keeps that; the choice is made when first needed, so opening reads nothing.
279+ */
280+ #lamportPaged: ReturnType<typeof storedNumbers> | undefined;
281+ #lamportPagesKnown: ReturnType<typeof storedNumbers> | null | undefined;
282+ get #lamportPages(): ReturnType<typeof storedNumbers> | null {
283+ if (this.#lamportPagesKnown === undefined)
284+ this.#lamportPagesKnown =
285+ this.#lamportPaged && this.#storage!.read("lamport:meta", "length") === undefined ? this.#lamportPaged : null;
286+ return this.#lamportPagesKnown;
287+ }
276288 // Lines, packed (#46): line n is the k-th line atom seq wrote, n = #lineBase[seq] + k. Each holds its
277289 // atom's seq, the file it was written in (an index into #paths) and its parent (a line's n, or -1 - a
278290 // path's index for a file's start). Its text stays in the atom. Ids and LineInfo objects are made only
@@ -547,6 +559,7 @@
547559 },
548560 );
549561 this.#lamport = storedArray(storage, "lamport");
562+ this.#lamportPaged = storedNumbers(storage, "lamport-pages");
550563 this.#lineBase = storedArray(storage, "line-base");
551564 this.#paths = storedArray(storage, "paths");
552565 this.#movers = storedArray(storage, "movers");
@@ -793,6 +806,8 @@
793806 #relocatedToCode: StateMap<number, RelocationInfo[]> = new Map();
794807 #relocatedToCodePages: ReturnType<typeof storedLists<RelocationInfo>> | undefined;
795808 #movers: AtomId[] = [];
809+ /** A stored graph's movers, read once (abso Capacity): every view walks them, a row each. */
810+ #moverList: AtomId[] | undefined;
796811 #atomFiles: (readonly string[])[] = [];
797812 /** Each atom's deleted lines by n, packed (#46), or undefined when it deletes none. */
798813 #atomDeletes: (readonly number[] | Int32Array | undefined)[] = [];
@@ -830,7 +845,7 @@
830845 /** lamport(a) = 1 + max lamport of its deps; 0 for an atom with no deps (such as a0). */
831846 lamport(id: AtomId): number {
832847 if (!this.has(id)) throw new EngineError("unknown-atom", `no atom ${id}`);
833− return this.#lamport[this.#seq(id)]!;
848+ return this.#lamportAt(this.#seq(id));
834849 }
835850
836851 /** Compare by priority (lamport, then seq). Negative when a comes first (is lower). */
@@ -969,8 +984,12 @@
969984 return atomId(seq);
970985 }
971986
987+ #lamportAt(seq: number): number {
988+ return this.#lamportPages ? this.#lamportPages.at(seq) : this.#lamport[seq]!;
989+ }
972991 lamportOfSeq(seq: number): number {
973− return this.#lamport[seq]!;
992+ return this.#lamportAt(seq);
974993 }
975994
976995 /** The file line n was written in. */
@@ -1256,7 +1275,13 @@
12561275
12571276 /** Atoms that move lines, in seq order. */
12581277 movers(): readonly AtomId[] {
1259− return this.#movers;
1278+ if (!this.#storage) return this.#movers;
1279+ // Checked against the stored list's length and last mover, so a rolled-back add can't leave one behind.
1280+ const length = this.#movers.length;
1281+ const list = this.#moverList;
1282+ if (list && list.length === length && (length === 0 || list[length - 1] === this.#movers[length - 1])) return list;
1283+ this.#moverList = [...this.#movers];
1284+ return this.#moverList;
12601285 }
12611286
12621287 /** Atoms that list this one directly in their deps. */
@@ -1330,7 +1355,7 @@
13301355 * the search never descends below the target's lamport.
13311356 */
13321357 #reaches(from: Iterable<AtomId>, target: AtomId): boolean {
1333− const floor = this.#lamport[this.#seq(target)]!;
1358+ const floor = this.#lamportAt(this.#seq(target));
13341359 if (this.#storage) {
13351360 return this.withProjectionScratch((scratch) => {
13361361 let length = 0;
@@ -1341,13 +1366,13 @@
13411366 };
13421367 for (const id of from) {
13431368 if (id === target) return true;
1344− if (this.#lamport[this.#seq(id)]! > floor) push(id);
1369+ if (this.#lamportAt(this.#seq(id)) > floor) push(id);
13451370 }
13461371 while (length > 0) {
13471372 const key = String(--length);
13481373 const current = scratch.read("stack", key) as AtomId;
13491374 scratch.remove("stack", key);
1350− if (this.#lamport[this.#seq(current)]! <= floor) continue;
1375+ if (this.#lamportAt(this.#seq(current)) <= floor) continue;
13511376 for (const dependency of this.atom(current).deps) {
13521377 if (dependency === target) return true;
13531378 push(dependency);
@@ -1363,7 +1388,7 @@
13631388 if (cur === target) return true;
13641389 if (seen.has(cur)) continue;
13651390 seen.add(cur);
1366− if (this.#lamport[this.#seq(cur)]! <= floor) continue;
1391+ if (this.#lamportAt(this.#seq(cur)) <= floor) continue;
13671392 for (const d of this.atom(cur).deps) if (!seen.has(d)) stack.push(d);
13681393 }
13691394 return false;
@@ -1507,7 +1532,8 @@
15071532 this.#atoms.push(this.#storage ? atom : frozen);
15081533 let lam = 0;
15091534 for (const d of deps) lam = Math.max(lam, this.lamport(d) + 1);
1510− this.#lamport.push(lam);
1535+ if (this.#lamportPages) this.#lamportPages.push(lam);
1536+ else this.#lamport.push(lam);
15111537
15121538 // The run starts' parents and the deleted lines, as codes, before this atom's own lines exist.
15131539 // The atom as given: with lists kept elsewhere, the frozen one reads them back from the log.
--- /dev/null
+++ b/src/engine/test/lamport-pages.test.ts
@@ -0,0 +1,48 @@
1+// A stored graph's lamport numbers (abso Capacity, Graph.#lamportPages): a fresh graph keeps them 256 to a row, and a
2+// graph that already keeps them a row each goes on doing so. Both answer every atom's lamport as the in-memory graph.
3+
4+import assert from "node:assert/strict";
5+import { test } from "node:test";
6+import { Graph } from "../index.ts";
7+import { storedArray } from "../state-source.ts";
8+import { lines, Repo } from "./helpers.ts";
9+import { SqlState } from "./storage-helper.ts";
11+function history() {
12+ const oracle = Repo.init({ "a.txt": lines("one", "two", "three"), "b.txt": "" });
13+ oracle.edit({ edits: [{ file: "a.txt", old: "two", new: "TWO" }] });
14+ oracle.edit({ move: { file: "a.txt", start: 1, end: 2, to: "b.txt", at: 0 } });
15+ oracle.edit({ edits: [{ file: "a.txt", old: "three", new: "three\nfour" }] });
16+ return oracle;
17+}
19+test("a fresh stored graph keeps lamport numbers in pages and reopens with them", () => {
20+ const oracle = history();
21+ const storage = new SqlState();
22+ const original = new Graph({ storage });
23+ for (const atom of oracle.graph.atoms()) original.add(atom);
24+ assert.equal(storage.read("lamport:meta", "length"), undefined, "no row each");
25+ assert.equal(storage.read("lamport-pages:meta", "length"), oracle.graph.size);
26+ const reopened = new Graph({ storage });
27+ for (const atom of oracle.graph.atoms()) assert.equal(reopened.lamport(atom.id), oracle.graph.lamport(atom.id));
28+ assert.deepEqual([...reopened.movers()], [...oracle.graph.movers()]);
29+});
31+test("a graph that keeps lamport numbers a row each goes on reading and writing rows", () => {
32+ const oracle = history();
33+ const atoms = [...oracle.graph.atoms()];
34+ const storage = new SqlState();
35+ const original = new Graph({ storage });
36+ for (const atom of atoms.slice(0, -1)) original.add(atom);
37+ // As a graph adopted before pages: the same numbers a row each, and no pages.
38+ const rows = storedArray<number>(storage, "lamport");
39+ for (let seq = 0; seq < atoms.length - 1; seq++) rows.push(original.lamportOfSeq(seq));
40+ storage.remove("lamport-pages:meta", "length");
41+ storage.remove("lamport-pages:meta", "format");
42+ const reopened = new Graph({ storage });
43+ for (const atom of atoms.slice(0, -1)) assert.equal(reopened.lamport(atom.id), oracle.graph.lamport(atom.id));
44+ reopened.add(atoms.at(-1)!);
45+ assert.equal(storage.read("lamport:meta", "length"), atoms.length, "the new atom gets a row");
46+ assert.equal(reopened.lamport(atoms.at(-1)!.id), oracle.graph.lamport(atoms.at(-1)!.id));
47+ assert.equal(storage.read("lamport-pages:meta", "length"), undefined);
48+});