{"version":232,"agent":"capacity","message":"Line ids and writers from the packed layout, and a sequence's text read only when used (disk-first 2; abso Capacity).\n\nCollisions on typescript-rs spent about 21 s in the definition rule's #replacedNames. It asks the base view for a file's whole sequence, then walks back from one line through a few. View.sequence read every line's text, deleted lines included, one row each on a stored graph (about 35,000 line-text reads). lines() and sequence() also looked up each line's id and writer again, two more reads per line.\n\n- The packed layout keeps each line's writer and place in it (visWriter, visK, and seqWriter and seqK for a complete layout). lines(), buildLines() and sequence() build ids and writers from them.\n- sequence() reads each line's text when it is first asked for.\n\nOn typescript-rs adopted fresh, cold: collisions 70 s to 46 s; where about 3 s. All 27 answers match replay. Run alone, why is about 0.95 s.\n\nNamed tests: every engine test (288 of 288), changed-definition, collision-streaming, definitions, draft-reads-stored, authors-stored, packed-crossings, view-cache, files-reads, project, trail, history, moves (82 of 82); tsc and biome clean.","time":1792056629629,"timeIso":"2026-10-15T09:30:29.629Z","changes":1,"change":3664,"files":["src/engine/view.ts"],"draft":null,"diff":[{"path":"src/engine/view.ts","added":37,"removed":9,"diff":"--- a/src/engine/view.ts\n+++ b/src/engine/view.ts\n@@ -10,7 +10,7 @@\n // made when a caller asks for them, and the latest asked for is kept.\n \n import type { Graph, RelocationInfo } from \"./graph.ts\";\n-import { isStartNode, seqOf } from \"./keys.ts\";\n+import { isStartNode, lineId, seqOf } from \"./keys.ts\";\n import { resolveScratchMoves, scratchLayoutNodes } from \"./relocation-scratch.ts\";\n import { isClosedSet, StableSet } from \"./state-source.ts\";\n import { joinLines } from \"./text.ts\";\n@@ -71,6 +71,11 @@\n \treadonly visText?: readonly (string | null)[];\n \t/** Its visible lines' writers' seqs, when laid out from the file's packed history. */\n \treadonly visWriter?: Int32Array;\n+\t/** Its visible lines' places in their writers (a line id's k), when laid out from packed history. */\n+\treadonly visK?: Int32Array;\n+\t/** The same for every line of seq, when complete and laid out from packed history. */\n+\treadonly seqWriter?: Int32Array;\n+\treadonly seqK?: Int32Array;\n \t/** Positions by n, built the first time they're asked for. */\n \tseqIndex?: Map<number, number>;\n \tvisIndex?: Map<number, number>;\n@@ -648,6 +653,7 @@\n \t\tconst children = new Map<number, Child[]>();\n \t\tconst texts = new Map<number, string | null>();\n \t\tconst writers = new Map<number, number>();\n+\t\tconst places = new Map<number, number>();\n \t\tconst deleters = new Map<number, number[]>();\n \t\t// Each atom's lamport once per layout: most lines share a few atoms, and a stored graph reads it from a page.\n \t\tconst lamports = new Map<number, number>();\n@@ -677,6 +683,7 @@\n \t\t\t\telse children.set(at, [child]);\n \t\t\t\ttexts.set(n, text);\n \t\t\t\twriters.set(n, seq);\n+\t\t\t\tplaces.set(n, k);\n \t\t\t}\n \t\t\tfor (const [n, deleter] of graph.packedDeletes(file)) {\n \t\t\t\tif (!this.#has(deleter)) continue;\n@@ -694,6 +701,9 @@\n \t\tconst vis: number[] = [];\n \t\tconst visText: (string | null)[] = [];\n \t\tconst visWriter: number[] = [];\n+\t\tconst visK: number[] = [];\n+\t\tconst seqWriter: number[] = [];\n+\t\tconst seqK: number[] = [];\n \t\tconst deletedBy = new Map<number, readonly number[]>();\n \t\tconst stack: number[] = [];\n \t\tconst push = (code: number) => {\n@@ -712,8 +722,13 @@\n \t\t\t\tvis.push(n);\n \t\t\t\tvisText.push(texts.get(n) ?? null);\n \t\t\t\tvisWriter.push(writers.get(n)!);\n+\t\t\t\tvisK.push(places.get(n)!);\n \t\t\t}\n-\t\t\tif (complete) seq.push(n);\n+\t\t\tif (complete) {\n+\t\t\t\tseq.push(n);\n+\t\t\t\tseqWriter.push(writers.get(n)!);\n+\t\t\t\tseqK.push(places.get(n)!);\n+\t\t\t}\n \t\t\tpush(n);\n \t\t}\n \t\treturn {\n@@ -724,6 +739,8 @@\n \t\t\tdeletedBy,\n \t\t\tvisText,\n \t\t\tvisWriter: Int32Array.from(visWriter),\n+\t\t\tvisK: Int32Array.from(visK),\n+\t\t\t...(complete ? { seqWriter: Int32Array.from(seqWriter), seqK: Int32Array.from(seqK) } : {}),\n \t\t};\n \t}\n \n@@ -884,13 +901,13 @@\n \tbuildLines(path: string): readonly VisibleLine[] {\n \t\tconst graph = this.graph;\n \t\t// Texts and writers the packed layout already holds are not read again (abso Capacity).\n-\t\tconst { vis, visText, visWriter } = this.#file(path);\n+\t\tconst { vis, visText, visWriter, visK } = this.#file(path);\n \t\tconst lines: VisibleLine[] = new Array(vis.length);\n \t\tfor (let i = 0; i < vis.length; i++) {\n \t\t\tconst n = vis[i]!;\n \t\t\tconst packed = visText?.[i];\n \t\t\tlines[i] = {\n-\t\t\t\tid: graph.lineIdOf(n),\n+\t\t\t\tid: visWriter && visK ? lineId(graph.idOfSeq(visWriter[i]!), visK[i]!) : graph.lineIdOf(n),\n \t\t\t\ttextChunks: () => graph.textChunks(n),\n \t\t\t\tget text() {\n \t\t\t\t\treturn packed ?? graph.textOf(n);\n@@ -905,12 +922,12 @@\n \tlines(path: string): readonly VisibleLine[] {\n \t\tif (this.#linesCache?.path === path) return this.#linesCache.lines;\n \t\tconst graph = this.graph;\n-\t\tconst { vis, visText, visWriter } = this.#file(path);\n+\t\tconst { vis, visText, visWriter, visK } = this.#file(path);\n \t\tconst lines: VisibleLine[] = new Array(vis.length);\n \t\tfor (let i = 0; i < vis.length; i++) {\n \t\t\tconst n = vis[i]!;\n \t\t\tlines[i] = {\n-\t\t\t\tid: graph.lineIdOf(n),\n+\t\t\t\tid: visWriter && visK ? lineId(graph.idOfSeq(visWriter[i]!), visK[i]!) : graph.lineIdOf(n),\n \t\t\t\ttext: visText?.[i] ?? graph.textOf(n),\n \t\t\t\tatom: graph.idOfSeq(visWriter ? visWriter[i]! : graph.writerSeqOf(n)),\n \t\t\t};\n@@ -925,13 +942,21 @@\n \t\tconst graph = this.graph;\n \t\tconst f = this.#file(path, true);\n \t\tconst out: SeqLine[] = new Array(f.seq.length);\n+\t\t// Ids and writers from the packed layout, and each text read only when asked (abso Capacity): callers walk a few\n+\t\t// lines of a file's history, and reading every line's text was a row each on a stored graph.\n+\t\tconst { seqWriter, seqK } = f;\n \t\tfor (let i = 0; i < f.seq.length; i++) {\n \t\t\tconst n = f.seq[i]!;\n \t\t\tconst by = f.deletedBy.get(i);\n+\t\t\tconst writer = seqWriter ? seqWriter[i]! : graph.writerSeqOf(n);\n+\t\t\tlet text: string | undefined;\n \t\t\tout[i] = {\n-\t\t\t\tid: graph.lineIdOf(n),\n-\t\t\t\ttext: graph.textOf(n),\n-\t\t\t\tatom: graph.idOfSeq(graph.writerSeqOf(n)),\n+\t\t\t\tid: seqWriter && seqK ? lineId(graph.idOfSeq(writer), seqK[i]!) : graph.lineIdOf(n),\n+\t\t\t\tget text() {\n+\t\t\t\t\ttext ??= graph.textOf(n);\n+\t\t\t\t\treturn text;\n+\t\t\t\t},\n+\t\t\t\tatom: graph.idOfSeq(writer),\n \t\t\t\tdeletedBy: by ? by.map((s) => graph.idOfSeq(s)) : NONE,\n \t\t\t\tvisible: by === undefined,\n \t\t\t};\n@@ -1053,6 +1078,9 @@\n \t\t\t\tn += f.seq.byteLength + f.vis.byteLength;\n \t\t\t\tif (f.visText) for (const text of f.visText) n += REFERENCE_BYTES + 2 * (text?.length ?? 0);\n \t\t\t\tif (f.visWriter) n += 4 * f.visWriter.length;\n+\t\t\t\tif (f.visK) n += 4 * f.visK.length;\n+\t\t\t\tif (f.seqWriter) n += 4 * f.seqWriter.length;\n+\t\t\t\tif (f.seqK) n += 4 * f.seqK.length;\n \t\t\t\tn += MAP_HEADER_BYTES + (MAP_ENTRY_BYTES + ARRAY_HEADER_BYTES) * f.deletedBy.size;\n \t\t\t\tfor (const deleters of f.deletedBy.values()) n += REFERENCE_BYTES * deleters.length;\n \t\t\t\tif (f.seqIndex) n += MAP_HEADER_BYTES + MAP_ENTRY_BYTES * f.seqIndex.size;"}],"ci":null}