{"draft":null,"from":229,"to":230,"files":[{"path":"src/engine/view.ts","added":34,"removed":9,"diff":"--- a/src/engine/view.ts\n+++ b/src/engine/view.ts\n@@ -69,6 +69,8 @@\n \treadonly deletedBy: ReadonlyMap<number, readonly number[]>;\n \t/** Its visible lines' text, when laid out from the file's packed history: null for a line too long to pack. */\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/** Positions by n, built the first time they're asked for. */\n \tseqIndex?: Map<number, number>;\n \tvisIndex?: Map<number, number>;\n@@ -645,7 +647,18 @@\n \t\tconst files = new Set<number>([-1 - start, ...(this.#movedInFrom().get(path) ?? [])]);\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 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+\t\tconst lamportOf = (seq: number): number => {\n+\t\t\tlet lamport = lamports.get(seq);\n+\t\t\tif (lamport === undefined) {\n+\t\t\t\tlamport = graph.lamportOfSeq(seq);\n+\t\t\t\tlamports.set(seq, lamport);\n+\t\t\t}\n+\t\t\treturn lamport;\n+\t\t};\n \t\tfor (const file of files) {\n \t\t\tconst lineTexts = graph.packedTexts(file);\n \t\t\tfor (const [n, parent, seq, k, replaces] of graph.packedLines(file)) {\n@@ -653,16 +666,17 @@\n \t\t\t\tif (!this.#has(seq)) continue;\n \t\t\t\tconst moved = relocs?.get(n);\n \t\t\t\tlet at = parent;\n-\t\t\t\tlet child: Child = { n, replaces, lamport: graph.lamportOfSeq(seq), seq, k };\n+\t\t\t\tlet child: Child = { n, replaces, lamport: lamportOf(seq), seq, k };\n \t\t\t\tif (moved) {\n \t\t\t\t\tconst mover = graph.atom(moved.r.atom).seq;\n-\t\t\t\t\tchild = { n, replaces: 0, lamport: graph.lamportOfSeq(mover), seq: mover, k: moved.r.k };\n+\t\t\t\t\tchild = { n, replaces: 0, lamport: lamportOf(mover), seq: mover, k: moved.r.k };\n \t\t\t\t\tat = moved.parent;\n \t\t\t\t}\n \t\t\t\tconst list = children.get(at);\n \t\t\t\tif (list) list.push(child);\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}\n \t\t\tfor (const [n, deleter] of graph.packedDeletes(file)) {\n \t\t\t\tif (!this.#has(deleter)) continue;\n@@ -675,10 +689,11 @@\n \t\t}\n \t\tconst order = (a: Child, b: Child) =>\n \t\t\tb.replaces - a.replaces || b.lamport - a.lamport || b.seq - a.seq || a.k - b.k;\n-\t\tconst priority = (a: number, b: number) => graph.lamportOfSeq(a) - graph.lamportOfSeq(b) || a - b;\n+\t\tconst priority = (a: number, b: number) => lamportOf(a) - lamportOf(b) || a - b;\n \t\tconst seq: number[] = [];\n \t\tconst vis: number[] = [];\n \t\tconst visText: (string | null)[] = [];\n+\t\tconst visWriter: number[] = [];\n \t\tconst deletedBy = new Map<number, readonly number[]>();\n \t\tconst stack: number[] = [];\n \t\tconst push = (code: number) => {\n@@ -696,11 +711,20 @@\n \t\t\t} else {\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}\n \t\t\tif (complete) seq.push(n);\n \t\t\tpush(n);\n \t\t}\n-\t\treturn { attrs, complete, seq: Int32Array.from(seq), vis: Int32Array.from(vis), deletedBy, visText };\n+\t\treturn {\n+\t\t\tattrs,\n+\t\t\tcomplete,\n+\t\t\tseq: Int32Array.from(seq),\n+\t\t\tvis: Int32Array.from(vis),\n+\t\t\tdeletedBy,\n+\t\t\tvisText,\n+\t\t\tvisWriter: Int32Array.from(visWriter),\n+\t\t};\n \t}\n \n \t#attributes(path: string): FileAttrs {\n@@ -859,8 +883,8 @@\n \t/** Atom-building line handles; text is loaded only when requested. */\n \tbuildLines(path: string): readonly VisibleLine[] {\n \t\tconst graph = this.graph;\n-\t\t// Texts the packed layout already holds are not read again (abso Capacity).\n-\t\tconst { vis, visText } = this.#file(path);\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 lines: VisibleLine[] = new Array(vis.length);\n \t\tfor (let i = 0; i < vis.length; i++) {\n \t\t\tconst n = vis[i]!;\n@@ -871,7 +895,7 @@\n \t\t\t\tget text() {\n \t\t\t\t\treturn packed ?? graph.textOf(n);\n \t\t\t\t},\n-\t\t\t\tatom: graph.idOfSeq(graph.writerSeqOf(n)),\n+\t\t\t\tatom: graph.idOfSeq(visWriter ? visWriter[i]! : graph.writerSeqOf(n)),\n \t\t\t};\n \t\t}\n \t\treturn lines;\n@@ -881,14 +905,14 @@\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 } = this.#file(path);\n+\t\tconst { vis, visText, visWriter } = 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\ttext: visText?.[i] ?? graph.textOf(n),\n-\t\t\t\tatom: graph.idOfSeq(graph.writerSeqOf(n)),\n+\t\t\t\tatom: graph.idOfSeq(visWriter ? visWriter[i]! : graph.writerSeqOf(n)),\n \t\t\t};\n \t\t}\n \t\tthis.#linesCache = { path, lines };\n@@ -1025,6 +1049,7 @@\n \t\t\t\tn += OBJECT_BYTES + OBJECT_BYTES + 2 * ARRAY_HEADER_BYTES;\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\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;"}],"unmatched":[]}