{"draft":null,"from":227,"to":228,"files":[{"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."}],"unmatched":[]}