Line ids and writers from the packed layout, and a sequence's text read only when used (disk-first 2; abso Capacity). Version 232 of shared· capacity· Oct 15 (2026-10-15 09:30 UTC) · Not checked
Collisions 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.
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. sequence() reads each line's text when it is first asked for. On 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.
Named 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.
Version 231 · Files at version 232
1 file, 37 lines added, 9 removed.
--- a/src/engine/view.ts
+++ b/src/engine/view.ts
@@ -10,7 +10,7 @@
10 10 // made when a caller asks for them, and the latest asked for is kept. 12 12 import type { Graph, RelocationInfo } from "./graph.ts"; 13 − import { isStartNode, seqOf } from "./keys.ts";
13 + import { isStartNode, lineId, seqOf } from "./keys.ts"; 14 14 import { resolveScratchMoves, scratchLayoutNodes } from "./relocation-scratch.ts"; 15 15 import { isClosedSet, StableSet } from "./state-source.ts"; 16 16 import { joinLines } from "./text.ts"; @@ -71,6 +71,11 @@
71 71 readonly visText?: readonly (string | null)[]; 72 72 /** Its visible lines' writers' seqs, when laid out from the file's packed history. */ 73 73 readonly visWriter?: Int32Array; 74 + /** Its visible lines' places in their writers (a line id's k), when laid out from packed history. */ 75 + readonly visK?: Int32Array; 76 + /** The same for every line of seq, when complete and laid out from packed history. */ 77 + readonly seqWriter?: Int32Array; 78 + readonly seqK?: Int32Array; 74 79 /** Positions by n, built the first time they're asked for. */ 75 80 seqIndex?: Map<number, number>; 76 81 visIndex?: Map<number, number>; @@ -648,6 +653,7 @@
648 653 const children = new Map<number, Child[]>(); 649 654 const texts = new Map<number, string | null>(); 650 655 const writers = new Map<number, number>(); 656 + const places = new Map<number, number>(); 651 657 const deleters = new Map<number, number[]>(); 652 658 // Each atom's lamport once per layout: most lines share a few atoms, and a stored graph reads it from a page. 653 659 const lamports = new Map<number, number>(); @@ -677,6 +683,7 @@
677 683 else children.set(at, [child]); 678 684 texts.set(n, text); 679 685 writers.set(n, seq); 681 688 for (const [n, deleter] of graph.packedDeletes(file)) { 682 689 if (!this.#has(deleter)) continue; @@ -694,6 +701,9 @@
694 701 const vis: number[] = []; 695 702 const visText: (string | null)[] = []; 696 703 const visWriter: number[] = []; 704 + const visK: number[] = []; 705 + const seqWriter: number[] = []; 706 + const seqK: number[] = []; 697 707 const deletedBy = new Map<number, readonly number[]>(); 698 708 const stack: number[] = []; 699 709 const push = (code: number) => { @@ -712,8 +722,13 @@
713 723 visText.push(texts.get(n) ?? null); 714 724 visWriter.push(writers.get(n)!); 725 + visK.push(places.get(n)!); 716 − if (complete) seq.push(n);
729 + seqWriter.push(writers.get(n)!); 730 + seqK.push(places.get(n)!); @@ -724,6 +739,8 @@
726 741 visWriter: Int32Array.from(visWriter), 742 + visK: Int32Array.from(visK), 743 + ...(complete ? { seqWriter: Int32Array.from(seqWriter), seqK: Int32Array.from(seqK) } : {}), @@ -884,13 +901,13 @@
884 901 buildLines(path: string): readonly VisibleLine[] { 885 902 const graph = this.graph; 886 903 // Texts and writers the packed layout already holds are not read again (abso Capacity). 887 − const { vis, visText, visWriter } = this.#file(path);
904 + const { vis, visText, visWriter, visK } = this.#file(path); 888 905 const lines: VisibleLine[] = new Array(vis.length); 889 906 for (let i = 0; i < vis.length; i++) { 890 907 const n = vis[i]!; 891 908 const packed = visText?.[i]; 893 − id: graph.lineIdOf(n),
910 + id: visWriter && visK ? lineId(graph.idOfSeq(visWriter[i]!), visK[i]!) : graph.lineIdOf(n), 894 911 textChunks: () => graph.textChunks(n), 896 913 return packed ?? graph.textOf(n); @@ -905,12 +922,12 @@
905 922 lines(path: string): readonly VisibleLine[] { 906 923 if (this.#linesCache?.path === path) return this.#linesCache.lines; 907 924 const graph = this.graph; 908 − const { vis, visText, visWriter } = this.#file(path);
925 + const { vis, visText, visWriter, visK } = this.#file(path); 909 926 const lines: VisibleLine[] = new Array(vis.length); 910 927 for (let i = 0; i < vis.length; i++) { 911 928 const n = vis[i]!; 913 − id: graph.lineIdOf(n),
930 + id: visWriter && visK ? lineId(graph.idOfSeq(visWriter[i]!), visK[i]!) : graph.lineIdOf(n), 914 931 text: visText?.[i] ?? graph.textOf(n), 915 932 atom: graph.idOfSeq(visWriter ? visWriter[i]! : graph.writerSeqOf(n)), @@ -925,13 +942,21 @@
925 942 const graph = this.graph; 926 943 const f = this.#file(path, true); 927 944 const out: SeqLine[] = new Array(f.seq.length); 945 + // Ids and writers from the packed layout, and each text read only when asked (abso Capacity): callers walk a few 946 + // lines of a file's history, and reading every line's text was a row each on a stored graph. 947 + const { seqWriter, seqK } = f; 928 948 for (let i = 0; i < f.seq.length; i++) { 929 949 const n = f.seq[i]!; 930 950 const by = f.deletedBy.get(i); 951 + const writer = seqWriter ? seqWriter[i]! : graph.writerSeqOf(n); 952 + let text: string | undefined; 932 − id: graph.lineIdOf(n),
933 − text: graph.textOf(n),
934 − atom: graph.idOfSeq(graph.writerSeqOf(n)),
954 + id: seqWriter && seqK ? lineId(graph.idOfSeq(writer), seqK[i]!) : graph.lineIdOf(n), 956 + text ??= graph.textOf(n); 959 + atom: graph.idOfSeq(writer), 935 960 deletedBy: by ? by.map((s) => graph.idOfSeq(s)) : NONE, 936 961 visible: by === undefined, @@ -1053,6 +1078,9 @@
1053 1078 n += f.seq.byteLength + f.vis.byteLength; 1054 1079 if (f.visText) for (const text of f.visText) n += REFERENCE_BYTES + 2 * (text?.length ?? 0); 1055 1080 if (f.visWriter) n += 4 * f.visWriter.length; 1081 + if (f.visK) n += 4 * f.visK.length; 1082 + if (f.seqWriter) n += 4 * f.seqWriter.length; 1083 + if (f.seqK) n += 4 * f.seqK.length; 1056 1084 n += MAP_HEADER_BYTES + (MAP_ENTRY_BYTES + ARRAY_HEADER_BYTES) * f.deletedBy.size; 1057 1085 for (const deleters of f.deletedBy.values()) n += REFERENCE_BYTES * deleters.length; 1058 1086 if (f.seqIndex) n += MAP_HEADER_BYTES + MAP_ENTRY_BYTES * f.seqIndex.size;