{"version":228,"agent":"capacity","message":"Lamport numbers 256 to a row, and movers read once per graph (disk-first 2; abso Capacity).\n\nAfter 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.\n\n- 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.\n- 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.\n\nOn 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.\n\nNew 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.","time":1792053568830,"timeIso":"2026-10-15T08:39:28.830Z","changes":2,"change":3643,"files":["src/engine/graph.ts","src/engine/test/lamport-pages.test.ts"],"draft":null,"diff":[{"path":"src/engine/graph.ts","added":34,"removed":8,"diff":"--- a/src/engine/graph.ts\n+++ b/src/engine/graph.ts\n@@ -273,6 +273,18 @@\n \treadonly #childCounts?: ChildCounts;\n \t#atoms: Atom[] = [];\n \t#lamport: number[] = [];\n+\t/**\n+\t * A stored graph's lamport numbers, 256 to a row (abso Capacity). A graph that already has them a row each (#lamport)\n+\t * keeps that; the choice is made when first needed, so opening reads nothing.\n+\t */\n+\t#lamportPaged: ReturnType<typeof storedNumbers> | undefined;\n+\t#lamportPagesKnown: ReturnType<typeof storedNumbers> | null | undefined;\n+\tget #lamportPages(): ReturnType<typeof storedNumbers> | null {\n+\t\tif (this.#lamportPagesKnown === undefined)\n+\t\t\tthis.#lamportPagesKnown =\n+\t\t\t\tthis.#lamportPaged && this.#storage!.read(\"lamport:meta\", \"length\") === undefined ? this.#lamportPaged : null;\n+\t\treturn this.#lamportPagesKnown;\n+\t}\n \t// Lines, packed (#46): line n is the k-th line atom seq wrote, n = #lineBase[seq] + k. Each holds its\n \t// atom's seq, the file it was written in (an index into #paths) and its parent (a line's n, or -1 - a\n \t// path's index for a file's start). Its text stays in the atom. Ids and LineInfo objects are made only\n@@ -547,6 +559,7 @@\n \t\t\t\t},\n \t\t\t);\n \t\t\tthis.#lamport = storedArray(storage, \"lamport\");\n+\t\t\tthis.#lamportPaged = storedNumbers(storage, \"lamport-pages\");\n \t\t\tthis.#lineBase = storedArray(storage, \"line-base\");\n \t\t\tthis.#paths = storedArray(storage, \"paths\");\n \t\t\tthis.#movers = storedArray(storage, \"movers\");\n@@ -793,6 +806,8 @@\n \t#relocatedToCode: StateMap<number, RelocationInfo[]> = new Map();\n \t#relocatedToCodePages: ReturnType<typeof storedLists<RelocationInfo>> | undefined;\n \t#movers: AtomId[] = [];\n+\t/** A stored graph's movers, read once (abso Capacity): every view walks them, a row each. */\n+\t#moverList: AtomId[] | undefined;\n \t#atomFiles: (readonly string[])[] = [];\n \t/** Each atom's deleted lines by n, packed (#46), or undefined when it deletes none. */\n \t#atomDeletes: (readonly number[] | Int32Array | undefined)[] = [];\n@@ -830,7 +845,7 @@\n \t/** lamport(a) = 1 + max lamport of its deps; 0 for an atom with no deps (such as a0). */\n \tlamport(id: AtomId): number {\n \t\tif (!this.has(id)) throw new EngineError(\"unknown-atom\", `no atom ${id}`);\n-\t\treturn this.#lamport[this.#seq(id)]!;\n+\t\treturn this.#lamportAt(this.#seq(id));\n \t}\n \n \t/** Compare by priority (lamport, then seq). Negative when a comes first (is lower). */\n@@ -969,8 +984,12 @@\n \t\treturn atomId(seq);\n \t}\n \n+\t#lamportAt(seq: number): number {\n+\t\treturn this.#lamportPages ? this.#lamportPages.at(seq) : this.#lamport[seq]!;\n+\t}\n+\n \tlamportOfSeq(seq: number): number {\n-\t\treturn this.#lamport[seq]!;\n+\t\treturn this.#lamportAt(seq);\n \t}\n \n \t/** The file line n was written in. */\n@@ -1256,7 +1275,13 @@\n \n \t/** Atoms that move lines, in seq order. */\n \tmovers(): readonly AtomId[] {\n-\t\treturn this.#movers;\n+\t\tif (!this.#storage) return this.#movers;\n+\t\t// Checked against the stored list's length and last mover, so a rolled-back add can't leave one behind.\n+\t\tconst length = this.#movers.length;\n+\t\tconst list = this.#moverList;\n+\t\tif (list && list.length === length && (length === 0 || list[length - 1] === this.#movers[length - 1])) return list;\n+\t\tthis.#moverList = [...this.#movers];\n+\t\treturn this.#moverList;\n \t}\n \n \t/** Atoms that list this one directly in their deps. */\n@@ -1330,7 +1355,7 @@\n \t * the search never descends below the target's lamport.\n \t */\n \t#reaches(from: Iterable<AtomId>, target: AtomId): boolean {\n-\t\tconst floor = this.#lamport[this.#seq(target)]!;\n+\t\tconst floor = this.#lamportAt(this.#seq(target));\n \t\tif (this.#storage) {\n \t\t\treturn this.withProjectionScratch((scratch) => {\n \t\t\t\tlet length = 0;\n@@ -1341,13 +1366,13 @@\n \t\t\t\t};\n \t\t\t\tfor (const id of from) {\n \t\t\t\t\tif (id === target) return true;\n-\t\t\t\t\tif (this.#lamport[this.#seq(id)]! > floor) push(id);\n+\t\t\t\t\tif (this.#lamportAt(this.#seq(id)) > floor) push(id);\n \t\t\t\t}\n \t\t\t\twhile (length > 0) {\n \t\t\t\t\tconst key = String(--length);\n \t\t\t\t\tconst current = scratch.read(\"stack\", key) as AtomId;\n \t\t\t\t\tscratch.remove(\"stack\", key);\n-\t\t\t\t\tif (this.#lamport[this.#seq(current)]! <= floor) continue;\n+\t\t\t\t\tif (this.#lamportAt(this.#seq(current)) <= floor) continue;\n \t\t\t\t\tfor (const dependency of this.atom(current).deps) {\n \t\t\t\t\t\tif (dependency === target) return true;\n \t\t\t\t\t\tpush(dependency);\n@@ -1363,7 +1388,7 @@\n \t\t\tif (cur === target) return true;\n \t\t\tif (seen.has(cur)) continue;\n \t\t\tseen.add(cur);\n-\t\t\tif (this.#lamport[this.#seq(cur)]! <= floor) continue;\n+\t\t\tif (this.#lamportAt(this.#seq(cur)) <= floor) continue;\n \t\t\tfor (const d of this.atom(cur).deps) if (!seen.has(d)) stack.push(d);\n \t\t}\n \t\treturn false;\n@@ -1507,7 +1532,8 @@\n \t\tthis.#atoms.push(this.#storage ? atom : frozen);\n \t\tlet lam = 0;\n \t\tfor (const d of deps) lam = Math.max(lam, this.lamport(d) + 1);\n-\t\tthis.#lamport.push(lam);\n+\t\tif (this.#lamportPages) this.#lamportPages.push(lam);\n+\t\telse this.#lamport.push(lam);\n \n \t\t// The run starts' parents and the deleted lines, as codes, before this atom's own lines exist.\n \t\t// The atom as given: with lists kept elsewhere, the frozen one reads them back from the log."},{"path":"src/engine/test/lamport-pages.test.ts","added":48,"removed":0,"diff":"--- /dev/null\n+++ b/src/engine/test/lamport-pages.test.ts\n@@ -0,0 +1,48 @@\n+// A stored graph's lamport numbers (abso Capacity, Graph.#lamportPages): a fresh graph keeps them 256 to a row, and a\n+// graph that already keeps them a row each goes on doing so. Both answer every atom's lamport as the in-memory graph.\n+\n+import assert from \"node:assert/strict\";\n+import { test } from \"node:test\";\n+import { Graph } from \"../index.ts\";\n+import { storedArray } from \"../state-source.ts\";\n+import { lines, Repo } from \"./helpers.ts\";\n+import { SqlState } from \"./storage-helper.ts\";\n+\n+function history() {\n+\tconst oracle = Repo.init({ \"a.txt\": lines(\"one\", \"two\", \"three\"), \"b.txt\": \"\" });\n+\toracle.edit({ edits: [{ file: \"a.txt\", old: \"two\", new: \"TWO\" }] });\n+\toracle.edit({ move: { file: \"a.txt\", start: 1, end: 2, to: \"b.txt\", at: 0 } });\n+\toracle.edit({ edits: [{ file: \"a.txt\", old: \"three\", new: \"three\\nfour\" }] });\n+\treturn oracle;\n+}\n+\n+test(\"a fresh stored graph keeps lamport numbers in pages and reopens with them\", () => {\n+\tconst oracle = history();\n+\tconst storage = new SqlState();\n+\tconst original = new Graph({ storage });\n+\tfor (const atom of oracle.graph.atoms()) original.add(atom);\n+\tassert.equal(storage.read(\"lamport:meta\", \"length\"), undefined, \"no row each\");\n+\tassert.equal(storage.read(\"lamport-pages:meta\", \"length\"), oracle.graph.size);\n+\tconst reopened = new Graph({ storage });\n+\tfor (const atom of oracle.graph.atoms()) assert.equal(reopened.lamport(atom.id), oracle.graph.lamport(atom.id));\n+\tassert.deepEqual([...reopened.movers()], [...oracle.graph.movers()]);\n+});\n+\n+test(\"a graph that keeps lamport numbers a row each goes on reading and writing rows\", () => {\n+\tconst oracle = history();\n+\tconst atoms = [...oracle.graph.atoms()];\n+\tconst storage = new SqlState();\n+\tconst original = new Graph({ storage });\n+\tfor (const atom of atoms.slice(0, -1)) original.add(atom);\n+\t// As a graph adopted before pages: the same numbers a row each, and no pages.\n+\tconst rows = storedArray<number>(storage, \"lamport\");\n+\tfor (let seq = 0; seq < atoms.length - 1; seq++) rows.push(original.lamportOfSeq(seq));\n+\tstorage.remove(\"lamport-pages:meta\", \"length\");\n+\tstorage.remove(\"lamport-pages:meta\", \"format\");\n+\tconst reopened = new Graph({ storage });\n+\tfor (const atom of atoms.slice(0, -1)) assert.equal(reopened.lamport(atom.id), oracle.graph.lamport(atom.id));\n+\treopened.add(atoms.at(-1)!);\n+\tassert.equal(storage.read(\"lamport:meta\", \"length\"), atoms.length, \"the new atom gets a row\");\n+\tassert.equal(reopened.lamport(atoms.at(-1)!.id), oracle.graph.lamport(atoms.at(-1)!.id));\n+\tassert.equal(storage.read(\"lamport-pages:meta\", \"length\"), undefined);\n+});"}],"ci":null}