Path names kept in memory once read (disk-first 2; abso Capacity). Version 240 of shared· capacity· Oct 15 (2026-10-15 12:17 UTC) · Not checked
After 239, collisions on website spent most of its 4.6 s naming files: finding a deleted line's file ends at a file's start node, and Graph.#nodeName read the stored path list for it every time, through the row cache. Line records, line files and an atom's files read it the same way.
Graph.#pathName keeps path names by index in memory, up to 4,096, and clears them whenever the graph accepts an atom, so a name a rolled-back add made never stays.
On website adopted fresh, cold, one opened writer: collisions 4.6 s to 1.6 s (replay 0.4 s), matching replay. typescript-rs: all 27 answers match.
Named tests: every engine test (290 of 290), every worker/project test (341 of 341); tsc and biome clean.
Version 239 · Files at version 240
1 file, 28 lines added, 5 removed.
--- a/src/engine/graph.ts
+++ b/src/engine/graph.ts
@@ -267,6 +267,8 @@
267 267 /** A run written in another file under one of a file's lines: [the parent's n, the run's file index]. */ 268 268 export type PackedCrossing = [number, number]; 269 269 const EMPTY_NUMBERS: readonly number[] = Object.freeze([]); 270 + /** At most this many path names kept in memory (Graph.#pathName). */ 271 + const PATH_NAMES = 4096; 270 272 /** Lines longer than this aren't packed with their file; their text is read on its own. */ 271 273 const PACKED_TEXT = 4096; @@ -881,7 +883,7 @@
882 884 atom: this.idOfSeq(seq), 883 885 k: n - this.#lineBase[seq]!, 884 − file: this.#paths[this.#lineFile.at(n)]!,
886 + file: this.#pathName(this.#lineFile.at(n)), 885 887 parent: this.#nodeName(this.#lineParent.at(n)), 886 888 text: this.#text(n), @@ -902,7 +904,7 @@
902 904 /** The file a line was written in, or undefined: line(id).file without making the record. */ 903 905 lineFile(id: LineId): string | undefined { 904 906 const n = this.#lineN(id); 905 − return n < 0 ? undefined : this.#paths[this.#lineFile.at(n)];
907 + return n < 0 ? undefined : this.#pathName(this.#lineFile.at(n)); 908 910 /** The node a line was written after, or undefined: line(id).parent without making the record. */ @@ -1014,7 +1016,7 @@
1015 1017 /** The file line n was written in. */ 1016 1018 writtenIn(n: number): string { 1017 − return this.#paths[this.#lineFile.at(n)]!;
1019 + return this.#pathName(this.#lineFile.at(n)); 1020 1022 /** The code of the node line n was written after. */ @@ -1177,9 +1179,30 @@
1179 1181 #nodeName(code: number): NodeId { 1180 − return code >= 0 ? this.#lineName(code) : startNode(this.#paths[-1 - code]!);
1182 + return code >= 0 ? this.#lineName(code) : startNode(this.#pathName(-1 - code)); 1186 + * A path's name by its index, kept in memory once read (abso Capacity): finding a deleted line's file names the file 1187 + * it reaches, and a stored graph read the path list each time. Cleared when the graph accepts an atom, so a name a 1188 + * rolled-back add made never stays. 1190 + #pathName(index: number): string { 1191 + if (this.#pathNamesAt !== this.#accepted) { 1192 + this.#pathNames.clear(); 1193 + this.#pathNamesAt = this.#accepted; 1195 + let name = this.#pathNames.get(index); 1196 + if (name === undefined) { 1197 + name = this.#paths[index]!; 1198 + if (this.#pathNames.size >= PATH_NAMES) this.#pathNames.clear(); 1199 + this.#pathNames.set(index, name); 1203 + readonly #pathNames = new Map<number, string>(); 1183 1206 #pathOf(file: string): number { 1184 1207 let p = this.#pathIndex.get(file); 1185 1208 if (p === undefined) { @@ -1689,7 +1712,7 @@
1690 1713 const files = new Set<string>(); 1691 1714 for (const run of atom.inserts) files.add(run.file); 1692 − for (const n of deletedNumbers(this)) files.add(this.#paths[this.#lineFile.at(n)]!);
1715 + for (const n of deletedNumbers(this)) files.add(this.#pathName(this.#lineFile.at(n))); 1693 1716 for (const a of frozen.attrs ?? []) files.add(a.file); 1694 1717 for (const m of frozen.moves ?? []) { 1695 1718 files.add(this.lineFile(m.line)!);