Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed
MCP
blame on this site's /mcp
CLI
abso blame src/engine/view.ts --version 232 --json
JSON
/christopher/abso-core/blame/src/engine/view.ts?version=232&format=json
1,122 linescapacity 41% · First import 33% · codex-capacity-chair 22% · codex-capacity-policy 4%Last change capacity in version 232,

1,122 lines from 32 changes in 29 versions.

init0Start the project1// Projection: the files a closed set of atoms produces. A pure function of the
2// set. Each file is a tree of lines hanging off its start node; linearizing it
3// depth-first, children in descending priority, gives the file's sequence. A
4// line hangs off the node it was written after, unless a move in the set gave
5// it another parent (#28): then the newest such move decides.
6//
7// A laid-out file is kept as arrays of line numbers (the graph's n), not as a
8// record per line (#46): a record, its id and two index entries cost about
9// 370 bytes a line, and the view cache holds up to 200,000 lines. Records are
10// made when a caller asks for them, and the latest asked for is kept.
12import type { Graph, RelocationInfo } from "./graph.ts";
capacity232Line ids and writers from the packed layout, and a sequence's text read only when used (disk-first 2; abso Capacity). 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.Compare13import { isStartNode, lineId, seqOf } from "./keys.ts";
codex-capacity-chair132Bound persistent relocation projection memory with rollback-only scratchCompare14import { resolveScratchMoves, scratchLayoutNodes } from "./relocation-scratch.ts";
capacity205Disk-first reads stop walking the whole history (disk-first 2, stage 1; abso Capacity). Shared's closure is kept on disk per version (spaces.ts indexClosure): the atoms a version needs beyond what it published, as events like membership's, with drops handled; views and Project.#closed trust a set marked closed, and over a closed stored base only a draft's own atoms are walked. A view resolves its moves once in memory (up to MOVED_LINES_KEPT, 20,000 moved lines) instead of again on disk for every file it lays out, and finds lines moved under a node from them. Graph.eachChildN skips the per-line children lookup when the paged child counts say none. On game's export (writer adopted, lock held): shared() went from not finishing in 8 minutes to 9-13 s cold and 0.15-0.25 s warm, 291,000 queries to 57,000; pathsAt(head) 0.1-0.2 s.Compare15import { isClosedSet, StableSet } from "./state-source.ts";
init0Start the project16import { joinLines } from "./text.ts";
17import { type AtomId, type AtomSet, EngineError, type LineId, type NodeId } from "./types.ts";
19/** A line in a file's full sequence, tombstones included. */
20export interface SeqLine {
21 readonly id: LineId;
22 readonly text: string;
23 /** The atom that wrote it. */
24 readonly atom: AtomId;
25 /** Atoms in the set that delete it, by seq. Empty when it is visible. */
26 readonly deletedBy: readonly AtomId[];
27 readonly visible: boolean;
30/** A visible line of a projected file. */
31export interface VisibleLine {
codex-capacity-chair175Reduce disk-backed record and publish allocations; reviewed in core ask 52 with parsed-code budget and exact aligned-line follow-ups. Keep disk-first activation off.Compare32 readonly textChunks?: () => Iterable<string>;
init0Start the project33 readonly id: LineId;
34 readonly text: string;
35 readonly atom: AtomId;
38/** A file's attributes in a view. */
39export interface FileAttrs {
40 /** Kept with no lines (an empty file). */
41 readonly exists: boolean;
42 readonly exec: boolean;
43 /** The target, when the file is a symbolic link. */
44 readonly link: string | null;
45 /** The SHA-256 of its bytes, when the file is binary. */
46 readonly blob: string | null;
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare49/** Structural read boundary shared by historical and transaction-bound projections. */
capacity212Draft reads on a stored writer (disk-first 2; abso Capacity): where, drafts, status and collisions on website's export. - where looks deleted lines up by number (graph.deletedNumbers, View.fileOfNumber, View.lineNumberOf). It takes the agent's view once instead of once per line, since each read weighed every cached view. It finds the draft's lines by writer (View.visibleWriters), with no text or id read per line. - Draft files (overlaps.ts) go by number the same way. - An agent's view takes its base's resolved moves when both hold the same atoms that move lines (View.shareMoves checks this). - Draft collisions: - build the union view only when two drafts share a file; - work out each agent's touched files and its "shared now plus draft" view once; - find claimants among the drafts from the drafts' own keys (collisions.ts claimantsAmong) instead of walking each key's history; - have the definition rule keep a draft's uses, and the newer work's definitions, across partners. - A stored list read in order reads its length once, not before every element. draft-reads-stored.test.ts checks where and collisions against the in-memory project. It covers edits, a whole file deleted, a line collision, one name defined twice, and bases before and after a move. 135 of 136 related tests pass; none fail. On website's export (1,387 entries) the answers match Project.load: - status: 17 s to 4.5 s - where: over 60 s to 8.8 s - drafts: 14 s to 5.3 s - collisions: over 60 s to 54 s, measured under the profiler before the last two changesCompare50export type ReadView = Omit<
51 Pick<View, keyof View>,
52 "sameText" | "visibleCount" | "shareMoves" | "fileOfNumber" | "lineNumberOf" | "visibleWriters"
53> & {
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare54 sameText(path: string, other: ReadView): boolean;
55};
init0Start the project57const NO_ATTRS: FileAttrs = { exists: false, exec: false, link: null, blob: null };
58const NONE: readonly never[] = Object.freeze([]);
60interface FileState {
61 readonly attrs: FileAttrs;
codex-capacity-chair110Keep current-file views and key scans from retaining historical stateCompare62 /** Full history is retained only when a sequence caller explicitly requests it. */
63 readonly complete: boolean;
init0Start the project64 /** The file's sequence, tombstones included: each line's n. */
65 readonly seq: Int32Array;
66 /** Its visible lines' n, in order. */
67 readonly vis: Int32Array;
68 /** For each deleted position in seq: the seqs of the atoms in the set that delete it, by priority. */
69 readonly deletedBy: ReadonlyMap<number, readonly number[]>;
capacity206Each file's line history packed (disk-first 2, lines by file; abso Capacity). A stored graph appends every line written in a file ([n, parent code, writer seq, k, replaces]) and its text, every delete of one of its lines, and every attribute set on it to that file's pages as atoms are added, a run at a time (storedLists appendAll). A view lays a file out from those pages in memory: membership checked once per atom, moves followed from the ones it already resolved, lines moved in from other files read from theirs. Same tree and order as before (packed-files.test.ts checks it against the in-memory graph through edits, deletes and moves). Graphs adopted before have no packs and lay out line by line as before; packFiles: false keeps that path for its tests. On game's export: first shared() 13 s to 2-3.6 s at 20,000 queries, warm 56-82 ms, pathsAt(head) 29-119 ms; files at a version 14 s to 3 s, compare 26 s to 11 s, a path's log 27 s to 4.5 s; every answer the harness finished matches Project.load.Compare70 /** Its visible lines' text, when laid out from the file's packed history: null for a line too long to pack. */
71 readonly visText?: readonly (string | null)[];
capacity230Who wrote what, read from the packed layout and each atom's author once (disk-first 2; abso Capacity). On website, with one opened writer, tree with authors took 9.6 s, tree for an agent with authors 9.1 s, and a folder's blame 4.9 s. Replay takes about 0.25 s. Few row reads: the time went on reading the same few large atoms again and again. - tree with authors, a folder's blame and a file's blame look up each atom's author once per call. graph.atom read and parsed the whole atom for every line, and most lines share a few big atoms. - The packed layout keeps each visible line's writer (visWriter), and lines() and buildLines use it instead of looking each line's writer up again. - The packed layout reads each atom's lamport number once per layout instead of once per line. On website adopted fresh, cold: tree with authors 3.2 s, tree for an agent with authors 4.5 s, a folder's blame 2.4 s; all seven tree and blame answers match replay. New test authors-stored: tree with authors (head, an older version, an agent's draft, a folder), folder blame and file blame on a writer-backed project answer as the in-memory one; it fails when the layout records the wrong writer. Named tests: every engine test (288 of 288), authors-stored, history, trail, draft-reads-stored, packed-crossings, version-files, files-reads, view-cache, membership-pages, project (54 of 54); tsc and biome clean.Compare72 /** Its visible lines' writers' seqs, when laid out from the file's packed history. */
73 readonly visWriter?: Int32Array;
capacity232Line ids and writers from the packed layout, and a sequence's text read only when used (disk-first 2; abso Capacity). 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.Compare74 /** 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;
init0Start the project79 /** Positions by n, built the first time they're asked for. */
80 seqIndex?: Map<number, number>;
81 visIndex?: Map<number, number>;
84interface Child {
85 readonly n: number;
86 /** 1 when the child's atom deleted the parent (the child replaces it), else 0. A moved line is 0. */
87 readonly replaces: number;
88 readonly lamport: number;
89 readonly seq: number;
90 readonly k: number;
93const EMPTY_INTS = new Int32Array(0);
codex-capacity-chair110Keep current-file views and key scans from retaining historical stateCompare94const NO_FILE: FileState = { attrs: NO_ATTRS, complete: true, seq: EMPTY_INTS, vis: EMPTY_INTS, deletedBy: new Map() };
init0Start the project95
codex-capacity-policy103Test deterministic replay and account view cache weightCompare96// Approximate retained-container costs for View.weight(): reference slots,
97// object headers, and map/set entries. These are cache-budget units, not V8
98// heap measurements. Referenced Graph strings and records are not charged.
99const ARRAY_HEADER_BYTES = 24;
100const OBJECT_BYTES = 32;
101const MAP_HEADER_BYTES = 32;
102const MAP_ENTRY_BYTES = 40;
103const SET_ENTRY_BYTES = 32;
104const REFERENCE_BYTES = 8;
capacity205Disk-first reads stop walking the whole history (disk-first 2, stage 1; abso Capacity). Shared's closure is kept on disk per version (spaces.ts indexClosure): the atoms a version needs beyond what it published, as events like membership's, with drops handled; views and Project.#closed trust a set marked closed, and over a closed stored base only a draft's own atoms are walked. A view resolves its moves once in memory (up to MOVED_LINES_KEPT, 20,000 moved lines) instead of again on disk for every file it lays out, and finds lines moved under a node from them. Graph.eachChildN skips the per-line children lookup when the paged child counts say none. On game's export (writer adopted, lock held): shared() went from not finishing in 8 minutes to 9-13 s cold and 0.15-0.25 s warm, 291,000 queries to 57,000; pathsAt(head) 0.1-0.2 s.Compare105/**
106 * Moved lines a view resolves once and keeps (abso Capacity): a stored graph otherwise resolved every move again on
107 * disk for each file it laid out. Game's whole history has 290; past this many, the view goes back to that.
108 */
109export const MOVED_LINES_KEPT = 20_000;
110class TooManyMoves extends Error {}
111const NO_LINES: readonly number[] = Object.freeze([]);
capacity215Moves resolved over the moved lines alone, and closure over a named draft's own atoms (disk-first 2; abso Capacity), for abso's status and drafts. - view.ts MoveSkeleton: once per graph, and extended as it grows, each mover's moved lines, each moved line's relocations, and for any node the nearest node above it that a move ever relocated (or its file's start), memoised up to 200,000 nodes. A view's relocations and its loop check now hop between moved lines instead of walking every moved line's file up to its start, and fileOf hops the same way. The per-view location memos are gone. On abso's export (1,687 moved lines, 972 movers), status went from 104 s to 41 s under the profiler; agent views no longer re-walk each base's moves. - project.ts #closed opens unions down to their closed parts. An agent in a named draft has the draft's atoms over a closed shared base, one union deeper than #closed looked, so it walked all of shared's atoms and their dependencies. Tests: 97 of 97 across moves, relocation, projection-move-resolution, packed-files, view, drop, queued-moves, named-drafts, stored-closure, stored-membership, version-files, draft-reads-stored and writer storage. tsc clean.Compare112/** Nodes whose nearest moved line above a graph remembers, at most: about 40 bytes each. */
113const CLIMB_MEMO = 200_000;
codex-capacity-policy103Test deterministic replay and account view cache weightCompare114
capacity215Moves resolved over the moved lines alone, and closure over a named draft's own atoms (disk-first 2; abso Capacity), for abso's status and drafts. - view.ts MoveSkeleton: once per graph, and extended as it grows, each mover's moved lines, each moved line's relocations, and for any node the nearest node above it that a move ever relocated (or its file's start), memoised up to 200,000 nodes. A view's relocations and its loop check now hop between moved lines instead of walking every moved line's file up to its start, and fileOf hops the same way. The per-view location memos are gone. On abso's export (1,687 moved lines, 972 movers), status went from 104 s to 41 s under the profiler; agent views no longer re-walk each base's moves. - project.ts #closed opens unions down to their closed parts. An agent in a named draft has the draft's atoms over a closed shared base, one union deeper than #closed looked, so it walked all of shared's atoms and their dependencies. Tests: 97 of 97 across moves, relocation, projection-move-resolution, packed-files, view, drop, queued-moves, named-drafts, stored-closure, stored-membership, version-files, draft-reads-stored and writer storage. tsc clean.Compare115/** One relocation of a moved line, with its line's number and its new parent's code. */
116interface MoveEntry {
117 readonly n: number;
118 readonly r: RelocationInfo;
119 readonly parent: number;
init0Start the project122/**
capacity215Moves resolved over the moved lines alone, and closure over a named draft's own atoms (disk-first 2; abso Capacity), for abso's status and drafts. - view.ts MoveSkeleton: once per graph, and extended as it grows, each mover's moved lines, each moved line's relocations, and for any node the nearest node above it that a move ever relocated (or its file's start), memoised up to 200,000 nodes. A view's relocations and its loop check now hop between moved lines instead of walking every moved line's file up to its start, and fileOf hops the same way. The per-view location memos are gone. On abso's export (1,687 moved lines, 972 movers), status went from 104 s to 41 s under the profiler; agent views no longer re-walk each base's moves. - project.ts #closed opens unions down to their closed parts. An agent in a named draft has the draft's atoms over a closed shared base, one union deeper than #closed looked, so it walked all of shared's atoms and their dependencies. Tests: 97 of 97 across moves, relocation, projection-move-resolution, packed-files, view, drop, queued-moves, named-drafts, stored-closure, stored-membership, version-files, draft-reads-stored and writer storage. tsc clean.Compare123 * A graph's moves, whatever the set (abso Capacity): each mover's moved lines, each moved line's relocations in seq
124 * order, and for any node the nearest node at or above it, by where lines were written, that a move ever relocated,
125 * or its file's start. Worked out once per graph and extended as it grows. A view's moves then resolve over the moved
126 * lines alone: before, every view walked each moved line's file up to its start, a read per line.
127 */
128class MoveSkeleton {
129 readonly #graph: Graph;
130 #seen = 0;
131 /** Movers in seq order, with the numbers of the lines each moves, in its moves' order. */
132 readonly movers: { readonly seq: number; readonly lines: readonly number[] }[] = [];
133 /** Every relocation of each moved line, by the line's number, in seq order. */
134 readonly byLine = new Map<number, MoveEntry[]>();
135 readonly #climbed = new Map<number, number>();
137 constructor(graph: Graph) {
138 this.#graph = graph;
139 }
141 /** Take in movers the graph gained since. */
142 update(): this {
143 const graph = this.#graph;
144 const all = graph.movers();
145 if (this.#seen === all.length) return this;
146 for (; this.#seen < all.length; this.#seen++) {
147 const id = all[this.#seen]!;
148 const lines: number[] = [];
149 graph.atom(id).moves!.forEach((m, k) => {
150 const n = graph.lineN(m.line);
151 const r: RelocationInfo = Object.freeze({ atom: id, line: m.line, parent: m.parent, k });
152 const entry: MoveEntry = { n, r, parent: graph.codeOf(m.parent)! };
153 const list = this.byLine.get(n);
154 if (list) list.push(entry);
155 else this.byLine.set(n, [entry]);
156 lines.push(n);
157 });
158 this.movers.push({ seq: seqOf(id), lines });
159 }
160 // A new moved line can sit between a node and the one it climbed to.
161 this.#climbed.clear();
162 return this;
163 }
165 /** The nearest node at or above this one, by where lines were written, that a move ever relocated; or its file's start. */
166 climb(code: number): number {
167 const walked: number[] = [];
168 let c = code;
169 while (c >= 0 && !this.byLine.has(c)) {
170 const known = this.#climbed.get(c);
171 if (known !== undefined) {
172 c = known;
173 break;
174 }
175 walked.push(c);
176 c = this.#graph.parentCodeOf(c);
177 }
178 if (this.#climbed.size + walked.length > CLIMB_MEMO) this.#climbed.clear();
179 for (const w of walked) this.#climbed.set(w, c);
180 return c;
181 }
184const skeletons = new WeakMap<Graph, MoveSkeleton>();
185function skeletonOf(graph: Graph): MoveSkeleton {
186 let skeleton = skeletons.get(graph);
187 if (!skeleton) skeletons.set(graph, (skeleton = new MoveSkeleton(graph)));
188 return skeleton.update();
191/**
init0Start the project192 * The projection of a closed set. Construct once, then ask for files, lines
193 * and sequences. Throws `not-closed` if some atom's dependency is missing.
194 * Each file is laid out the first time it is asked for, so a view of a large
195 * set costs little until files are read.
196 */
197export class View {
198 readonly graph: Graph;
199 /** The set, made from #in the first time it's asked for: a view keeps a byte per atom, not a copy of the set (#46). */
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare200 #set: AtomSet | undefined;
201 readonly #stable: StableSet<AtomId> | undefined;
codex-capacity-chair116Bound repeated indexed view membership lookupsCompare202 /** Fixed-size memo for immutable indexed membership, independent of history size. */
203 #membershipSeq = new Float64Array(256).fill(-1);
204 #membershipValue = new Uint8Array(256);
init0Start the project205 #files = new Map<string, FileState>();
206 /** Every file the set wrote in, sorted; worked out the first time it's asked for. */
207 #knownList: string[] | undefined;
208 /** 1 for each atom (by seq) in the set. */
209 #in: Uint8Array;
210 /** Atoms in the set that move lines. */
codex-capacity-chair123Stream mover history when opening persisted viewsCompare211 #movers: AtomId[] | undefined;
212 #hasMoves = false;
init0Start the project213 /** Each moved line's relocation that counts in this set; built on first use. */
214 #relocs: Map<LineId, RelocationInfo> | undefined;
215 /** The same, by n, with the new parent's code. */
216 #relocsN: Map<number, { readonly r: RelocationInfo; readonly parent: number }> | undefined;
capacity205Disk-first reads stop walking the whole history (disk-first 2, stage 1; abso Capacity). Shared's closure is kept on disk per version (spaces.ts indexClosure): the atoms a version needs beyond what it published, as events like membership's, with drops handled; views and Project.#closed trust a set marked closed, and over a closed stored base only a draft's own atoms are walked. A view resolves its moves once in memory (up to MOVED_LINES_KEPT, 20,000 moved lines) instead of again on disk for every file it lays out, and finds lines moved under a node from them. Graph.eachChildN skips the per-line children lookup when the paged child counts say none. On game's export (writer adopted, lock held): shared() went from not finishing in 8 minutes to 9-13 s cold and 0.15-0.25 s warm, 291,000 queries to 57,000; pathsAt(head) 0.1-0.2 s.Compare217 /** The moved lines under each node, by its code, made from the relocations on first use. */
218 #movedInto: Map<number, number[]> | undefined;
219 /** Whether this view's moves are too many to keep, so they're resolved on disk per layout; undefined until asked. */
220 #movesOnDisk: boolean | undefined;
init0Start the project221 /** The latest records asked for: one file's lines, one file's sequence, one file's text. */
222 #linesCache: { path: string; lines: readonly VisibleLine[] } | undefined;
223 #seqCache: { path: string; seq: readonly SeqLine[] } | undefined;
224 #textCache: { path: string; text: string } | undefined;
226 constructor(graph: Graph, set: Iterable<AtomId>) {
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare227 this.graph = graph;
228 if (set instanceof StableSet) {
229 this.#stable = set;
230 this.#set = set;
231 this.#in = new Uint8Array(0);
capacity205Disk-first reads stop walking the whole history (disk-first 2, stage 1; abso Capacity). Shared's closure is kept on disk per version (spaces.ts indexClosure): the atoms a version needs beyond what it published, as events like membership's, with drops handled; views and Project.#closed trust a set marked closed, and over a closed stored base only a draft's own atoms are walked. A view resolves its moves once in memory (up to MOVED_LINES_KEPT, 20,000 moved lines) instead of again on disk for every file it lays out, and finds lines moved under a node from them. Graph.eachChildN skips the per-line children lookup when the paged child counts say none. On game's export (writer adopted, lock held): shared() went from not finishing in 8 minutes to 9-13 s cold and 0.15-0.25 s warm, 291,000 queries to 57,000; pathsAt(head) 0.1-0.2 s.Compare232 // A set kept closed when it was written needs no proof here (abso Capacity).
233 for (const id of isClosedSet(set) ? [] : set) {
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare234 const atom = graph.atom(id);
235 for (const dependency of atom.deps) {
236 graph.atom(dependency);
237 if (!set.has(dependency))
238 throw new EngineError("not-closed", `set is not closed: ${id} depends on ${dependency}`);
239 }
240 }
codex-capacity-chair123Stream mover history when opening persisted viewsCompare241 for (const id of graph.movers()) {
242 if (set.has(id)) {
243 this.#hasMoves = true;
244 break;
245 }
246 }
247 this.#relocs = this.#hasMoves ? undefined : new Map();
248 this.#relocsN = this.#hasMoves ? undefined : new Map();
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare249 return;
250 }
init0Start the project251 const inSet = new Uint8Array(graph.size);
capacity218why on a stored writer (disk-first 2; abso Capacity). - A View reads atoms' numbers from their ids instead of reading each atom: building one from a plain set read every atom twice, and every mover once. - keptThrough, the settle a line was kept through, looks only among the atoms that write or take out the file's lines (graph.eachAtomIn), and lays out the file just before that settle from a lazy prefix of the view's set when that set is closed. It used to read every atom in the history and list all the earlier ones. - publishOf looks in shared before listing the named drafts, since listing them decodes each one's space. - view.ts loses #eachMover, unused since 215. On abso's export, why for line 1 of issues/src/index.ts went from 41 s to 11 s on one opened writer, matching Project.load. The rest is trail's search for a moved line's origin among nearby changes. Named tests: trail, named-drafts, files-reads, project, markers, version-files, draft-reads-stored, view, moves, drop (109 of 109); tsc and biome clean.Compare252 // An atom's number is in its id (abso Capacity): reading the atom for it read the whole history on a stored graph.
253 const seqIn = (id: AtomId): number => {
254 const seq = seqOf(id);
255 return seq >= 0 && seq < inSet.length && graph.idOfSeq(seq) === id ? seq : graph.atom(id).seq;
256 };
257 for (const id of set) inSet[seqIn(id)] = 1;
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare258 // Validate one atom at a time. Keeping all decoded atoms here defeats
259 // storage-backed Graph reads even though the view only needs membership.
260 for (let seq = 0; seq < inSet.length; seq++) {
261 if (inSet[seq] !== 1) continue;
262 const atom = graph.atom(graph.idOfSeq(seq));
init0Start the project263 for (const d of atom.deps) {
capacity218why on a stored writer (disk-first 2; abso Capacity). - A View reads atoms' numbers from their ids instead of reading each atom: building one from a plain set read every atom twice, and every mover once. - keptThrough, the settle a line was kept through, looks only among the atoms that write or take out the file's lines (graph.eachAtomIn), and lays out the file just before that settle from a lazy prefix of the view's set when that set is closed. It used to read every atom in the history and list all the earlier ones. - publishOf looks in shared before listing the named drafts, since listing them decodes each one's space. - view.ts loses #eachMover, unused since 215. On abso's export, why for line 1 of issues/src/index.ts went from 41 s to 11 s on one opened writer, matching Project.load. The rest is trail's search for a moved line's origin among nearby changes. Named tests: trail, named-drafts, files-reads, project, markers, version-files, draft-reads-stored, view, moves, drop (109 of 109); tsc and biome clean.Compare264 if (inSet[seqIn(d)] !== 1) throw new EngineError("not-closed", `set is not closed: ${atom.id} depends on ${d}`);
init0Start the project265 }
266 }
267 this.graph = graph;
268 this.#in = inSet;
capacity218why on a stored writer (disk-first 2; abso Capacity). - A View reads atoms' numbers from their ids instead of reading each atom: building one from a plain set read every atom twice, and every mover once. - keptThrough, the settle a line was kept through, looks only among the atoms that write or take out the file's lines (graph.eachAtomIn), and lays out the file just before that settle from a lazy prefix of the view's set when that set is closed. It used to read every atom in the history and list all the earlier ones. - publishOf looks in shared before listing the named drafts, since listing them decodes each one's space. - view.ts loses #eachMover, unused since 215. On abso's export, why for line 1 of issues/src/index.ts went from 41 s to 11 s on one opened writer, matching Project.load. The rest is trail's search for a moved line's origin among nearby changes. Named tests: trail, named-drafts, files-reads, project, markers, version-files, draft-reads-stored, view, moves, drop (109 of 109); tsc and biome clean.Compare269 this.#movers = graph.movers().filter((id) => inSet[seqOf(id)] === 1);
codex-capacity-chair123Stream mover history when opening persisted viewsCompare270 this.#hasMoves = this.#movers.length > 0;
init0Start the project271 this.#relocs = this.#movers.length === 0 ? new Map() : undefined;
272 this.#relocsN = this.#movers.length === 0 ? new Map() : undefined;
273 }
275 /** The set of atoms this view projects. */
276 get set(): AtomSet {
277 if (!this.#set) {
278 const out = new Set<AtomId>();
279 for (let seq = 0; seq < this.#in.length; seq++) if (this.#in[seq] === 1) out.add(this.graph.idOfSeq(seq));
280 this.#set = out;
281 }
282 return this.#set;
283 }
285 /** Whether the atom with this seq is in the set. */
286 #has(seq: number): boolean {
codex-capacity-chair116Bound repeated indexed view membership lookupsCompare287 if (this.#stable) {
288 const slot = seq % this.#membershipSeq.length;
289 if (this.#membershipSeq[slot] === seq) return this.#membershipValue[slot] === 1;
290 const present = this.#stable.has(this.graph.idOfSeq(seq));
291 this.#membershipSeq[slot] = seq;
292 this.#membershipValue[slot] = present ? 1 : 0;
293 return present;
294 }
init0Start the project295 return seq < this.#in.length && this.#in[seq] === 1;
296 }
298 /**
299 * The relocation that counts for each moved line: the newest (by priority)
300 * in the set. Two moves made apart can loop lines into each other, so no
301 * start node reaches them; then the oldest relocation on the loop is
302 * ignored, and the next newest of that line counts, until none loop.
303 */
304 #relocations(): Map<LineId, RelocationInfo> {
305 if (this.#relocs) return this.#relocs;
capacity216Moves picked as walks reach them, and shared's file list from kept shapes (disk-first 2; abso Capacity), for abso's status, drafts and file list. - view.ts: a view picks a moved line's relocation only when a walk to find a line's file reaches that line. That is #relocations' own pick, right whenever the walk goes on to a file's start, since only lines on a loop have their relocation set aside; a walk that comes back to a line it passed resolves every move as before. shareMoves now takes the other view's moves only when this view first needs all of them, such as for a layout, so a view that only finds a few lines' files never resolves them. weight() counts the picks. - pathindex.ts keptPaths: shared's files at a version, folded from version 0 over each version's kept files made and taken out, with no file laid out. Only on a stored writer, and only when every version up to it has a kept row that describes it; otherwise the version is laid out as before. pathsAt uses it. On abso's export (81,855 entries, 1,224 versions), one opened project, answers matching Project.load: - status: 104 s to 5.8 s (under the profiler) - drafts: over 60 s to 5.7 s - files at head: over 60 s to 1.2 s - files at 612: 54 s to 0.3 s version-files.test.ts now also checks the file list at every version against the in-memory project. 124 of 124 related tests pass; tsc clean.Compare306 this.#takeShared();
307 if (this.#relocs) return this.#relocs;
init0Start the project308 const graph = this.graph;
capacity215Moves resolved over the moved lines alone, and closure over a named draft's own atoms (disk-first 2; abso Capacity), for abso's status and drafts. - view.ts MoveSkeleton: once per graph, and extended as it grows, each mover's moved lines, each moved line's relocations, and for any node the nearest node above it that a move ever relocated (or its file's start), memoised up to 200,000 nodes. A view's relocations and its loop check now hop between moved lines instead of walking every moved line's file up to its start, and fileOf hops the same way. The per-view location memos are gone. On abso's export (1,687 moved lines, 972 movers), status went from 104 s to 41 s under the profiler; agent views no longer re-walk each base's moves. - project.ts #closed opens unions down to their closed parts. An agent in a named draft has the draft's atoms over a closed shared base, one union deeper than #closed looked, so it walked all of shared's atoms and their dependencies. Tests: 97 of 97 across moves, relocation, projection-move-resolution, packed-files, view, drop, queued-moves, named-drafts, stored-closure, stored-membership, version-files, draft-reads-stored and writer storage. tsc clean.Compare309 const skeleton = skeletonOf(graph);
init0Start the project310 const stronger = (a: RelocationInfo, b: RelocationInfo): boolean => graph.comparePriority(a.atom, b.atom) > 0;
codex-capacity-chair126Identify suppressed relocation cycles across persistent readsCompare311 const identity = (r: RelocationInfo): string => JSON.stringify([r.atom, r.k]);
312 const ignored = new Set<string>();
capacity215Moves resolved over the moved lines alone, and closure over a named draft's own atoms (disk-first 2; abso Capacity), for abso's status and drafts. - view.ts MoveSkeleton: once per graph, and extended as it grows, each mover's moved lines, each moved line's relocations, and for any node the nearest node above it that a move ever relocated (or its file's start), memoised up to 200,000 nodes. A view's relocations and its loop check now hop between moved lines instead of walking every moved line's file up to its start, and fileOf hops the same way. The per-view location memos are gone. On abso's export (1,687 moved lines, 972 movers), status went from 104 s to 41 s under the profiler; agent views no longer re-walk each base's moves. - project.ts #closed opens unions down to their closed parts. An agent in a named draft has the draft's atoms over a closed shared base, one union deeper than #closed looked, so it walked all of shared's atoms and their dependencies. Tests: 97 of 97 across moves, relocation, projection-move-resolution, packed-files, view, drop, queued-moves, named-drafts, stored-closure, stored-membership, version-files, draft-reads-stored and writer storage. tsc clean.Compare313 const pick = (n: number): MoveEntry | undefined => {
314 let best: MoveEntry | undefined;
315 for (const e of skeleton.byLine.get(n) ?? []) {
316 if (this.#has(seqOf(e.r.atom)) && !ignored.has(identity(e.r)) && (!best || stronger(e.r, best.r))) best = e;
init0Start the project317 }
318 return best;
319 };
capacity215Moves resolved over the moved lines alone, and closure over a named draft's own atoms (disk-first 2; abso Capacity), for abso's status and drafts. - view.ts MoveSkeleton: once per graph, and extended as it grows, each mover's moved lines, each moved line's relocations, and for any node the nearest node above it that a move ever relocated (or its file's start), memoised up to 200,000 nodes. A view's relocations and its loop check now hop between moved lines instead of walking every moved line's file up to its start, and fileOf hops the same way. The per-view location memos are gone. On abso's export (1,687 moved lines, 972 movers), status went from 104 s to 41 s under the profiler; agent views no longer re-walk each base's moves. - project.ts #closed opens unions down to their closed parts. An agent in a named draft has the draft's atoms over a closed shared base, one union deeper than #closed looked, so it walked all of shared's atoms and their dependencies. Tests: 97 of 97 across moves, relocation, projection-move-resolution, packed-files, view, drop, queued-moves, named-drafts, stored-closure, stored-membership, version-files, draft-reads-stored and writer storage. tsc clean.Compare320 // By the moved line's number, in the order its movers come (seq order, then each mover's moves).
321 const relocs = new Map<number, MoveEntry>();
322 for (const mover of skeleton.movers) {
323 if (!this.#has(mover.seq)) continue;
324 for (const n of mover.lines) {
325 if (!relocs.has(n)) relocs.set(n, pick(n)!);
capacity205Disk-first reads stop walking the whole history (disk-first 2, stage 1; abso Capacity). Shared's closure is kept on disk per version (spaces.ts indexClosure): the atoms a version needs beyond what it published, as events like membership's, with drops handled; views and Project.#closed trust a set marked closed, and over a closed stored base only a draft's own atoms are walked. A view resolves its moves once in memory (up to MOVED_LINES_KEPT, 20,000 moved lines) instead of again on disk for every file it lays out, and finds lines moved under a node from them. Graph.eachChildN skips the per-line children lookup when the paged child counts say none. On game's export (writer adopted, lock held): shared() went from not finishing in 8 minutes to 9-13 s cold and 0.15-0.25 s warm, 291,000 queries to 57,000; pathsAt(head) 0.1-0.2 s.Compare326 if (graph.hasOrderedChildren && relocs.size > MOVED_LINES_KEPT) throw new TooManyMoves();
init0Start the project327 }
328 }
capacity215Moves resolved over the moved lines alone, and closure over a named draft's own atoms (disk-first 2; abso Capacity), for abso's status and drafts. - view.ts MoveSkeleton: once per graph, and extended as it grows, each mover's moved lines, each moved line's relocations, and for any node the nearest node above it that a move ever relocated (or its file's start), memoised up to 200,000 nodes. A view's relocations and its loop check now hop between moved lines instead of walking every moved line's file up to its start, and fileOf hops the same way. The per-view location memos are gone. On abso's export (1,687 moved lines, 972 movers), status went from 104 s to 41 s under the profiler; agent views no longer re-walk each base's moves. - project.ts #closed opens unions down to their closed parts. An agent in a named draft has the draft's atoms over a closed shared base, one union deeper than #closed looked, so it walked all of shared's atoms and their dependencies. Tests: 97 of 97 across moves, relocation, projection-move-resolution, packed-files, view, drop, queued-moves, named-drafts, stored-closure, stored-membership, version-files, draft-reads-stored and writer storage. tsc clean.Compare329 // From a node, the next node that matters for loops: a line moved in this set, or a file's start.
330 const hop = (code: number): number => {
331 let c = skeleton.climb(code);
332 while (c >= 0 && !relocs.has(c)) c = skeleton.climb(graph.parentCodeOf(c));
333 return c;
334 };
335 const step = (n: number): number => {
336 const e = relocs.get(n);
337 return hop(e ? e.parent : graph.parentCodeOf(n));
338 };
339 // Two moves made apart can loop lines into each other, so no start node reaches them; then the oldest
340 // relocation on the loop is ignored, and the next newest of that line counts, until none loop.
341 const reaches = new Set<number>();
init0Start the project342 for (const line of [...relocs.keys()]) {
343 for (;;) {
capacity215Moves resolved over the moved lines alone, and closure over a named draft's own atoms (disk-first 2; abso Capacity), for abso's status and drafts. - view.ts MoveSkeleton: once per graph, and extended as it grows, each mover's moved lines, each moved line's relocations, and for any node the nearest node above it that a move ever relocated (or its file's start), memoised up to 200,000 nodes. A view's relocations and its loop check now hop between moved lines instead of walking every moved line's file up to its start, and fileOf hops the same way. The per-view location memos are gone. On abso's export (1,687 moved lines, 972 movers), status went from 104 s to 41 s under the profiler; agent views no longer re-walk each base's moves. - project.ts #closed opens unions down to their closed parts. An agent in a named draft has the draft's atoms over a closed shared base, one union deeper than #closed looked, so it walked all of shared's atoms and their dependencies. Tests: 97 of 97 across moves, relocation, projection-move-resolution, packed-files, view, drop, queued-moves, named-drafts, stored-closure, stored-membership, version-files, draft-reads-stored and writer storage. tsc clean.Compare344 const path: number[] = [];
345 const onPath = new Map<number, number>();
346 let cur = line;
init0Start the project347 let loopAt = -1;
capacity215Moves resolved over the moved lines alone, and closure over a named draft's own atoms (disk-first 2; abso Capacity), for abso's status and drafts. - view.ts MoveSkeleton: once per graph, and extended as it grows, each mover's moved lines, each moved line's relocations, and for any node the nearest node above it that a move ever relocated (or its file's start), memoised up to 200,000 nodes. A view's relocations and its loop check now hop between moved lines instead of walking every moved line's file up to its start, and fileOf hops the same way. The per-view location memos are gone. On abso's export (1,687 moved lines, 972 movers), status went from 104 s to 41 s under the profiler; agent views no longer re-walk each base's moves. - project.ts #closed opens unions down to their closed parts. An agent in a named draft has the draft's atoms over a closed shared base, one union deeper than #closed looked, so it walked all of shared's atoms and their dependencies. Tests: 97 of 97 across moves, relocation, projection-move-resolution, packed-files, view, drop, queued-moves, named-drafts, stored-closure, stored-membership, version-files, draft-reads-stored and writer storage. tsc clean.Compare348 while (cur >= 0 && !reaches.has(cur)) {
init0Start the project349 const at = onPath.get(cur);
350 if (at !== undefined) {
351 loopAt = at;
352 break;
353 }
354 onPath.set(cur, path.length);
355 path.push(cur);
capacity215Moves resolved over the moved lines alone, and closure over a named draft's own atoms (disk-first 2; abso Capacity), for abso's status and drafts. - view.ts MoveSkeleton: once per graph, and extended as it grows, each mover's moved lines, each moved line's relocations, and for any node the nearest node above it that a move ever relocated (or its file's start), memoised up to 200,000 nodes. A view's relocations and its loop check now hop between moved lines instead of walking every moved line's file up to its start, and fileOf hops the same way. The per-view location memos are gone. On abso's export (1,687 moved lines, 972 movers), status went from 104 s to 41 s under the profiler; agent views no longer re-walk each base's moves. - project.ts #closed opens unions down to their closed parts. An agent in a named draft has the draft's atoms over a closed shared base, one union deeper than #closed looked, so it walked all of shared's atoms and their dependencies. Tests: 97 of 97 across moves, relocation, projection-move-resolution, packed-files, view, drop, queued-moves, named-drafts, stored-closure, stored-membership, version-files, draft-reads-stored and writer storage. tsc clean.Compare356 cur = step(cur);
init0Start the project357 }
358 if (loopAt < 0) {
359 for (const l of path) reaches.add(l);
360 break;
361 }
capacity215Moves resolved over the moved lines alone, and closure over a named draft's own atoms (disk-first 2; abso Capacity), for abso's status and drafts. - view.ts MoveSkeleton: once per graph, and extended as it grows, each mover's moved lines, each moved line's relocations, and for any node the nearest node above it that a move ever relocated (or its file's start), memoised up to 200,000 nodes. A view's relocations and its loop check now hop between moved lines instead of walking every moved line's file up to its start, and fileOf hops the same way. The per-view location memos are gone. On abso's export (1,687 moved lines, 972 movers), status went from 104 s to 41 s under the profiler; agent views no longer re-walk each base's moves. - project.ts #closed opens unions down to their closed parts. An agent in a named draft has the draft's atoms over a closed shared base, one union deeper than #closed looked, so it walked all of shared's atoms and their dependencies. Tests: 97 of 97 across moves, relocation, projection-move-resolution, packed-files, view, drop, queued-moves, named-drafts, stored-closure, stored-membership, version-files, draft-reads-stored and writer storage. tsc clean.Compare362 let weakest: MoveEntry | undefined;
init0Start the project363 for (const l of path.slice(loopAt)) {
capacity215Moves resolved over the moved lines alone, and closure over a named draft's own atoms (disk-first 2; abso Capacity), for abso's status and drafts. - view.ts MoveSkeleton: once per graph, and extended as it grows, each mover's moved lines, each moved line's relocations, and for any node the nearest node above it that a move ever relocated (or its file's start), memoised up to 200,000 nodes. A view's relocations and its loop check now hop between moved lines instead of walking every moved line's file up to its start, and fileOf hops the same way. The per-view location memos are gone. On abso's export (1,687 moved lines, 972 movers), status went from 104 s to 41 s under the profiler; agent views no longer re-walk each base's moves. - project.ts #closed opens unions down to their closed parts. An agent in a named draft has the draft's atoms over a closed shared base, one union deeper than #closed looked, so it walked all of shared's atoms and their dependencies. Tests: 97 of 97 across moves, relocation, projection-move-resolution, packed-files, view, drop, queued-moves, named-drafts, stored-closure, stored-membership, version-files, draft-reads-stored and writer storage. tsc clean.Compare364 const e = relocs.get(l);
365 if (e && (!weakest || stronger(weakest.r, e.r))) weakest = e;
init0Start the project366 }
capacity215Moves resolved over the moved lines alone, and closure over a named draft's own atoms (disk-first 2; abso Capacity), for abso's status and drafts. - view.ts MoveSkeleton: once per graph, and extended as it grows, each mover's moved lines, each moved line's relocations, and for any node the nearest node above it that a move ever relocated (or its file's start), memoised up to 200,000 nodes. A view's relocations and its loop check now hop between moved lines instead of walking every moved line's file up to its start, and fileOf hops the same way. The per-view location memos are gone. On abso's export (1,687 moved lines, 972 movers), status went from 104 s to 41 s under the profiler; agent views no longer re-walk each base's moves. - project.ts #closed opens unions down to their closed parts. An agent in a named draft has the draft's atoms over a closed shared base, one union deeper than #closed looked, so it walked all of shared's atoms and their dependencies. Tests: 97 of 97 across moves, relocation, projection-move-resolution, packed-files, view, drop, queued-moves, named-drafts, stored-closure, stored-membership, version-files, draft-reads-stored and writer storage. tsc clean.Compare367 ignored.add(identity(weakest!.r));
368 const next = pick(weakest!.n);
369 if (next) relocs.set(weakest!.n, next);
370 else relocs.delete(weakest!.n);
init0Start the project371 }
372 }
capacity215Moves resolved over the moved lines alone, and closure over a named draft's own atoms (disk-first 2; abso Capacity), for abso's status and drafts. - view.ts MoveSkeleton: once per graph, and extended as it grows, each mover's moved lines, each moved line's relocations, and for any node the nearest node above it that a move ever relocated (or its file's start), memoised up to 200,000 nodes. A view's relocations and its loop check now hop between moved lines instead of walking every moved line's file up to its start, and fileOf hops the same way. The per-view location memos are gone. On abso's export (1,687 moved lines, 972 movers), status went from 104 s to 41 s under the profiler; agent views no longer re-walk each base's moves. - project.ts #closed opens unions down to their closed parts. An agent in a named draft has the draft's atoms over a closed shared base, one union deeper than #closed looked, so it walked all of shared's atoms and their dependencies. Tests: 97 of 97 across moves, relocation, projection-move-resolution, packed-files, view, drop, queued-moves, named-drafts, stored-closure, stored-membership, version-files, draft-reads-stored and writer storage. tsc clean.Compare373 this.#relocsN = new Map([...relocs].map(([n, e]) => [n, { r: e.r, parent: e.parent }]));
374 this.#relocs = new Map([...relocs.values()].map((e) => [e.r.line, e.r]));
375 return this.#relocs;
init0Start the project376 }
capacity207Each shared version's changed files kept as it lands (disk-first 2; abso Capacity, version-files.ts). A version's files are decided from what it touched: visible lines in and out per file, their texts' balance, a running count of each file's visible lines for made and taken out, and mode and blob; a version with moves, drops or a closure change, or whose lines in and out have the same texts, is laid out as before. Views of consecutive versions share resolved moves and where lines sit (View.shareMoves). PathIndex.keep records them, into the shapes table when the host gives one. version-files.test.ts checks log, path logs and every show against the in-memory project through edits, new and removed files, same text put back, a move and a drop. On game's export all 27 harness answers now match Project.load: the log 70 ms (was over 30 s), a path's history 0.56 s (was over 30 s), the tree 3.1-3.4 s (was over 30 s); adoption about 85 s; heap 14.4 MB at most.Compare377
capacity216Moves picked as walks reach them, and shared's file list from kept shapes (disk-first 2; abso Capacity), for abso's status, drafts and file list. - view.ts: a view picks a moved line's relocation only when a walk to find a line's file reaches that line. That is #relocations' own pick, right whenever the walk goes on to a file's start, since only lines on a loop have their relocation set aside; a walk that comes back to a line it passed resolves every move as before. shareMoves now takes the other view's moves only when this view first needs all of them, such as for a layout, so a view that only finds a few lines' files never resolves them. weight() counts the picks. - pathindex.ts keptPaths: shared's files at a version, folded from version 0 over each version's kept files made and taken out, with no file laid out. Only on a stored writer, and only when every version up to it has a kept row that describes it; otherwise the version is laid out as before. pathsAt uses it. On abso's export (81,855 entries, 1,224 versions), one opened project, answers matching Project.load: - status: 104 s to 5.8 s (under the profiler) - drafts: over 60 s to 5.7 s - files at head: over 60 s to 1.2 s - files at 612: 54 s to 0.3 s version-files.test.ts now also checks the file list at every version against the in-memory project. 124 of 124 related tests pass; tsc clean.Compare378 /** The view whose moves this one may take, until it needs them all; then the view it took them from. */
379 #movesFrom: View | undefined;
380 #movesTaken: View | undefined;
capacity207Each shared version's changed files kept as it lands (disk-first 2; abso Capacity, version-files.ts). A version's files are decided from what it touched: visible lines in and out per file, their texts' balance, a running count of each file's visible lines for made and taken out, and mode and blob; a version with moves, drops or a closure change, or whose lines in and out have the same texts, is laid out as before. Views of consecutive versions share resolved moves and where lines sit (View.shareMoves). PathIndex.keep records them, into the shapes table when the host gives one. version-files.test.ts checks log, path logs and every show against the in-memory project through edits, new and removed files, same text put back, a move and a drop. On game's export all 27 harness answers now match Project.load: the log 70 ms (was over 30 s), a path's history 0.56 s (was over 30 s), the tree 3.1-3.4 s (was over 30 s); adoption about 85 s; heap 14.4 MB at most.Compare382 /**
capacity212Draft reads on a stored writer (disk-first 2; abso Capacity): where, drafts, status and collisions on website's export. - where looks deleted lines up by number (graph.deletedNumbers, View.fileOfNumber, View.lineNumberOf). It takes the agent's view once instead of once per line, since each read weighed every cached view. It finds the draft's lines by writer (View.visibleWriters), with no text or id read per line. - Draft files (overlaps.ts) go by number the same way. - An agent's view takes its base's resolved moves when both hold the same atoms that move lines (View.shareMoves checks this). - Draft collisions: - build the union view only when two drafts share a file; - work out each agent's touched files and its "shared now plus draft" view once; - find claimants among the drafts from the drafts' own keys (collisions.ts claimantsAmong) instead of walking each key's history; - have the definition rule keep a draft's uses, and the newer work's definitions, across partners. - A stored list read in order reads its length once, not before every element. draft-reads-stored.test.ts checks where and collisions against the in-memory project. It covers edits, a whole file deleted, a line collision, one name defined twice, and bases before and after a move. 135 of 136 related tests pass; none fail. On website's export (1,387 entries) the answers match Project.load: - status: 17 s to 4.5 s - where: over 60 s to 8.8 s - drafts: 14 s to 5.3 s - collisions: over 60 s to 54 s, measured under the profiler before the last two changesCompare383 * Take another view's resolved moves (abso Capacity), when both sets hold the very same atoms that move lines: the
capacity216Moves picked as walks reach them, and shared's file list from kept shapes (disk-first 2; abso Capacity), for abso's status, drafts and file list. - view.ts: a view picks a moved line's relocation only when a walk to find a line's file reaches that line. That is #relocations' own pick, right whenever the walk goes on to a file's start, since only lines on a loop have their relocation set aside; a walk that comes back to a line it passed resolves every move as before. shareMoves now takes the other view's moves only when this view first needs all of them, such as for a layout, so a view that only finds a few lines' files never resolves them. weight() counts the picks. - pathindex.ts keptPaths: shared's files at a version, folded from version 0 over each version's kept files made and taken out, with no file laid out. Only on a stored writer, and only when every version up to it has a kept row that describes it; otherwise the version is laid out as before. pathsAt uses it. On abso's export (81,855 entries, 1,224 versions), one opened project, answers matching Project.load: - status: 104 s to 5.8 s (under the profiler) - drafts: over 60 s to 5.7 s - files at head: over 60 s to 1.2 s - files at 612: 54 s to 0.3 s version-files.test.ts now also checks the file list at every version against the in-memory project. 124 of 124 related tests pass; tsc clean.Compare384 * moves then resolve the same, and every line sits where it sits there. Checked when this view first needs all its
385 * moves, so any caller may ask, and a view that only finds a few lines' files never resolves them.
capacity207Each shared version's changed files kept as it lands (disk-first 2; abso Capacity, version-files.ts). A version's files are decided from what it touched: visible lines in and out per file, their texts' balance, a running count of each file's visible lines for made and taken out, and mode and blob; a version with moves, drops or a closure change, or whose lines in and out have the same texts, is laid out as before. Views of consecutive versions share resolved moves and where lines sit (View.shareMoves). PathIndex.keep records them, into the shapes table when the host gives one. version-files.test.ts checks log, path logs and every show against the in-memory project through edits, new and removed files, same text put back, a move and a drop. On game's export all 27 harness answers now match Project.load: the log 70 ms (was over 30 s), a path's history 0.56 s (was over 30 s), the tree 3.1-3.4 s (was over 30 s); adoption about 85 s; heap 14.4 MB at most.Compare386 */
387 shareMoves(from: View): void {
capacity216Moves picked as walks reach them, and shared's file list from kept shapes (disk-first 2; abso Capacity), for abso's status, drafts and file list. - view.ts: a view picks a moved line's relocation only when a walk to find a line's file reaches that line. That is #relocations' own pick, right whenever the walk goes on to a file's start, since only lines on a loop have their relocation set aside; a walk that comes back to a line it passed resolves every move as before. shareMoves now takes the other view's moves only when this view first needs all of them, such as for a layout, so a view that only finds a few lines' files never resolves them. weight() counts the picks. - pathindex.ts keptPaths: shared's files at a version, folded from version 0 over each version's kept files made and taken out, with no file laid out. Only on a stored writer, and only when every version up to it has a kept row that describes it; otherwise the version is laid out as before. pathsAt uses it. On abso's export (81,855 entries, 1,224 versions), one opened project, answers matching Project.load: - status: 104 s to 5.8 s (under the profiler) - drafts: over 60 s to 5.7 s - files at head: over 60 s to 1.2 s - files at 612: 54 s to 0.3 s version-files.test.ts now also checks the file list at every version against the in-memory project. 124 of 124 related tests pass; tsc clean.Compare388 if (from.graph !== this.graph || from.#hasMoves !== this.#hasMoves || !this.#hasMoves || this.#relocs) return;
389 this.#movesFrom = from;
390 }
392 #takeShared(): void {
393 const from = this.#movesFrom;
394 if (!from) return;
395 this.#movesFrom = undefined;
396 if (from.#scratchMoves()) return;
capacity212Draft reads on a stored writer (disk-first 2; abso Capacity): where, drafts, status and collisions on website's export. - where looks deleted lines up by number (graph.deletedNumbers, View.fileOfNumber, View.lineNumberOf). It takes the agent's view once instead of once per line, since each read weighed every cached view. It finds the draft's lines by writer (View.visibleWriters), with no text or id read per line. - Draft files (overlaps.ts) go by number the same way. - An agent's view takes its base's resolved moves when both hold the same atoms that move lines (View.shareMoves checks this). - Draft collisions: - build the union view only when two drafts share a file; - work out each agent's touched files and its "shared now plus draft" view once; - find claimants among the drafts from the drafts' own keys (collisions.ts claimantsAmong) instead of walking each key's history; - have the definition rule keep a draft's uses, and the newer work's definitions, across partners. - A stored list read in order reads its length once, not before every element. draft-reads-stored.test.ts checks where and collisions against the in-memory project. It covers edits, a whole file deleted, a line collision, one name defined twice, and bases before and after a move. 135 of 136 related tests pass; none fail. On website's export (1,387 entries) the answers match Project.load: - status: 17 s to 4.5 s - where: over 60 s to 8.8 s - drafts: 14 s to 5.3 s - collisions: over 60 s to 54 s, measured under the profiler before the last two changesCompare397 for (const id of this.graph.movers()) {
398 const seq = seqOf(id);
399 if (this.#has(seq) !== from.#has(seq)) return;
400 }
capacity207Each shared version's changed files kept as it lands (disk-first 2; abso Capacity, version-files.ts). A version's files are decided from what it touched: visible lines in and out per file, their texts' balance, a running count of each file's visible lines for made and taken out, and mode and blob; a version with moves, drops or a closure change, or whose lines in and out have the same texts, is laid out as before. Views of consecutive versions share resolved moves and where lines sit (View.shareMoves). PathIndex.keep records them, into the shapes table when the host gives one. version-files.test.ts checks log, path logs and every show against the in-memory project through edits, new and removed files, same text put back, a move and a drop. On game's export all 27 harness answers now match Project.load: the log 70 ms (was over 30 s), a path's history 0.56 s (was over 30 s), the tree 3.1-3.4 s (was over 30 s); adoption about 85 s; heap 14.4 MB at most.Compare401 this.#relocs = from.#relocations();
402 this.#relocsN = from.#relocationsN();
403 this.#movesOnDisk = false;
capacity216Moves picked as walks reach them, and shared's file list from kept shapes (disk-first 2; abso Capacity), for abso's status, drafts and file list. - view.ts: a view picks a moved line's relocation only when a walk to find a line's file reaches that line. That is #relocations' own pick, right whenever the walk goes on to a file's start, since only lines on a loop have their relocation set aside; a walk that comes back to a line it passed resolves every move as before. shareMoves now takes the other view's moves only when this view first needs all of them, such as for a layout, so a view that only finds a few lines' files never resolves them. weight() counts the picks. - pathindex.ts keptPaths: shared's files at a version, folded from version 0 over each version's kept files made and taken out, with no file laid out. Only on a stored writer, and only when every version up to it has a kept row that describes it; otherwise the version is laid out as before. pathsAt uses it. On abso's export (81,855 entries, 1,224 versions), one opened project, answers matching Project.load: - status: 104 s to 5.8 s (under the profiler) - drafts: over 60 s to 5.7 s - files at head: over 60 s to 1.2 s - files at 612: 54 s to 0.3 s version-files.test.ts now also checks the file list at every version against the in-memory project. 124 of 124 related tests pass; tsc clean.Compare404 this.#movesTaken = from;
capacity207Each shared version's changed files kept as it lands (disk-first 2; abso Capacity, version-files.ts). A version's files are decided from what it touched: visible lines in and out per file, their texts' balance, a running count of each file's visible lines for made and taken out, and mode and blob; a version with moves, drops or a closure change, or whose lines in and out have the same texts, is laid out as before. Views of consecutive versions share resolved moves and where lines sit (View.shareMoves). PathIndex.keep records them, into the shapes table when the host gives one. version-files.test.ts checks log, path logs and every show against the in-memory project through edits, new and removed files, same text put back, a move and a drop. On game's export all 27 harness answers now match Project.load: the log 70 ms (was over 30 s), a path's history 0.56 s (was over 30 s), the tree 3.1-3.4 s (was over 30 s); adoption about 85 s; heap 14.4 MB at most.Compare405 }
capacity216Moves picked as walks reach them, and shared's file list from kept shapes (disk-first 2; abso Capacity), for abso's status, drafts and file list. - view.ts: a view picks a moved line's relocation only when a walk to find a line's file reaches that line. That is #relocations' own pick, right whenever the walk goes on to a file's start, since only lines on a loop have their relocation set aside; a walk that comes back to a line it passed resolves every move as before. shareMoves now takes the other view's moves only when this view first needs all of them, such as for a layout, so a view that only finds a few lines' files never resolves them. weight() counts the picks. - pathindex.ts keptPaths: shared's files at a version, folded from version 0 over each version's kept files made and taken out, with no file laid out. Only on a stored writer, and only when every version up to it has a kept row that describes it; otherwise the version is laid out as before. pathsAt uses it. On abso's export (81,855 entries, 1,224 versions), one opened project, answers matching Project.load: - status: 104 s to 5.8 s (under the profiler) - drafts: over 60 s to 5.7 s - files at head: over 60 s to 1.2 s - files at 612: 54 s to 0.3 s version-files.test.ts now also checks the file list at every version against the in-memory project. 124 of 124 related tests pass; tsc clean.Compare406
407 /** Moved lines' relocations picked one at a time, before the view resolves them all (null: not moved here). */
408 readonly #picked = new Map<number, MoveEntry | null>();
capacity207Each shared version's changed files kept as it lands (disk-first 2; abso Capacity, version-files.ts). A version's files are decided from what it touched: visible lines in and out per file, their texts' balance, a running count of each file's visible lines for made and taken out, and mode and blob; a version with moves, drops or a closure change, or whose lines in and out have the same texts, is laid out as before. Views of consecutive versions share resolved moves and where lines sit (View.shareMoves). PathIndex.keep records them, into the shapes table when the host gives one. version-files.test.ts checks log, path logs and every show against the in-memory project through edits, new and removed files, same text put back, a move and a drop. On game's export all 27 harness answers now match Project.load: the log 70 ms (was over 30 s), a path's history 0.56 s (was over 30 s), the tree 3.1-3.4 s (was over 30 s); adoption about 85 s; heap 14.4 MB at most.Compare409
capacity216Moves picked as walks reach them, and shared's file list from kept shapes (disk-first 2; abso Capacity), for abso's status, drafts and file list. - view.ts: a view picks a moved line's relocation only when a walk to find a line's file reaches that line. That is #relocations' own pick, right whenever the walk goes on to a file's start, since only lines on a loop have their relocation set aside; a walk that comes back to a line it passed resolves every move as before. shareMoves now takes the other view's moves only when this view first needs all of them, such as for a layout, so a view that only finds a few lines' files never resolves them. weight() counts the picks. - pathindex.ts keptPaths: shared's files at a version, folded from version 0 over each version's kept files made and taken out, with no file laid out. Only on a stored writer, and only when every version up to it has a kept row that describes it; otherwise the version is laid out as before. pathsAt uses it. On abso's export (81,855 entries, 1,224 versions), one opened project, answers matching Project.load: - status: 104 s to 5.8 s (under the profiler) - drafts: over 60 s to 5.7 s - files at head: over 60 s to 1.2 s - files at 612: 54 s to 0.3 s version-files.test.ts now also checks the file list at every version against the in-memory project. 124 of 124 related tests pass; tsc clean.Compare410 /**
411 * The relocation of moved line n that counts here, as #relocations picks it before any loop: right whenever the
412 * walk that reached n goes on to a file's start, since only lines on a loop have their relocation set aside.
413 */
414 #pickOne(n: number): MoveEntry | undefined {
415 let picked = this.#picked.get(n);
416 if (picked === undefined) {
417 const graph = this.graph;
418 let best: MoveEntry | undefined;
419 for (const e of skeletonOf(graph).byLine.get(n) ?? []) {
420 if (this.#has(seqOf(e.r.atom)) && (!best || graph.comparePriority(e.r.atom, best.r.atom) > 0)) best = e;
421 }
422 this.#picked.set(n, (picked = best ?? null));
423 }
424 return picked ?? undefined;
425 }
capacity205Disk-first reads stop walking the whole history (disk-first 2, stage 1; abso Capacity). Shared's closure is kept on disk per version (spaces.ts indexClosure): the atoms a version needs beyond what it published, as events like membership's, with drops handled; views and Project.#closed trust a set marked closed, and over a closed stored base only a draft's own atoms are walked. A view resolves its moves once in memory (up to MOVED_LINES_KEPT, 20,000 moved lines) instead of again on disk for every file it lays out, and finds lines moved under a node from them. Graph.eachChildN skips the per-line children lookup when the paged child counts say none. On game's export (writer adopted, lock held): shared() went from not finishing in 8 minutes to 9-13 s cold and 0.15-0.25 s warm, 291,000 queries to 57,000; pathsAt(head) 0.1-0.2 s.Compare427 /** Whether moves are resolved on disk for each layout: only a stored graph's view with more than MOVED_LINES_KEPT. */
428 #scratchMoves(): boolean {
429 if (!this.#hasMoves || !this.graph.hasOrderedChildren) return false;
430 if (this.#movesOnDisk === undefined) {
431 try {
432 this.#relocations();
433 this.#movesOnDisk = false;
434 } catch (error) {
435 if (!(error instanceof TooManyMoves)) throw error;
436 this.#movesOnDisk = true;
437 }
438 }
439 return this.#movesOnDisk;
440 }
init0Start the project442 /** The relocations by n, with each new parent's code. */
443 #relocationsN(): Map<number, { readonly r: RelocationInfo; readonly parent: number }> {
444 if (this.#relocsN) return this.#relocsN;
445 const out = new Map<number, { readonly r: RelocationInfo; readonly parent: number }>();
446 for (const [line, r] of this.#relocations())
447 out.set(this.graph.lineN(line), { r, parent: this.graph.codeOf(r.parent)! });
448 this.#relocsN = out;
449 return out;
450 }
452 /** The node a line hangs off in this set: where it was written, or where a move put it. */
453 parentOf(line: LineId): NodeId {
codex-capacity-chair132Bound persistent relocation projection memory with rollback-only scratchCompare454 if (this.graph.lineParent(line) === undefined) throw new EngineError("unknown-line", `no line ${line}`);
capacity205Disk-first reads stop walking the whole history (disk-first 2, stage 1; abso Capacity). Shared's closure is kept on disk per version (spaces.ts indexClosure): the atoms a version needs beyond what it published, as events like membership's, with drops handled; views and Project.#closed trust a set marked closed, and over a closed stored base only a draft's own atoms are walked. A view resolves its moves once in memory (up to MOVED_LINES_KEPT, 20,000 moved lines) instead of again on disk for every file it lays out, and finds lines moved under a node from them. Graph.eachChildN skips the per-line children lookup when the paged child counts say none. On game's export (writer adopted, lock held): shared() went from not finishing in 8 minutes to 9-13 s cold and 0.15-0.25 s warm, 291,000 queries to 57,000; pathsAt(head) 0.1-0.2 s.Compare455 if (this.#scratchMoves())
codex-capacity-chair132Bound persistent relocation projection memory with rollback-only scratchCompare456 return this.graph.withProjectionScratch((scratch) =>
457 resolveScratchMoves(this.graph, (id) => this.#has(this.graph.atom(id).seq), scratch).parent(line),
458 );
codex-capacity-chair123Stream mover history when opening persisted viewsCompare459 const r = this.#hasMoves ? this.#relocations().get(line) : undefined;
init0Start the project460 if (r) return r.parent;
461 const parent = this.graph.lineParent(line);
462 if (parent === undefined) throw new EngineError("unknown-line", `no line ${line}`);
463 return parent;
464 }
466 /** Whether any atom in the set moves lines. */
467 hasMoves(): boolean {
codex-capacity-chair123Stream mover history when opening persisted viewsCompare468 return this.#hasMoves;
init0Start the project469 }
471 /** The file a line is in, in this set: the one its chain of parents reaches. */
472 fileOf(line: LineId): string {
473 const n = this.graph.lineN(line);
474 if (n < 0) throw new EngineError("unknown-line", `no line ${line}`);
475 return this.#fileOfN(n);
476 }
478 #fileOfN(n: number): string {
479 const graph = this.graph;
codex-capacity-chair123Stream mover history when opening persisted viewsCompare480 if (!this.#hasMoves) return graph.writtenIn(n);
capacity205Disk-first reads stop walking the whole history (disk-first 2, stage 1; abso Capacity). Shared's closure is kept on disk per version (spaces.ts indexClosure): the atoms a version needs beyond what it published, as events like membership's, with drops handled; views and Project.#closed trust a set marked closed, and over a closed stored base only a draft's own atoms are walked. A view resolves its moves once in memory (up to MOVED_LINES_KEPT, 20,000 moved lines) instead of again on disk for every file it lays out, and finds lines moved under a node from them. Graph.eachChildN skips the per-line children lookup when the paged child counts say none. On game's export (writer adopted, lock held): shared() went from not finishing in 8 minutes to 9-13 s cold and 0.15-0.25 s warm, 291,000 queries to 57,000; pathsAt(head) 0.1-0.2 s.Compare481 if (this.#scratchMoves())
codex-capacity-chair132Bound persistent relocation projection memory with rollback-only scratchCompare482 return graph.withProjectionScratch((scratch) => {
483 const moves = resolveScratchMoves(graph, (id) => this.#has(graph.atom(id).seq), scratch);
484 let current = graph.nodeOf(n);
485 while (!isStartNode(current)) current = moves.parent(current);
486 return current.slice(1);
487 });
capacity215Moves resolved over the moved lines alone, and closure over a named draft's own atoms (disk-first 2; abso Capacity), for abso's status and drafts. - view.ts MoveSkeleton: once per graph, and extended as it grows, each mover's moved lines, each moved line's relocations, and for any node the nearest node above it that a move ever relocated (or its file's start), memoised up to 200,000 nodes. A view's relocations and its loop check now hop between moved lines instead of walking every moved line's file up to its start, and fileOf hops the same way. The per-view location memos are gone. On abso's export (1,687 moved lines, 972 movers), status went from 104 s to 41 s under the profiler; agent views no longer re-walk each base's moves. - project.ts #closed opens unions down to their closed parts. An agent in a named draft has the draft's atoms over a closed shared base, one union deeper than #closed looked, so it walked all of shared's atoms and their dependencies. Tests: 97 of 97 across moves, relocation, projection-move-resolution, packed-files, view, drop, queued-moves, named-drafts, stored-closure, stored-membership, version-files, draft-reads-stored and writer storage. tsc clean.Compare488 return this.#fileOfCode(n);
489 }
491 /** The file a node sits in, in this set: up by where lines were written, through the moves that count here. */
492 #fileOfCode(code: number): string {
493 const graph = this.graph;
494 const skeleton = skeletonOf(graph);
capacity216Moves picked as walks reach them, and shared's file list from kept shapes (disk-first 2; abso Capacity), for abso's status, drafts and file list. - view.ts: a view picks a moved line's relocation only when a walk to find a line's file reaches that line. That is #relocations' own pick, right whenever the walk goes on to a file's start, since only lines on a loop have their relocation set aside; a walk that comes back to a line it passed resolves every move as before. shareMoves now takes the other view's moves only when this view first needs all of them, such as for a layout, so a view that only finds a few lines' files never resolves them. weight() counts the picks. - pathindex.ts keptPaths: shared's files at a version, folded from version 0 over each version's kept files made and taken out, with no file laid out. Only on a stored writer, and only when every version up to it has a kept row that describes it; otherwise the version is laid out as before. pathsAt uses it. On abso's export (81,855 entries, 1,224 versions), one opened project, answers matching Project.load: - status: 104 s to 5.8 s (under the profiler) - drafts: over 60 s to 5.7 s - files at head: over 60 s to 1.2 s - files at 612: 54 s to 0.3 s version-files.test.ts now also checks the file list at every version against the in-memory project. 124 of 124 related tests pass; tsc clean.Compare495 if (!this.#relocsN) {
496 // One moved line at a time, until a walk comes back to a line it passed: then moves loop, and are resolved whole.
497 const passed = new Set<number>();
498 let c = code;
499 for (;;) {
500 c = skeleton.climb(c);
501 if (c < 0) return graph.nodeOf(c).slice(1);
502 if (passed.has(c)) break;
503 passed.add(c);
504 const e = this.#pickOne(c);
505 c = e ? e.parent : graph.parentCodeOf(c);
506 }
507 }
init0Start the project508 const relocs = this.#relocationsN();
capacity215Moves resolved over the moved lines alone, and closure over a named draft's own atoms (disk-first 2; abso Capacity), for abso's status and drafts. - view.ts MoveSkeleton: once per graph, and extended as it grows, each mover's moved lines, each moved line's relocations, and for any node the nearest node above it that a move ever relocated (or its file's start), memoised up to 200,000 nodes. A view's relocations and its loop check now hop between moved lines instead of walking every moved line's file up to its start, and fileOf hops the same way. The per-view location memos are gone. On abso's export (1,687 moved lines, 972 movers), status went from 104 s to 41 s under the profiler; agent views no longer re-walk each base's moves. - project.ts #closed opens unions down to their closed parts. An agent in a named draft has the draft's atoms over a closed shared base, one union deeper than #closed looked, so it walked all of shared's atoms and their dependencies. Tests: 97 of 97 across moves, relocation, projection-move-resolution, packed-files, view, drop, queued-moves, named-drafts, stored-closure, stored-membership, version-files, draft-reads-stored and writer storage. tsc clean.Compare509 let c = code;
510 for (;;) {
511 c = skeleton.climb(c);
512 if (c < 0) return graph.nodeOf(c).slice(1);
513 const e = relocs.get(c);
514 c = e ? e.parent : graph.parentCodeOf(c);
init0Start the project515 }
516 }
518 /** The lines hanging off a node in this set, in layout order. */
519 #children(code: number): Child[] {
520 const graph = this.graph;
codex-capacity-chair123Stream mover history when opening persisted viewsCompare521 const relocs = this.#hasMoves ? this.#relocationsN() : undefined;
init0Start the project522 const out: Child[] = [];
codex-capacity-chair130Stream paged child history into layout filteringCompare523 for (const n of graph.eachChildN(code)) {
init0Start the project524 const seq = graph.writerSeqOf(n);
525 if (!this.#has(seq) || relocs?.has(n)) continue;
526 out.push({ n, replaces: graph.replacesN(n) ? 1 : 0, lamport: graph.lamportOfSeq(seq), seq, k: graph.kOf(n) });
527 }
528 if (relocs) {
capacity205Disk-first reads stop walking the whole history (disk-first 2, stage 1; abso Capacity). Shared's closure is kept on disk per version (spaces.ts indexClosure): the atoms a version needs beyond what it published, as events like membership's, with drops handled; views and Project.#closed trust a set marked closed, and over a closed stored base only a draft's own atoms are walked. A view resolves its moves once in memory (up to MOVED_LINES_KEPT, 20,000 moved lines) instead of again on disk for every file it lays out, and finds lines moved under a node from them. Graph.eachChildN skips the per-line children lookup when the paged child counts say none. On game's export (writer adopted, lock held): shared() went from not finishing in 8 minutes to 9-13 s cold and 0.15-0.25 s warm, 291,000 queries to 57,000; pathsAt(head) 0.1-0.2 s.Compare529 // The lines this set's moves put under each node, from the moves it already resolved: no row read per node
530 // (abso Capacity).
531 if (!this.#movedInto) {
532 this.#movedInto = new Map();
533 for (const [n, { parent }] of relocs) {
534 const into = this.#movedInto.get(parent);
535 if (into) into.push(n);
536 else this.#movedInto.set(parent, [n]);
537 }
538 }
539 for (const n of this.#movedInto.get(code) ?? NO_LINES) {
540 const r = relocs.get(n)!.r;
init0Start the project541 const seq = graph.atom(r.atom).seq;
542 out.push({ n, replaces: 0, lamport: graph.lamportOfSeq(seq), seq, k: r.k });
543 }
544 }
545 // A line's replacements (runs of atoms that deleted it) first, then the
546 // rest; each group in descending priority (lamport, then seq); lines of
547 // one atom keep k order. A replacement already outranks every insertion
548 // after the line that reads it (it depends on them, or conflicts with
549 // them); the grouping also puts it above a `before` insertion, which
550 // doesn't read the line above, so the new text lands in the replaced
551 // line's place. A moved line ranks like an insertion by the moving atom.
552 if (out.length > 1)
553 out.sort((a, b) => b.replaces - a.replaces || b.lamport - a.lamport || b.seq - a.seq || a.k - b.k);
554 return out;
555 }
codex-capacity-chair131Bound persisted no-move layout with ordered successor traversalCompare557 /** Parent/successor traversal keeps no history-sized ancestry or sibling frontier. */
558 *#layoutNodes(start: number): IterableIterator<number> {
559 const graph = this.graph;
560 if (graph.hasOrderedChildren && !this.#hasMoves) {
561 const first = (parent: number, after?: number): number | undefined => {
562 for (const n of graph.orderedChildrenN(parent, after)) if (this.#has(graph.writerSeqOf(n))) return n;
563 return undefined;
564 };
565 let n = first(start);
566 while (n !== undefined) {
567 yield n;
568 const child = first(n);
569 if (child !== undefined) {
570 n = child;
571 continue;
572 }
573 let previous = n;
574 for (;;) {
575 const parent = graph.parentCodeOf(previous);
576 const sibling = first(parent, previous);
577 if (sibling !== undefined) {
578 n = sibling;
579 break;
580 }
581 if (parent === start) {
582 n = undefined;
583 break;
584 }
585 if (parent < 0 || parent >= previous) throw new Error("invalid persistent layout ancestry");
586 previous = parent;
587 }
588 }
589 return;
590 }
init0Start the project591 const stack: number[] = [];
codex-capacity-chair131Bound persisted no-move layout with ordered successor traversalCompare592 const push = (parent: number): void => {
593 const children = this.#children(parent);
594 for (let i = children.length - 1; i >= 0; i--) stack.push(children[i]!.n);
595 };
596 push(start);
597 while (stack.length) {
598 const n = stack.pop()!;
599 yield n;
600 push(n);
601 }
602 }
init0Start the project604 /** Lay out one file: its line tree from the set's atoms, linearized. */
codex-capacity-chair110Keep current-file views and key scans from retaining historical stateCompare605 #layout(path: string, complete: boolean): FileState {
init0Start the project606 const graph = this.graph;
capacity221Packed layout follows lines written in another file (disk-first 2; abso Capacity). where {} on typescript-rs left 11 lines out of erasable_syntax.rs in cloud-ts-12's draft. cloud-ts-12 moved one block between files several times, wrote lines under its last line while it sat in uninitialized_props_forms.rs, then moved the block on. Those lines followed their parent with no move of their own. The packed layout read only the file's own lines and the files its moved-in lines were written in, so it never read them. - Each file's packed history also keeps the runs written in another file under one of its lines (file-crossings). The packed layout follows them until no new file turns up. - New adoptions write packed format 2. A graph packed at format 1 has no such list, so it lays files out line by line: correct, but slower until it is adopted again. - packed-crossings.test.ts moves c.ts to d.ts, adds a line in d.ts, moves d.ts to e.ts, and checks files, where and every draft's text against the in-memory project. Named tests: packed-crossings, packed-files, state-source, draft-reads-stored, version-files, project-writer-storage, writer-adoption, moves, queued-moves, files-reads, move-reconstruction (60 of 60); tsc and biome clean.Compare607 if (graph.packedLayout && !this.#scratchMoves()) return this.#layoutPacked(path, complete);
capacity205Disk-first reads stop walking the whole history (disk-first 2, stage 1; abso Capacity). Shared's closure is kept on disk per version (spaces.ts indexClosure): the atoms a version needs beyond what it published, as events like membership's, with drops handled; views and Project.#closed trust a set marked closed, and over a closed stored base only a draft's own atoms are walked. A view resolves its moves once in memory (up to MOVED_LINES_KEPT, 20,000 moved lines) instead of again on disk for every file it lays out, and finds lines moved under a node from them. Graph.eachChildN skips the per-line children lookup when the paged child counts say none. On game's export (writer adopted, lock held): shared() went from not finishing in 8 minutes to 9-13 s cold and 0.15-0.25 s warm, 291,000 queries to 57,000; pathsAt(head) 0.1-0.2 s.Compare608 if (this.#scratchMoves())
codex-capacity-chair132Bound persistent relocation projection memory with rollback-only scratchCompare609 return graph.withProjectionScratch((scratch) =>
610 this.#layoutResolved(
611 path,
612 complete,
613 scratchLayoutNodes(graph, (id) => this.#has(graph.atom(id).seq), scratch, `^${path}`),
614 ),
615 );
616 return this.#layoutResolved(path, complete);
617 }
capacity206Each file's line history packed (disk-first 2, lines by file; abso Capacity). A stored graph appends every line written in a file ([n, parent code, writer seq, k, replaces]) and its text, every delete of one of its lines, and every attribute set on it to that file's pages as atoms are added, a run at a time (storedLists appendAll). A view lays a file out from those pages in memory: membership checked once per atom, moves followed from the ones it already resolved, lines moved in from other files read from theirs. Same tree and order as before (packed-files.test.ts checks it against the in-memory graph through edits, deletes and moves). Graphs adopted before have no packs and lay out line by line as before; packFiles: false keeps that path for its tests. On game's export: first shared() 13 s to 2-3.6 s at 20,000 queries, warm 56-82 ms, pathsAt(head) 29-119 ms; files at a version 14 s to 3 s, compare 26 s to 11 s, a path's log 27 s to 4.5 s; every answer the harness finished matches Project.load.Compare619 /** For each path, the files that lines moved into it were written in: worked out once per view. */
620 #movedFrom: Map<string, Set<number>> | undefined;
621 #movedInFrom(): Map<string, Set<number>> {
622 if (this.#movedFrom) return this.#movedFrom;
capacity216Moves picked as walks reach them, and shared's file list from kept shapes (disk-first 2; abso Capacity), for abso's status, drafts and file list. - view.ts: a view picks a moved line's relocation only when a walk to find a line's file reaches that line. That is #relocations' own pick, right whenever the walk goes on to a file's start, since only lines on a loop have their relocation set aside; a walk that comes back to a line it passed resolves every move as before. shareMoves now takes the other view's moves only when this view first needs all of them, such as for a layout, so a view that only finds a few lines' files never resolves them. weight() counts the picks. - pathindex.ts keptPaths: shared's files at a version, folded from version 0 over each version's kept files made and taken out, with no file laid out. Only on a stored writer, and only when every version up to it has a kept row that describes it; otherwise the version is laid out as before. pathsAt uses it. On abso's export (81,855 entries, 1,224 versions), one opened project, answers matching Project.load: - status: 104 s to 5.8 s (under the profiler) - drafts: over 60 s to 5.7 s - files at head: over 60 s to 1.2 s - files at 612: 54 s to 0.3 s version-files.test.ts now also checks the file list at every version against the in-memory project. 124 of 124 related tests pass; tsc clean.Compare623 this.#relocations();
624 if (this.#movesTaken) return (this.#movedFrom = this.#movesTaken.#movedInFrom());
capacity206Each file's line history packed (disk-first 2, lines by file; abso Capacity). A stored graph appends every line written in a file ([n, parent code, writer seq, k, replaces]) and its text, every delete of one of its lines, and every attribute set on it to that file's pages as atoms are added, a run at a time (storedLists appendAll). A view lays a file out from those pages in memory: membership checked once per atom, moves followed from the ones it already resolved, lines moved in from other files read from theirs. Same tree and order as before (packed-files.test.ts checks it against the in-memory graph through edits, deletes and moves). Graphs adopted before have no packs and lay out line by line as before; packFiles: false keeps that path for its tests. On game's export: first shared() 13 s to 2-3.6 s at 20,000 queries, warm 56-82 ms, pathsAt(head) 29-119 ms; files at a version 14 s to 3 s, compare 26 s to 11 s, a path's log 27 s to 4.5 s; every answer the harness finished matches Project.load.Compare625 const graph = this.graph;
626 const out = new Map<string, Set<number>>();
627 if (this.#hasMoves) {
628 const relocs = this.#relocationsN();
capacity215Moves resolved over the moved lines alone, and closure over a named draft's own atoms (disk-first 2; abso Capacity), for abso's status and drafts. - view.ts MoveSkeleton: once per graph, and extended as it grows, each mover's moved lines, each moved line's relocations, and for any node the nearest node above it that a move ever relocated (or its file's start), memoised up to 200,000 nodes. A view's relocations and its loop check now hop between moved lines instead of walking every moved line's file up to its start, and fileOf hops the same way. The per-view location memos are gone. On abso's export (1,687 moved lines, 972 movers), status went from 104 s to 41 s under the profiler; agent views no longer re-walk each base's moves. - project.ts #closed opens unions down to their closed parts. An agent in a named draft has the draft's atoms over a closed shared base, one union deeper than #closed looked, so it walked all of shared's atoms and their dependencies. Tests: 97 of 97 across moves, relocation, projection-move-resolution, packed-files, view, drop, queued-moves, named-drafts, stored-closure, stored-membership, version-files, draft-reads-stored and writer storage. tsc clean.Compare629 const fileOf = (code: number): string => this.#fileOfCode(code);
capacity206Each file's line history packed (disk-first 2, lines by file; abso Capacity). A stored graph appends every line written in a file ([n, parent code, writer seq, k, replaces]) and its text, every delete of one of its lines, and every attribute set on it to that file's pages as atoms are added, a run at a time (storedLists appendAll). A view lays a file out from those pages in memory: membership checked once per atom, moves followed from the ones it already resolved, lines moved in from other files read from theirs. Same tree and order as before (packed-files.test.ts checks it against the in-memory graph through edits, deletes and moves). Graphs adopted before have no packs and lay out line by line as before; packFiles: false keeps that path for its tests. On game's export: first shared() 13 s to 2-3.6 s at 20,000 queries, warm 56-82 ms, pathsAt(head) 29-119 ms; files at a version 14 s to 3 s, compare 26 s to 11 s, a path's log 27 s to 4.5 s; every answer the harness finished matches Project.load.Compare630 for (const [n, { parent }] of relocs) {
631 const into = fileOf(parent);
632 let from = out.get(into);
633 if (!from) out.set(into, (from = new Set()));
634 from.add(graph.writtenInIndex(n));
635 }
636 }
637 this.#movedFrom = out;
638 return out;
639 }
641 /**
capacity221Packed layout follows lines written in another file (disk-first 2; abso Capacity). where {} on typescript-rs left 11 lines out of erasable_syntax.rs in cloud-ts-12's draft. cloud-ts-12 moved one block between files several times, wrote lines under its last line while it sat in uninitialized_props_forms.rs, then moved the block on. Those lines followed their parent with no move of their own. The packed layout read only the file's own lines and the files its moved-in lines were written in, so it never read them. - Each file's packed history also keeps the runs written in another file under one of its lines (file-crossings). The packed layout follows them until no new file turns up. - New adoptions write packed format 2. A graph packed at format 1 has no such list, so it lays files out line by line: correct, but slower until it is adopted again. - packed-crossings.test.ts moves c.ts to d.ts, adds a line in d.ts, moves d.ts to e.ts, and checks files, where and every draft's text against the in-memory project. Named tests: packed-crossings, packed-files, state-source, draft-reads-stored, version-files, project-writer-storage, writer-adoption, moves, queued-moves, files-reads, move-reconstruction (60 of 60); tsc and biome clean.Compare642 * Lay one file out from its packed history (abso Capacity, Graph.packedLines): the lines written in it, in the files
643 * its moved-in lines came from, and in the files runs under any of those lines were written in, read a page at a
644 * time; the same tree and order as #layoutResolved, built in memory with no read per line.
capacity206Each file's line history packed (disk-first 2, lines by file; abso Capacity). A stored graph appends every line written in a file ([n, parent code, writer seq, k, replaces]) and its text, every delete of one of its lines, and every attribute set on it to that file's pages as atoms are added, a run at a time (storedLists appendAll). A view lays a file out from those pages in memory: membership checked once per atom, moves followed from the ones it already resolved, lines moved in from other files read from theirs. Same tree and order as before (packed-files.test.ts checks it against the in-memory graph through edits, deletes and moves). Graphs adopted before have no packs and lay out line by line as before; packFiles: false keeps that path for its tests. On game's export: first shared() 13 s to 2-3.6 s at 20,000 queries, warm 56-82 ms, pathsAt(head) 29-119 ms; files at a version 14 s to 3 s, compare 26 s to 11 s, a path's log 27 s to 4.5 s; every answer the harness finished matches Project.load.Compare645 */
646 #layoutPacked(path: string, complete: boolean): FileState {
647 const graph = this.graph;
648 const attrs = this.#attributes(path);
649 const start = graph.startCodeOf(path);
650 if (start === undefined) return { attrs, complete, seq: EMPTY_INTS, vis: EMPTY_INTS, deletedBy: new Map() };
651 const relocs = this.#hasMoves ? this.#relocationsN() : undefined;
652 const files = new Set<number>([-1 - start, ...(this.#movedInFrom().get(path) ?? [])]);
653 const children = new Map<number, Child[]>();
654 const texts = new Map<number, string | null>();
capacity230Who wrote what, read from the packed layout and each atom's author once (disk-first 2; abso Capacity). On website, with one opened writer, tree with authors took 9.6 s, tree for an agent with authors 9.1 s, and a folder's blame 4.9 s. Replay takes about 0.25 s. Few row reads: the time went on reading the same few large atoms again and again. - tree with authors, a folder's blame and a file's blame look up each atom's author once per call. graph.atom read and parsed the whole atom for every line, and most lines share a few big atoms. - The packed layout keeps each visible line's writer (visWriter), and lines() and buildLines use it instead of looking each line's writer up again. - The packed layout reads each atom's lamport number once per layout instead of once per line. On website adopted fresh, cold: tree with authors 3.2 s, tree for an agent with authors 4.5 s, a folder's blame 2.4 s; all seven tree and blame answers match replay. New test authors-stored: tree with authors (head, an older version, an agent's draft, a folder), folder blame and file blame on a writer-backed project answer as the in-memory one; it fails when the layout records the wrong writer. Named tests: every engine test (288 of 288), authors-stored, history, trail, draft-reads-stored, packed-crossings, version-files, files-reads, view-cache, membership-pages, project (54 of 54); tsc and biome clean.Compare655 const writers = new Map<number, number>();
capacity232Line ids and writers from the packed layout, and a sequence's text read only when used (disk-first 2; abso Capacity). 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.Compare656 const places = new Map<number, number>();
capacity206Each file's line history packed (disk-first 2, lines by file; abso Capacity). A stored graph appends every line written in a file ([n, parent code, writer seq, k, replaces]) and its text, every delete of one of its lines, and every attribute set on it to that file's pages as atoms are added, a run at a time (storedLists appendAll). A view lays a file out from those pages in memory: membership checked once per atom, moves followed from the ones it already resolved, lines moved in from other files read from theirs. Same tree and order as before (packed-files.test.ts checks it against the in-memory graph through edits, deletes and moves). Graphs adopted before have no packs and lay out line by line as before; packFiles: false keeps that path for its tests. On game's export: first shared() 13 s to 2-3.6 s at 20,000 queries, warm 56-82 ms, pathsAt(head) 29-119 ms; files at a version 14 s to 3 s, compare 26 s to 11 s, a path's log 27 s to 4.5 s; every answer the harness finished matches Project.load.Compare657 const deleters = new Map<number, number[]>();
capacity230Who wrote what, read from the packed layout and each atom's author once (disk-first 2; abso Capacity). On website, with one opened writer, tree with authors took 9.6 s, tree for an agent with authors 9.1 s, and a folder's blame 4.9 s. Replay takes about 0.25 s. Few row reads: the time went on reading the same few large atoms again and again. - tree with authors, a folder's blame and a file's blame look up each atom's author once per call. graph.atom read and parsed the whole atom for every line, and most lines share a few big atoms. - The packed layout keeps each visible line's writer (visWriter), and lines() and buildLines use it instead of looking each line's writer up again. - The packed layout reads each atom's lamport number once per layout instead of once per line. On website adopted fresh, cold: tree with authors 3.2 s, tree for an agent with authors 4.5 s, a folder's blame 2.4 s; all seven tree and blame answers match replay. New test authors-stored: tree with authors (head, an older version, an agent's draft, a folder), folder blame and file blame on a writer-backed project answer as the in-memory one; it fails when the layout records the wrong writer. Named tests: every engine test (288 of 288), authors-stored, history, trail, draft-reads-stored, packed-crossings, version-files, files-reads, view-cache, membership-pages, project (54 of 54); tsc and biome clean.Compare658 // Each atom's lamport once per layout: most lines share a few atoms, and a stored graph reads it from a page.
659 const lamports = new Map<number, number>();
660 const lamportOf = (seq: number): number => {
661 let lamport = lamports.get(seq);
662 if (lamport === undefined) {
663 lamport = graph.lamportOfSeq(seq);
664 lamports.set(seq, lamport);
665 }
666 return lamport;
667 };
capacity206Each file's line history packed (disk-first 2, lines by file; abso Capacity). A stored graph appends every line written in a file ([n, parent code, writer seq, k, replaces]) and its text, every delete of one of its lines, and every attribute set on it to that file's pages as atoms are added, a run at a time (storedLists appendAll). A view lays a file out from those pages in memory: membership checked once per atom, moves followed from the ones it already resolved, lines moved in from other files read from theirs. Same tree and order as before (packed-files.test.ts checks it against the in-memory graph through edits, deletes and moves). Graphs adopted before have no packs and lay out line by line as before; packFiles: false keeps that path for its tests. On game's export: first shared() 13 s to 2-3.6 s at 20,000 queries, warm 56-82 ms, pathsAt(head) 29-119 ms; files at a version 14 s to 3 s, compare 26 s to 11 s, a path's log 27 s to 4.5 s; every answer the harness finished matches Project.load.Compare668 for (const file of files) {
669 const lineTexts = graph.packedTexts(file);
670 for (const [n, parent, seq, k, replaces] of graph.packedLines(file)) {
671 const text = lineTexts.next().value as string | null;
672 if (!this.#has(seq)) continue;
673 const moved = relocs?.get(n);
674 let at = parent;
capacity230Who wrote what, read from the packed layout and each atom's author once (disk-first 2; abso Capacity). On website, with one opened writer, tree with authors took 9.6 s, tree for an agent with authors 9.1 s, and a folder's blame 4.9 s. Replay takes about 0.25 s. Few row reads: the time went on reading the same few large atoms again and again. - tree with authors, a folder's blame and a file's blame look up each atom's author once per call. graph.atom read and parsed the whole atom for every line, and most lines share a few big atoms. - The packed layout keeps each visible line's writer (visWriter), and lines() and buildLines use it instead of looking each line's writer up again. - The packed layout reads each atom's lamport number once per layout instead of once per line. On website adopted fresh, cold: tree with authors 3.2 s, tree for an agent with authors 4.5 s, a folder's blame 2.4 s; all seven tree and blame answers match replay. New test authors-stored: tree with authors (head, an older version, an agent's draft, a folder), folder blame and file blame on a writer-backed project answer as the in-memory one; it fails when the layout records the wrong writer. Named tests: every engine test (288 of 288), authors-stored, history, trail, draft-reads-stored, packed-crossings, version-files, files-reads, view-cache, membership-pages, project (54 of 54); tsc and biome clean.Compare675 let child: Child = { n, replaces, lamport: lamportOf(seq), seq, k };
capacity206Each file's line history packed (disk-first 2, lines by file; abso Capacity). A stored graph appends every line written in a file ([n, parent code, writer seq, k, replaces]) and its text, every delete of one of its lines, and every attribute set on it to that file's pages as atoms are added, a run at a time (storedLists appendAll). A view lays a file out from those pages in memory: membership checked once per atom, moves followed from the ones it already resolved, lines moved in from other files read from theirs. Same tree and order as before (packed-files.test.ts checks it against the in-memory graph through edits, deletes and moves). Graphs adopted before have no packs and lay out line by line as before; packFiles: false keeps that path for its tests. On game's export: first shared() 13 s to 2-3.6 s at 20,000 queries, warm 56-82 ms, pathsAt(head) 29-119 ms; files at a version 14 s to 3 s, compare 26 s to 11 s, a path's log 27 s to 4.5 s; every answer the harness finished matches Project.load.Compare676 if (moved) {
677 const mover = graph.atom(moved.r.atom).seq;
capacity230Who wrote what, read from the packed layout and each atom's author once (disk-first 2; abso Capacity). On website, with one opened writer, tree with authors took 9.6 s, tree for an agent with authors 9.1 s, and a folder's blame 4.9 s. Replay takes about 0.25 s. Few row reads: the time went on reading the same few large atoms again and again. - tree with authors, a folder's blame and a file's blame look up each atom's author once per call. graph.atom read and parsed the whole atom for every line, and most lines share a few big atoms. - The packed layout keeps each visible line's writer (visWriter), and lines() and buildLines use it instead of looking each line's writer up again. - The packed layout reads each atom's lamport number once per layout instead of once per line. On website adopted fresh, cold: tree with authors 3.2 s, tree for an agent with authors 4.5 s, a folder's blame 2.4 s; all seven tree and blame answers match replay. New test authors-stored: tree with authors (head, an older version, an agent's draft, a folder), folder blame and file blame on a writer-backed project answer as the in-memory one; it fails when the layout records the wrong writer. Named tests: every engine test (288 of 288), authors-stored, history, trail, draft-reads-stored, packed-crossings, version-files, files-reads, view-cache, membership-pages, project (54 of 54); tsc and biome clean.Compare678 child = { n, replaces: 0, lamport: lamportOf(mover), seq: mover, k: moved.r.k };
capacity206Each file's line history packed (disk-first 2, lines by file; abso Capacity). A stored graph appends every line written in a file ([n, parent code, writer seq, k, replaces]) and its text, every delete of one of its lines, and every attribute set on it to that file's pages as atoms are added, a run at a time (storedLists appendAll). A view lays a file out from those pages in memory: membership checked once per atom, moves followed from the ones it already resolved, lines moved in from other files read from theirs. Same tree and order as before (packed-files.test.ts checks it against the in-memory graph through edits, deletes and moves). Graphs adopted before have no packs and lay out line by line as before; packFiles: false keeps that path for its tests. On game's export: first shared() 13 s to 2-3.6 s at 20,000 queries, warm 56-82 ms, pathsAt(head) 29-119 ms; files at a version 14 s to 3 s, compare 26 s to 11 s, a path's log 27 s to 4.5 s; every answer the harness finished matches Project.load.Compare679 at = moved.parent;
680 }
681 const list = children.get(at);
682 if (list) list.push(child);
683 else children.set(at, [child]);
684 texts.set(n, text);
capacity230Who wrote what, read from the packed layout and each atom's author once (disk-first 2; abso Capacity). On website, with one opened writer, tree with authors took 9.6 s, tree for an agent with authors 9.1 s, and a folder's blame 4.9 s. Replay takes about 0.25 s. Few row reads: the time went on reading the same few large atoms again and again. - tree with authors, a folder's blame and a file's blame look up each atom's author once per call. graph.atom read and parsed the whole atom for every line, and most lines share a few big atoms. - The packed layout keeps each visible line's writer (visWriter), and lines() and buildLines use it instead of looking each line's writer up again. - The packed layout reads each atom's lamport number once per layout instead of once per line. On website adopted fresh, cold: tree with authors 3.2 s, tree for an agent with authors 4.5 s, a folder's blame 2.4 s; all seven tree and blame answers match replay. New test authors-stored: tree with authors (head, an older version, an agent's draft, a folder), folder blame and file blame on a writer-backed project answer as the in-memory one; it fails when the layout records the wrong writer. Named tests: every engine test (288 of 288), authors-stored, history, trail, draft-reads-stored, packed-crossings, version-files, files-reads, view-cache, membership-pages, project (54 of 54); tsc and biome clean.Compare685 writers.set(n, seq);
capacity232Line ids and writers from the packed layout, and a sequence's text read only when used (disk-first 2; abso Capacity). 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.Compare686 places.set(n, k);
capacity206Each file's line history packed (disk-first 2, lines by file; abso Capacity). A stored graph appends every line written in a file ([n, parent code, writer seq, k, replaces]) and its text, every delete of one of its lines, and every attribute set on it to that file's pages as atoms are added, a run at a time (storedLists appendAll). A view lays a file out from those pages in memory: membership checked once per atom, moves followed from the ones it already resolved, lines moved in from other files read from theirs. Same tree and order as before (packed-files.test.ts checks it against the in-memory graph through edits, deletes and moves). Graphs adopted before have no packs and lay out line by line as before; packFiles: false keeps that path for its tests. On game's export: first shared() 13 s to 2-3.6 s at 20,000 queries, warm 56-82 ms, pathsAt(head) 29-119 ms; files at a version 14 s to 3 s, compare 26 s to 11 s, a path's log 27 s to 4.5 s; every answer the harness finished matches Project.load.Compare687 }
688 for (const [n, deleter] of graph.packedDeletes(file)) {
689 if (!this.#has(deleter)) continue;
690 const by = deleters.get(n);
691 if (by) by.push(deleter);
692 else deleters.set(n, [deleter]);
693 }
capacity221Packed layout follows lines written in another file (disk-first 2; abso Capacity). where {} on typescript-rs left 11 lines out of erasable_syntax.rs in cloud-ts-12's draft. cloud-ts-12 moved one block between files several times, wrote lines under its last line while it sat in uninitialized_props_forms.rs, then moved the block on. Those lines followed their parent with no move of their own. The packed layout read only the file's own lines and the files its moved-in lines were written in, so it never read them. - Each file's packed history also keeps the runs written in another file under one of its lines (file-crossings). The packed layout follows them until no new file turns up. - New adoptions write packed format 2. A graph packed at format 1 has no such list, so it lays files out line by line: correct, but slower until it is adopted again. - packed-crossings.test.ts moves c.ts to d.ts, adds a line in d.ts, moves d.ts to e.ts, and checks files, where and every draft's text against the in-memory project. Named tests: packed-crossings, packed-files, state-source, draft-reads-stored, version-files, project-writer-storage, writer-adoption, moves, queued-moves, files-reads, move-reconstruction (60 of 60); tsc and biome clean.Compare694 // Runs written elsewhere under this file's lines follow them; the loop reads their files too.
695 for (const [parent, into] of graph.packedCrossings(file)) if (texts.has(parent)) files.add(into);
capacity206Each file's line history packed (disk-first 2, lines by file; abso Capacity). A stored graph appends every line written in a file ([n, parent code, writer seq, k, replaces]) and its text, every delete of one of its lines, and every attribute set on it to that file's pages as atoms are added, a run at a time (storedLists appendAll). A view lays a file out from those pages in memory: membership checked once per atom, moves followed from the ones it already resolved, lines moved in from other files read from theirs. Same tree and order as before (packed-files.test.ts checks it against the in-memory graph through edits, deletes and moves). Graphs adopted before have no packs and lay out line by line as before; packFiles: false keeps that path for its tests. On game's export: first shared() 13 s to 2-3.6 s at 20,000 queries, warm 56-82 ms, pathsAt(head) 29-119 ms; files at a version 14 s to 3 s, compare 26 s to 11 s, a path's log 27 s to 4.5 s; every answer the harness finished matches Project.load.Compare696 }
697 const order = (a: Child, b: Child) =>
698 b.replaces - a.replaces || b.lamport - a.lamport || b.seq - a.seq || a.k - b.k;
capacity230Who wrote what, read from the packed layout and each atom's author once (disk-first 2; abso Capacity). On website, with one opened writer, tree with authors took 9.6 s, tree for an agent with authors 9.1 s, and a folder's blame 4.9 s. Replay takes about 0.25 s. Few row reads: the time went on reading the same few large atoms again and again. - tree with authors, a folder's blame and a file's blame look up each atom's author once per call. graph.atom read and parsed the whole atom for every line, and most lines share a few big atoms. - The packed layout keeps each visible line's writer (visWriter), and lines() and buildLines use it instead of looking each line's writer up again. - The packed layout reads each atom's lamport number once per layout instead of once per line. On website adopted fresh, cold: tree with authors 3.2 s, tree for an agent with authors 4.5 s, a folder's blame 2.4 s; all seven tree and blame answers match replay. New test authors-stored: tree with authors (head, an older version, an agent's draft, a folder), folder blame and file blame on a writer-backed project answer as the in-memory one; it fails when the layout records the wrong writer. Named tests: every engine test (288 of 288), authors-stored, history, trail, draft-reads-stored, packed-crossings, version-files, files-reads, view-cache, membership-pages, project (54 of 54); tsc and biome clean.Compare699 const priority = (a: number, b: number) => lamportOf(a) - lamportOf(b) || a - b;
capacity206Each file's line history packed (disk-first 2, lines by file; abso Capacity). A stored graph appends every line written in a file ([n, parent code, writer seq, k, replaces]) and its text, every delete of one of its lines, and every attribute set on it to that file's pages as atoms are added, a run at a time (storedLists appendAll). A view lays a file out from those pages in memory: membership checked once per atom, moves followed from the ones it already resolved, lines moved in from other files read from theirs. Same tree and order as before (packed-files.test.ts checks it against the in-memory graph through edits, deletes and moves). Graphs adopted before have no packs and lay out line by line as before; packFiles: false keeps that path for its tests. On game's export: first shared() 13 s to 2-3.6 s at 20,000 queries, warm 56-82 ms, pathsAt(head) 29-119 ms; files at a version 14 s to 3 s, compare 26 s to 11 s, a path's log 27 s to 4.5 s; every answer the harness finished matches Project.load.Compare700 const seq: number[] = [];
701 const vis: number[] = [];
702 const visText: (string | null)[] = [];
capacity230Who wrote what, read from the packed layout and each atom's author once (disk-first 2; abso Capacity). On website, with one opened writer, tree with authors took 9.6 s, tree for an agent with authors 9.1 s, and a folder's blame 4.9 s. Replay takes about 0.25 s. Few row reads: the time went on reading the same few large atoms again and again. - tree with authors, a folder's blame and a file's blame look up each atom's author once per call. graph.atom read and parsed the whole atom for every line, and most lines share a few big atoms. - The packed layout keeps each visible line's writer (visWriter), and lines() and buildLines use it instead of looking each line's writer up again. - The packed layout reads each atom's lamport number once per layout instead of once per line. On website adopted fresh, cold: tree with authors 3.2 s, tree for an agent with authors 4.5 s, a folder's blame 2.4 s; all seven tree and blame answers match replay. New test authors-stored: tree with authors (head, an older version, an agent's draft, a folder), folder blame and file blame on a writer-backed project answer as the in-memory one; it fails when the layout records the wrong writer. Named tests: every engine test (288 of 288), authors-stored, history, trail, draft-reads-stored, packed-crossings, version-files, files-reads, view-cache, membership-pages, project (54 of 54); tsc and biome clean.Compare703 const visWriter: number[] = [];
capacity232Line ids and writers from the packed layout, and a sequence's text read only when used (disk-first 2; abso Capacity). 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.Compare704 const visK: number[] = [];
705 const seqWriter: number[] = [];
706 const seqK: number[] = [];
capacity206Each file's line history packed (disk-first 2, lines by file; abso Capacity). A stored graph appends every line written in a file ([n, parent code, writer seq, k, replaces]) and its text, every delete of one of its lines, and every attribute set on it to that file's pages as atoms are added, a run at a time (storedLists appendAll). A view lays a file out from those pages in memory: membership checked once per atom, moves followed from the ones it already resolved, lines moved in from other files read from theirs. Same tree and order as before (packed-files.test.ts checks it against the in-memory graph through edits, deletes and moves). Graphs adopted before have no packs and lay out line by line as before; packFiles: false keeps that path for its tests. On game's export: first shared() 13 s to 2-3.6 s at 20,000 queries, warm 56-82 ms, pathsAt(head) 29-119 ms; files at a version 14 s to 3 s, compare 26 s to 11 s, a path's log 27 s to 4.5 s; every answer the harness finished matches Project.load.Compare707 const deletedBy = new Map<number, readonly number[]>();
708 const stack: number[] = [];
709 const push = (code: number) => {
710 const list = children.get(code);
711 if (!list) return;
712 if (list.length > 1) list.sort(order);
713 for (let i = list.length - 1; i >= 0; i--) stack.push(list[i]!.n);
714 };
715 push(start);
716 while (stack.length) {
717 const n = stack.pop()!;
718 const by = deleters.get(n);
719 if (by) {
720 if (complete) deletedBy.set(seq.length, by.length > 1 ? by.sort(priority) : by);
721 } else {
722 vis.push(n);
723 visText.push(texts.get(n) ?? null);
capacity230Who wrote what, read from the packed layout and each atom's author once (disk-first 2; abso Capacity). On website, with one opened writer, tree with authors took 9.6 s, tree for an agent with authors 9.1 s, and a folder's blame 4.9 s. Replay takes about 0.25 s. Few row reads: the time went on reading the same few large atoms again and again. - tree with authors, a folder's blame and a file's blame look up each atom's author once per call. graph.atom read and parsed the whole atom for every line, and most lines share a few big atoms. - The packed layout keeps each visible line's writer (visWriter), and lines() and buildLines use it instead of looking each line's writer up again. - The packed layout reads each atom's lamport number once per layout instead of once per line. On website adopted fresh, cold: tree with authors 3.2 s, tree for an agent with authors 4.5 s, a folder's blame 2.4 s; all seven tree and blame answers match replay. New test authors-stored: tree with authors (head, an older version, an agent's draft, a folder), folder blame and file blame on a writer-backed project answer as the in-memory one; it fails when the layout records the wrong writer. Named tests: every engine test (288 of 288), authors-stored, history, trail, draft-reads-stored, packed-crossings, version-files, files-reads, view-cache, membership-pages, project (54 of 54); tsc and biome clean.Compare724 visWriter.push(writers.get(n)!);
capacity232Line ids and writers from the packed layout, and a sequence's text read only when used (disk-first 2; abso Capacity). 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.Compare725 visK.push(places.get(n)!);
capacity206Each file's line history packed (disk-first 2, lines by file; abso Capacity). A stored graph appends every line written in a file ([n, parent code, writer seq, k, replaces]) and its text, every delete of one of its lines, and every attribute set on it to that file's pages as atoms are added, a run at a time (storedLists appendAll). A view lays a file out from those pages in memory: membership checked once per atom, moves followed from the ones it already resolved, lines moved in from other files read from theirs. Same tree and order as before (packed-files.test.ts checks it against the in-memory graph through edits, deletes and moves). Graphs adopted before have no packs and lay out line by line as before; packFiles: false keeps that path for its tests. On game's export: first shared() 13 s to 2-3.6 s at 20,000 queries, warm 56-82 ms, pathsAt(head) 29-119 ms; files at a version 14 s to 3 s, compare 26 s to 11 s, a path's log 27 s to 4.5 s; every answer the harness finished matches Project.load.Compare726 }
capacity232Line ids and writers from the packed layout, and a sequence's text read only when used (disk-first 2; abso Capacity). 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.Compare727 if (complete) {
728 seq.push(n);
729 seqWriter.push(writers.get(n)!);
730 seqK.push(places.get(n)!);
731 }
capacity206Each file's line history packed (disk-first 2, lines by file; abso Capacity). A stored graph appends every line written in a file ([n, parent code, writer seq, k, replaces]) and its text, every delete of one of its lines, and every attribute set on it to that file's pages as atoms are added, a run at a time (storedLists appendAll). A view lays a file out from those pages in memory: membership checked once per atom, moves followed from the ones it already resolved, lines moved in from other files read from theirs. Same tree and order as before (packed-files.test.ts checks it against the in-memory graph through edits, deletes and moves). Graphs adopted before have no packs and lay out line by line as before; packFiles: false keeps that path for its tests. On game's export: first shared() 13 s to 2-3.6 s at 20,000 queries, warm 56-82 ms, pathsAt(head) 29-119 ms; files at a version 14 s to 3 s, compare 26 s to 11 s, a path's log 27 s to 4.5 s; every answer the harness finished matches Project.load.Compare732 push(n);
733 }
capacity230Who wrote what, read from the packed layout and each atom's author once (disk-first 2; abso Capacity). On website, with one opened writer, tree with authors took 9.6 s, tree for an agent with authors 9.1 s, and a folder's blame 4.9 s. Replay takes about 0.25 s. Few row reads: the time went on reading the same few large atoms again and again. - tree with authors, a folder's blame and a file's blame look up each atom's author once per call. graph.atom read and parsed the whole atom for every line, and most lines share a few big atoms. - The packed layout keeps each visible line's writer (visWriter), and lines() and buildLines use it instead of looking each line's writer up again. - The packed layout reads each atom's lamport number once per layout instead of once per line. On website adopted fresh, cold: tree with authors 3.2 s, tree for an agent with authors 4.5 s, a folder's blame 2.4 s; all seven tree and blame answers match replay. New test authors-stored: tree with authors (head, an older version, an agent's draft, a folder), folder blame and file blame on a writer-backed project answer as the in-memory one; it fails when the layout records the wrong writer. Named tests: every engine test (288 of 288), authors-stored, history, trail, draft-reads-stored, packed-crossings, version-files, files-reads, view-cache, membership-pages, project (54 of 54); tsc and biome clean.Compare734 return {
735 attrs,
736 complete,
737 seq: Int32Array.from(seq),
738 vis: Int32Array.from(vis),
739 deletedBy,
740 visText,
741 visWriter: Int32Array.from(visWriter),
capacity232Line ids and writers from the packed layout, and a sequence's text read only when used (disk-first 2; abso Capacity). 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.Compare742 visK: Int32Array.from(visK),
743 ...(complete ? { seqWriter: Int32Array.from(seqWriter), seqK: Int32Array.from(seqK) } : {}),
capacity230Who wrote what, read from the packed layout and each atom's author once (disk-first 2; abso Capacity). On website, with one opened writer, tree with authors took 9.6 s, tree for an agent with authors 9.1 s, and a folder's blame 4.9 s. Replay takes about 0.25 s. Few row reads: the time went on reading the same few large atoms again and again. - tree with authors, a folder's blame and a file's blame look up each atom's author once per call. graph.atom read and parsed the whole atom for every line, and most lines share a few big atoms. - The packed layout keeps each visible line's writer (visWriter), and lines() and buildLines use it instead of looking each line's writer up again. - The packed layout reads each atom's lamport number once per layout instead of once per line. On website adopted fresh, cold: tree with authors 3.2 s, tree for an agent with authors 4.5 s, a folder's blame 2.4 s; all seven tree and blame answers match replay. New test authors-stored: tree with authors (head, an older version, an agent's draft, a folder), folder blame and file blame on a writer-backed project answer as the in-memory one; it fails when the layout records the wrong writer. Named tests: every engine test (288 of 288), authors-stored, history, trail, draft-reads-stored, packed-crossings, version-files, files-reads, view-cache, membership-pages, project (54 of 54); tsc and biome clean.Compare744 };
capacity206Each file's line history packed (disk-first 2, lines by file; abso Capacity). A stored graph appends every line written in a file ([n, parent code, writer seq, k, replaces]) and its text, every delete of one of its lines, and every attribute set on it to that file's pages as atoms are added, a run at a time (storedLists appendAll). A view lays a file out from those pages in memory: membership checked once per atom, moves followed from the ones it already resolved, lines moved in from other files read from theirs. Same tree and order as before (packed-files.test.ts checks it against the in-memory graph through edits, deletes and moves). Graphs adopted before have no packs and lay out line by line as before; packFiles: false keeps that path for its tests. On game's export: first shared() 13 s to 2-3.6 s at 20,000 queries, warm 56-82 ms, pathsAt(head) 29-119 ms; files at a version 14 s to 3 s, compare 26 s to 11 s, a path's log 27 s to 4.5 s; every answer the harness finished matches Project.load.Compare745 }
codex-capacity-chair140Avoid line projection for file attribute queriesCompare747 #attributes(path: string): FileAttrs {
codex-capacity-chair132Bound persistent relocation projection memory with rollback-only scratchCompare748 const graph = this.graph;
init0Start the project749 // For each attribute, the highest-priority setter in the set wins.
750 const setters = new Map<string, { id: AtomId; value: string | null }>();
capacity206Each file's line history packed (disk-first 2, lines by file; abso Capacity). A stored graph appends every line written in a file ([n, parent code, writer seq, k, replaces]) and its text, every delete of one of its lines, and every attribute set on it to that file's pages as atoms are added, a run at a time (storedLists appendAll). A view lays a file out from those pages in memory: membership checked once per atom, moves followed from the ones it already resolved, lines moved in from other files read from theirs. Same tree and order as before (packed-files.test.ts checks it against the in-memory graph through edits, deletes and moves). Graphs adopted before have no packs and lay out line by line as before; packFiles: false keeps that path for its tests. On game's export: first shared() 13 s to 2-3.6 s at 20,000 queries, warm 56-82 ms, pathsAt(head) 29-119 ms; files at a version 14 s to 3 s, compare 26 s to 11 s, a path's log 27 s to 4.5 s; every answer the harness finished matches Project.load.Compare751 const file = graph.packedFiles ? graph.pathIndexOf(path) : undefined;
752 if (graph.packedFiles) {
753 for (const [seq, name, value] of file === undefined ? [] : graph.packedAttrs(file)) {
754 if (!this.#has(seq)) continue;
755 const id = graph.idOfSeq(seq);
756 const best = setters.get(name);
757 if (!best || graph.comparePriority(best.id, id) < 0) setters.set(name, { id, value });
758 }
759 return {
760 exists: setters.get("exists")?.value === "1",
761 exec: setters.get("exec")?.value === "1",
762 link: setters.get("link")?.value ?? null,
763 blob: setters.get("blob")?.value ?? null,
764 };
765 }
codex-capacity-chair119Page per-file atom indexes and stream current-view attribute scansCompare766 for (const id of graph.eachAtomIn(path)) {
init0Start the project767 if (!this.#has(graph.atom(id).seq)) continue;
768 for (const a of graph.atom(id).attrs ?? []) {
769 if (a.file !== path) continue;
770 const best = setters.get(a.name);
771 if (!best || graph.comparePriority(best.id, id) < 0) setters.set(a.name, { id, value: a.value });
772 }
773 }
codex-capacity-chair140Avoid line projection for file attribute queriesCompare774
775 return {
init0Start the project776 exists: setters.get("exists")?.value === "1",
777 exec: setters.get("exec")?.value === "1",
778 link: setters.get("link")?.value ?? null,
779 blob: setters.get("blob")?.value ?? null,
780 };
codex-capacity-chair140Avoid line projection for file attribute queriesCompare781 }
init0Start the project782
codex-capacity-chair132Bound persistent relocation projection memory with rollback-only scratchCompare783 #layoutResolved(path: string, complete: boolean, nodes?: Iterable<number>): FileState {
codex-capacity-chair140Avoid line projection for file attribute queriesCompare784 const graph = this.graph;
785 const attrs = this.#attributes(path);
init0Start the project786 const seq: number[] = [];
787 const vis: number[] = [];
788 const deletedBy = new Map<number, readonly number[]>();
codex-capacity-chair131Bound persisted no-move layout with ordered successor traversalCompare789
init0Start the project790 const start = graph.startCodeOf(path);
791 const priority = (a: number, b: number) => graph.lamportOfSeq(a) - graph.lamportOfSeq(b) || a - b;
codex-capacity-chair132Bound persistent relocation projection memory with rollback-only scratchCompare792 for (const n of nodes ?? (start === undefined ? [] : this.#layoutNodes(start))) {
codex-capacity-chair128Page deletion history and short-circuit current visibilityCompare793 let deleted = false;
794 const by: number[] = [];
795 for (const deleter of graph.eachDeleterSeqOf(n)) {
796 if (!this.#has(deleter)) continue;
797 deleted = true;
798 if (!complete) break;
799 by.push(deleter);
800 }
801 if (deleted) {
802 if (complete) deletedBy.set(seq.length, by.length > 1 ? by.sort(priority) : by);
codex-capacity-chair110Keep current-file views and key scans from retaining historical stateCompare803 } else vis.push(n);
804 if (complete) seq.push(n);
init0Start the project805 }
codex-capacity-chair140Avoid line projection for file attribute queriesCompare806
codex-capacity-chair110Keep current-file views and key scans from retaining historical stateCompare807 return { attrs, complete, seq: Int32Array.from(seq), vis: Int32Array.from(vis), deletedBy };
init0Start the project808 }
810 get #known(): string[] {
811 if (!this.#knownList) {
812 const known = new Set<string>();
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare813 if (this.#stable) {
814 for (const id of this.#stable) for (const file of this.graph.filesOf(id)) known.add(file);
815 } else {
816 for (let seq = 0; seq < this.#in.length; seq++)
817 if (this.#in[seq] === 1) for (const file of this.graph.filesOf(this.graph.idOfSeq(seq))) known.add(file);
818 }
init0Start the project819 this.#knownList = [...known].sort();
820 }
821 return this.#knownList;
822 }
824 /** Files with at least one visible line, sorted. */
825 paths(): string[] {
codex-capacity-chair118Avoid retaining deleted historical paths in indexed current viewsCompare826 if (this.#stable) {
827 const paths: string[] = [];
828 for (const path of this.graph.knownFiles()) {
829 if (this.hasFile(path)) paths.push(path);
830 else this.#files.delete(path);
831 }
832 return paths.sort();
833 }
init0Start the project834 return this.#known.filter((p) => this.hasFile(p));
835 }
837 /** Every file the set has ever written a line in, including fully deleted ones. */
838 knownPaths(): string[] {
839 return [...this.#known];
capacity207Each shared version's changed files kept as it lands (disk-first 2; abso Capacity, version-files.ts). A version's files are decided from what it touched: visible lines in and out per file, their texts' balance, a running count of each file's visible lines for made and taken out, and mode and blob; a version with moves, drops or a closure change, or whose lines in and out have the same texts, is laid out as before. Views of consecutive versions share resolved moves and where lines sit (View.shareMoves). PathIndex.keep records them, into the shapes table when the host gives one. version-files.test.ts checks log, path logs and every show against the in-memory project through edits, new and removed files, same text put back, a move and a drop. On game's export all 27 harness answers now match Project.load: the log 70 ms (was over 30 s), a path's history 0.56 s (was over 30 s), the tree 3.1-3.4 s (was over 30 s); adoption about 85 s; heap 14.4 MB at most.Compare840 }
capacity212Draft reads on a stored writer (disk-first 2; abso Capacity): where, drafts, status and collisions on website's export. - where looks deleted lines up by number (graph.deletedNumbers, View.fileOfNumber, View.lineNumberOf). It takes the agent's view once instead of once per line, since each read weighed every cached view. It finds the draft's lines by writer (View.visibleWriters), with no text or id read per line. - Draft files (overlaps.ts) go by number the same way. - An agent's view takes its base's resolved moves when both hold the same atoms that move lines (View.shareMoves checks this). - Draft collisions: - build the union view only when two drafts share a file; - work out each agent's touched files and its "shared now plus draft" view once; - find claimants among the drafts from the drafts' own keys (collisions.ts claimantsAmong) instead of walking each key's history; - have the definition rule keep a draft's uses, and the newer work's definitions, across partners. - A stored list read in order reads its length once, not before every element. draft-reads-stored.test.ts checks where and collisions against the in-memory project. It covers edits, a whole file deleted, a line collision, one name defined twice, and bases before and after a move. 135 of 136 related tests pass; none fail. On website's export (1,387 entries) the answers match Project.load: - status: 17 s to 4.5 s - where: over 60 s to 8.8 s - drafts: 14 s to 5.3 s - collisions: over 60 s to 54 s, measured under the profiler before the last two changesCompare842 /** The file line n sits in, in this set: fileOf by the line's number, with no lookup of its id. */
843 fileOfNumber(n: number): string {
844 return this.#fileOfN(n);
845 }
capacity207Each shared version's changed files kept as it lands (disk-first 2; abso Capacity, version-files.ts). A version's files are decided from what it touched: visible lines in and out per file, their texts' balance, a running count of each file's visible lines for made and taken out, and mode and blob; a version with moves, drops or a closure change, or whose lines in and out have the same texts, is laid out as before. Views of consecutive versions share resolved moves and where lines sit (View.shareMoves). PathIndex.keep records them, into the shapes table when the host gives one. version-files.test.ts checks log, path logs and every show against the in-memory project through edits, new and removed files, same text put back, a move and a drop. On game's export all 27 harness answers now match Project.load: the log 70 ms (was over 30 s), a path's history 0.56 s (was over 30 s), the tree 3.1-3.4 s (was over 30 s); adoption about 85 s; heap 14.4 MB at most.Compare847 /** How many visible lines a file has. */
848 visibleCount(path: string): number {
849 return this.#file(path).vis.length;
init0Start the project850 }
852 /** Whether the file exists in this projection (has a visible line). */
853 hasFile(path: string): boolean {
codex-capacity-chair140Avoid line projection for file attribute queriesCompare854 const attrs = this.attrs(path);
855 return attrs.exists || attrs.link !== null || attrs.blob !== null || this.#file(path).vis.length > 0;
init0Start the project856 }
858 /** A file's attributes: kept while empty, executable, a link's target. */
859 attrs(path: string): FileAttrs {
codex-capacity-chair140Avoid line projection for file attribute queriesCompare860 return this.#files.get(path)?.attrs ?? this.#attributes(path);
init0Start the project861 }
863 /** The projected text of a file ("" if it has no visible lines). */
864 text(path: string): string {
865 if (this.#textCache?.path === path) return this.#textCache.text;
capacity206Each file's line history packed (disk-first 2, lines by file; abso Capacity). A stored graph appends every line written in a file ([n, parent code, writer seq, k, replaces]) and its text, every delete of one of its lines, and every attribute set on it to that file's pages as atoms are added, a run at a time (storedLists appendAll). A view lays a file out from those pages in memory: membership checked once per atom, moves followed from the ones it already resolved, lines moved in from other files read from theirs. Same tree and order as before (packed-files.test.ts checks it against the in-memory graph through edits, deletes and moves). Graphs adopted before have no packs and lay out line by line as before; packFiles: false keeps that path for its tests. On game's export: first shared() 13 s to 2-3.6 s at 20,000 queries, warm 56-82 ms, pathsAt(head) 29-119 ms; files at a version 14 s to 3 s, compare 26 s to 11 s, a path's log 27 s to 4.5 s; every answer the harness finished matches Project.load.Compare866 const { vis, visText } = this.#file(path);
init0Start the project867 const lines: string[] = new Array(vis.length);
capacity206Each file's line history packed (disk-first 2, lines by file; abso Capacity). A stored graph appends every line written in a file ([n, parent code, writer seq, k, replaces]) and its text, every delete of one of its lines, and every attribute set on it to that file's pages as atoms are added, a run at a time (storedLists appendAll). A view lays a file out from those pages in memory: membership checked once per atom, moves followed from the ones it already resolved, lines moved in from other files read from theirs. Same tree and order as before (packed-files.test.ts checks it against the in-memory graph through edits, deletes and moves). Graphs adopted before have no packs and lay out line by line as before; packFiles: false keeps that path for its tests. On game's export: first shared() 13 s to 2-3.6 s at 20,000 queries, warm 56-82 ms, pathsAt(head) 29-119 ms; files at a version 14 s to 3 s, compare 26 s to 11 s, a path's log 27 s to 4.5 s; every answer the harness finished matches Project.load.Compare868 for (let i = 0; i < vis.length; i++) lines[i] = visText?.[i] ?? this.graph.textOf(vis[i]!);
init0Start the project869 const text = joinLines(lines);
870 this.#textCache = { path, text };
871 return text;
872 }
874 /** Whether a file reads the same here and in `other` (of the same graph), compared line by line without joining either (#46). */
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare875 sameText(path: string, other: ReadView): boolean {
876 if (!(other instanceof View)) {
877 const a = this.lines(path),
878 b = other.lines(path);
879 return a.length === b.length && a.every((line, i) => line.text === b[i]!.text);
880 }
init0Start the project881 const a = this.#file(path).vis;
882 const b = other.#file(path).vis;
883 if (a.length !== b.length) return false;
884 for (let i = 0; i < a.length; i++)
885 if (a[i] !== b[i] && this.graph.textOf(a[i]!) !== this.graph.textOf(b[i]!)) return false;
886 return true;
codex-capacity-chair175Reduce disk-backed record and publish allocations; reviewed in core ask 52 with parsed-code budget and exact aligned-line follow-ups. Keep disk-first activation off.Compare887 }
889 *lineChunks(path: string): IterableIterator<() => Iterable<string>> {
890 for (const n of this.#file(path).vis) yield () => this.graph.textChunks(n);
891 }
893 /** Visible lines without retaining their text in the view cache. */
894 *visibleLines(path: string): IterableIterator<VisibleLine> {
895 const graph = this.graph;
896 for (const n of this.#file(path).vis)
897 yield { id: graph.lineIdOf(n), text: graph.textOf(n), atom: graph.idOfSeq(graph.writerSeqOf(n)) };
898 }
900 /** Atom-building line handles; text is loaded only when requested. */
901 buildLines(path: string): readonly VisibleLine[] {
902 const graph = this.graph;
capacity230Who wrote what, read from the packed layout and each atom's author once (disk-first 2; abso Capacity). On website, with one opened writer, tree with authors took 9.6 s, tree for an agent with authors 9.1 s, and a folder's blame 4.9 s. Replay takes about 0.25 s. Few row reads: the time went on reading the same few large atoms again and again. - tree with authors, a folder's blame and a file's blame look up each atom's author once per call. graph.atom read and parsed the whole atom for every line, and most lines share a few big atoms. - The packed layout keeps each visible line's writer (visWriter), and lines() and buildLines use it instead of looking each line's writer up again. - The packed layout reads each atom's lamport number once per layout instead of once per line. On website adopted fresh, cold: tree with authors 3.2 s, tree for an agent with authors 4.5 s, a folder's blame 2.4 s; all seven tree and blame answers match replay. New test authors-stored: tree with authors (head, an older version, an agent's draft, a folder), folder blame and file blame on a writer-backed project answer as the in-memory one; it fails when the layout records the wrong writer. Named tests: every engine test (288 of 288), authors-stored, history, trail, draft-reads-stored, packed-crossings, version-files, files-reads, view-cache, membership-pages, project (54 of 54); tsc and biome clean.Compare903 // Texts and writers the packed layout already holds are not read again (abso Capacity).
capacity232Line ids and writers from the packed layout, and a sequence's text read only when used (disk-first 2; abso Capacity). 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.Compare904 const { vis, visText, visWriter, visK } = this.#file(path);
codex-capacity-chair175Reduce disk-backed record and publish allocations; reviewed in core ask 52 with parsed-code budget and exact aligned-line follow-ups. Keep disk-first activation off.Compare905 const lines: VisibleLine[] = new Array(vis.length);
906 for (let i = 0; i < vis.length; i++) {
907 const n = vis[i]!;
capacity229Draft collisions without copying shared's atoms per pair (disk-first 2; abso Capacity). On typescript-rs, with one opened writer, collisions ran past 5 minutes with 2.5 million row reads; replay takes 5 s. - Each pair of agents built a new set of all of shared's atoms plus both drafts, and each agent's view of shared-now did the same. On a stored writer that read every one of shared's atoms, per pair, and the view then proved the copy closed by walking it. The pair's set is now a lookup over shared's own atoms and the two drafts (same membership as before). The views are built over shared's view's own closed set plus the drafts, which closes to the same atoms and walks only the drafts. - View.lines and buildLines use the texts the packed layout already holds, instead of reading each line's text again. - The definition rule takes a line's atom and place from its id, and collisions use graph.lineAtom; graph.line read each line's text as well. On typescript-rs adopted fresh, cold: collisions finishes in 71 s with 299,000 reads, matching replay. Still slow: most of what's left is laying the same files out again for each agent's view. Named tests: every engine test (288 of 288), changed-definition, collision-streaming, definition-code, definitions, draft-reads-stored, same-line, spelling-clash, review-fixes, membership-pages, stored-closure, packed-crossings, project-writer-storage, writer-adoption, moves, version-files, where-many-agents (67 of 67); tsc and biome clean.Compare908 const packed = visText?.[i];
codex-capacity-chair175Reduce disk-backed record and publish allocations; reviewed in core ask 52 with parsed-code budget and exact aligned-line follow-ups. Keep disk-first activation off.Compare909 lines[i] = {
capacity232Line ids and writers from the packed layout, and a sequence's text read only when used (disk-first 2; abso Capacity). 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.Compare910 id: visWriter && visK ? lineId(graph.idOfSeq(visWriter[i]!), visK[i]!) : graph.lineIdOf(n),
codex-capacity-chair175Reduce disk-backed record and publish allocations; reviewed in core ask 52 with parsed-code budget and exact aligned-line follow-ups. Keep disk-first activation off.Compare911 textChunks: () => graph.textChunks(n),
912 get text() {
capacity229Draft collisions without copying shared's atoms per pair (disk-first 2; abso Capacity). On typescript-rs, with one opened writer, collisions ran past 5 minutes with 2.5 million row reads; replay takes 5 s. - Each pair of agents built a new set of all of shared's atoms plus both drafts, and each agent's view of shared-now did the same. On a stored writer that read every one of shared's atoms, per pair, and the view then proved the copy closed by walking it. The pair's set is now a lookup over shared's own atoms and the two drafts (same membership as before). The views are built over shared's view's own closed set plus the drafts, which closes to the same atoms and walks only the drafts. - View.lines and buildLines use the texts the packed layout already holds, instead of reading each line's text again. - The definition rule takes a line's atom and place from its id, and collisions use graph.lineAtom; graph.line read each line's text as well. On typescript-rs adopted fresh, cold: collisions finishes in 71 s with 299,000 reads, matching replay. Still slow: most of what's left is laying the same files out again for each agent's view. Named tests: every engine test (288 of 288), changed-definition, collision-streaming, definition-code, definitions, draft-reads-stored, same-line, spelling-clash, review-fixes, membership-pages, stored-closure, packed-crossings, project-writer-storage, writer-adoption, moves, version-files, where-many-agents (67 of 67); tsc and biome clean.Compare913 return packed ?? graph.textOf(n);
codex-capacity-chair175Reduce disk-backed record and publish allocations; reviewed in core ask 52 with parsed-code budget and exact aligned-line follow-ups. Keep disk-first activation off.Compare914 },
capacity230Who wrote what, read from the packed layout and each atom's author once (disk-first 2; abso Capacity). On website, with one opened writer, tree with authors took 9.6 s, tree for an agent with authors 9.1 s, and a folder's blame 4.9 s. Replay takes about 0.25 s. Few row reads: the time went on reading the same few large atoms again and again. - tree with authors, a folder's blame and a file's blame look up each atom's author once per call. graph.atom read and parsed the whole atom for every line, and most lines share a few big atoms. - The packed layout keeps each visible line's writer (visWriter), and lines() and buildLines use it instead of looking each line's writer up again. - The packed layout reads each atom's lamport number once per layout instead of once per line. On website adopted fresh, cold: tree with authors 3.2 s, tree for an agent with authors 4.5 s, a folder's blame 2.4 s; all seven tree and blame answers match replay. New test authors-stored: tree with authors (head, an older version, an agent's draft, a folder), folder blame and file blame on a writer-backed project answer as the in-memory one; it fails when the layout records the wrong writer. Named tests: every engine test (288 of 288), authors-stored, history, trail, draft-reads-stored, packed-crossings, version-files, files-reads, view-cache, membership-pages, project (54 of 54); tsc and biome clean.Compare915 atom: graph.idOfSeq(visWriter ? visWriter[i]! : graph.writerSeqOf(n)),
codex-capacity-chair175Reduce disk-backed record and publish allocations; reviewed in core ask 52 with parsed-code budget and exact aligned-line follow-ups. Keep disk-first activation off.Compare916 };
917 }
918 return lines;
init0Start the project919 }
921 /** Visible lines with their ids. */
922 lines(path: string): readonly VisibleLine[] {
923 if (this.#linesCache?.path === path) return this.#linesCache.lines;
924 const graph = this.graph;
capacity232Line ids and writers from the packed layout, and a sequence's text read only when used (disk-first 2; abso Capacity). 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.Compare925 const { vis, visText, visWriter, visK } = this.#file(path);
init0Start the project926 const lines: VisibleLine[] = new Array(vis.length);
927 for (let i = 0; i < vis.length; i++) {
928 const n = vis[i]!;
capacity229Draft collisions without copying shared's atoms per pair (disk-first 2; abso Capacity). On typescript-rs, with one opened writer, collisions ran past 5 minutes with 2.5 million row reads; replay takes 5 s. - Each pair of agents built a new set of all of shared's atoms plus both drafts, and each agent's view of shared-now did the same. On a stored writer that read every one of shared's atoms, per pair, and the view then proved the copy closed by walking it. The pair's set is now a lookup over shared's own atoms and the two drafts (same membership as before). The views are built over shared's view's own closed set plus the drafts, which closes to the same atoms and walks only the drafts. - View.lines and buildLines use the texts the packed layout already holds, instead of reading each line's text again. - The definition rule takes a line's atom and place from its id, and collisions use graph.lineAtom; graph.line read each line's text as well. On typescript-rs adopted fresh, cold: collisions finishes in 71 s with 299,000 reads, matching replay. Still slow: most of what's left is laying the same files out again for each agent's view. Named tests: every engine test (288 of 288), changed-definition, collision-streaming, definition-code, definitions, draft-reads-stored, same-line, spelling-clash, review-fixes, membership-pages, stored-closure, packed-crossings, project-writer-storage, writer-adoption, moves, version-files, where-many-agents (67 of 67); tsc and biome clean.Compare929 lines[i] = {
capacity232Line ids and writers from the packed layout, and a sequence's text read only when used (disk-first 2; abso Capacity). 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.Compare930 id: visWriter && visK ? lineId(graph.idOfSeq(visWriter[i]!), visK[i]!) : graph.lineIdOf(n),
capacity229Draft collisions without copying shared's atoms per pair (disk-first 2; abso Capacity). On typescript-rs, with one opened writer, collisions ran past 5 minutes with 2.5 million row reads; replay takes 5 s. - Each pair of agents built a new set of all of shared's atoms plus both drafts, and each agent's view of shared-now did the same. On a stored writer that read every one of shared's atoms, per pair, and the view then proved the copy closed by walking it. The pair's set is now a lookup over shared's own atoms and the two drafts (same membership as before). The views are built over shared's view's own closed set plus the drafts, which closes to the same atoms and walks only the drafts. - View.lines and buildLines use the texts the packed layout already holds, instead of reading each line's text again. - The definition rule takes a line's atom and place from its id, and collisions use graph.lineAtom; graph.line read each line's text as well. On typescript-rs adopted fresh, cold: collisions finishes in 71 s with 299,000 reads, matching replay. Still slow: most of what's left is laying the same files out again for each agent's view. Named tests: every engine test (288 of 288), changed-definition, collision-streaming, definition-code, definitions, draft-reads-stored, same-line, spelling-clash, review-fixes, membership-pages, stored-closure, packed-crossings, project-writer-storage, writer-adoption, moves, version-files, where-many-agents (67 of 67); tsc and biome clean.Compare931 text: visText?.[i] ?? graph.textOf(n),
capacity230Who wrote what, read from the packed layout and each atom's author once (disk-first 2; abso Capacity). On website, with one opened writer, tree with authors took 9.6 s, tree for an agent with authors 9.1 s, and a folder's blame 4.9 s. Replay takes about 0.25 s. Few row reads: the time went on reading the same few large atoms again and again. - tree with authors, a folder's blame and a file's blame look up each atom's author once per call. graph.atom read and parsed the whole atom for every line, and most lines share a few big atoms. - The packed layout keeps each visible line's writer (visWriter), and lines() and buildLines use it instead of looking each line's writer up again. - The packed layout reads each atom's lamport number once per layout instead of once per line. On website adopted fresh, cold: tree with authors 3.2 s, tree for an agent with authors 4.5 s, a folder's blame 2.4 s; all seven tree and blame answers match replay. New test authors-stored: tree with authors (head, an older version, an agent's draft, a folder), folder blame and file blame on a writer-backed project answer as the in-memory one; it fails when the layout records the wrong writer. Named tests: every engine test (288 of 288), authors-stored, history, trail, draft-reads-stored, packed-crossings, version-files, files-reads, view-cache, membership-pages, project (54 of 54); tsc and biome clean.Compare932 atom: graph.idOfSeq(visWriter ? visWriter[i]! : graph.writerSeqOf(n)),
capacity229Draft collisions without copying shared's atoms per pair (disk-first 2; abso Capacity). On typescript-rs, with one opened writer, collisions ran past 5 minutes with 2.5 million row reads; replay takes 5 s. - Each pair of agents built a new set of all of shared's atoms plus both drafts, and each agent's view of shared-now did the same. On a stored writer that read every one of shared's atoms, per pair, and the view then proved the copy closed by walking it. The pair's set is now a lookup over shared's own atoms and the two drafts (same membership as before). The views are built over shared's view's own closed set plus the drafts, which closes to the same atoms and walks only the drafts. - View.lines and buildLines use the texts the packed layout already holds, instead of reading each line's text again. - The definition rule takes a line's atom and place from its id, and collisions use graph.lineAtom; graph.line read each line's text as well. On typescript-rs adopted fresh, cold: collisions finishes in 71 s with 299,000 reads, matching replay. Still slow: most of what's left is laying the same files out again for each agent's view. Named tests: every engine test (288 of 288), changed-definition, collision-streaming, definition-code, definitions, draft-reads-stored, same-line, spelling-clash, review-fixes, membership-pages, stored-closure, packed-crossings, project-writer-storage, writer-adoption, moves, version-files, where-many-agents (67 of 67); tsc and biome clean.Compare933 };
init0Start the project934 }
935 this.#linesCache = { path, lines };
936 return lines;
937 }
939 /** The full linearized sequence of a file, tombstones included. */
940 sequence(path: string): readonly SeqLine[] {
941 if (this.#seqCache?.path === path) return this.#seqCache.seq;
942 const graph = this.graph;
codex-capacity-chair110Keep current-file views and key scans from retaining historical stateCompare943 const f = this.#file(path, true);
init0Start the project944 const out: SeqLine[] = new Array(f.seq.length);
capacity232Line ids and writers from the packed layout, and a sequence's text read only when used (disk-first 2; abso Capacity). 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.Compare945 // 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;
init0Start the project948 for (let i = 0; i < f.seq.length; i++) {
949 const n = f.seq[i]!;
950 const by = f.deletedBy.get(i);
capacity232Line ids and writers from the packed layout, and a sequence's text read only when used (disk-first 2; abso Capacity). 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.Compare951 const writer = seqWriter ? seqWriter[i]! : graph.writerSeqOf(n);
952 let text: string | undefined;
init0Start the project953 out[i] = {
capacity232Line ids and writers from the packed layout, and a sequence's text read only when used (disk-first 2; abso Capacity). 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.Compare954 id: seqWriter && seqK ? lineId(graph.idOfSeq(writer), seqK[i]!) : graph.lineIdOf(n),
955 get text() {
956 text ??= graph.textOf(n);
957 return text;
958 },
959 atom: graph.idOfSeq(writer),
init0Start the project960 deletedBy: by ? by.map((s) => graph.idOfSeq(s)) : NONE,
961 visible: by === undefined,
962 };
963 }
964 this.#seqCache = { path, seq: out };
965 return out;
966 }
codex-capacity-chair138Find reason-warning neighbors without materializing file historyCompare968 /** Two visible neighbours without retaining the file's historical sequence. */
969 visibleNeighbours(path: string, line: LineId): LineId[] {
970 const graph = this.graph;
971 const target = graph.lineN(line);
972 const start = graph.startCodeOf(path);
973 if (target < 0 || start === undefined) return [];
974 const scan = (nodes: Iterable<number>): LineId[] => {
975 let previous: LineId | undefined;
976 let found = false;
977 for (const n of nodes) {
978 if (n === target) {
979 found = true;
980 continue;
981 }
982 let deleted = false;
983 for (const seq of graph.eachDeleterSeqOf(n))
984 if (this.#has(seq)) {
985 deleted = true;
986 break;
987 }
988 if (deleted) continue;
989 const id = graph.lineIdOf(n);
990 if (found) return previous === undefined ? [id] : [previous, id];
991 previous = id;
992 }
993 return found && previous !== undefined ? [previous] : [];
994 };
capacity205Disk-first reads stop walking the whole history (disk-first 2, stage 1; abso Capacity). Shared's closure is kept on disk per version (spaces.ts indexClosure): the atoms a version needs beyond what it published, as events like membership's, with drops handled; views and Project.#closed trust a set marked closed, and over a closed stored base only a draft's own atoms are walked. A view resolves its moves once in memory (up to MOVED_LINES_KEPT, 20,000 moved lines) instead of again on disk for every file it lays out, and finds lines moved under a node from them. Graph.eachChildN skips the per-line children lookup when the paged child counts say none. On game's export (writer adopted, lock held): shared() went from not finishing in 8 minutes to 9-13 s cold and 0.15-0.25 s warm, 291,000 queries to 57,000; pathsAt(head) 0.1-0.2 s.Compare995 if (this.#scratchMoves())
codex-capacity-chair138Find reason-warning neighbors without materializing file historyCompare996 return graph.withProjectionScratch((scratch) =>
997 scan(scratchLayoutNodes(graph, (id) => this.#has(graph.atom(id).seq), scratch, graph.nodeOf(start))),
998 );
999 return scan(this.#layoutNodes(start));
init0Start the project1002 /** Index of a line in `sequence(path)`, or -1. */
1003 sequenceIndex(path: string, line: LineId): number {
codex-capacity-chair110Keep current-file views and key scans from retaining historical stateCompare1004 const f = this.#file(path, true);
init0Start the project1005 if (!f.seqIndex) {
1006 f.seqIndex = new Map();
1007 for (let i = 0; i < f.seq.length; i++) f.seqIndex.set(f.seq[i]!, i);
1009 return f.seqIndex.get(this.graph.lineN(line)) ?? -1;
1012 /** Index of a line in `lines(path)` (0-based visible line number), or -1 if not visible. */
1013 lineNumber(path: string, line: LineId): number {
capacity212Draft reads on a stored writer (disk-first 2; abso Capacity): where, drafts, status and collisions on website's export. - where looks deleted lines up by number (graph.deletedNumbers, View.fileOfNumber, View.lineNumberOf). It takes the agent's view once instead of once per line, since each read weighed every cached view. It finds the draft's lines by writer (View.visibleWriters), with no text or id read per line. - Draft files (overlaps.ts) go by number the same way. - An agent's view takes its base's resolved moves when both hold the same atoms that move lines (View.shareMoves checks this). - Draft collisions: - build the union view only when two drafts share a file; - work out each agent's touched files and its "shared now plus draft" view once; - find claimants among the drafts from the drafts' own keys (collisions.ts claimantsAmong) instead of walking each key's history; - have the definition rule keep a draft's uses, and the newer work's definitions, across partners. - A stored list read in order reads its length once, not before every element. draft-reads-stored.test.ts checks where and collisions against the in-memory project. It covers edits, a whole file deleted, a line collision, one name defined twice, and bases before and after a move. 135 of 136 related tests pass; none fail. On website's export (1,387 entries) the answers match Project.load: - status: 17 s to 4.5 s - where: over 60 s to 8.8 s - drafts: 14 s to 5.3 s - collisions: over 60 s to 54 s, measured under the profiler before the last two changesCompare1014 return this.lineNumberOf(path, this.graph.lineN(line));
1017 /** lineNumber by the line's number, with no lookup of its id. */
1018 lineNumberOf(path: string, n: number): number {
init0Start the project1019 const f = this.#file(path);
1020 if (!f.visIndex) {
1021 f.visIndex = new Map();
1022 for (let i = 0; i < f.vis.length; i++) f.visIndex.set(f.vis[i]!, i);
capacity212Draft reads on a stored writer (disk-first 2; abso Capacity): where, drafts, status and collisions on website's export. - where looks deleted lines up by number (graph.deletedNumbers, View.fileOfNumber, View.lineNumberOf). It takes the agent's view once instead of once per line, since each read weighed every cached view. It finds the draft's lines by writer (View.visibleWriters), with no text or id read per line. - Draft files (overlaps.ts) go by number the same way. - An agent's view takes its base's resolved moves when both hold the same atoms that move lines (View.shareMoves checks this). - Draft collisions: - build the union view only when two drafts share a file; - work out each agent's touched files and its "shared now plus draft" view once; - find claimants among the drafts from the drafts' own keys (collisions.ts claimantsAmong) instead of walking each key's history; - have the definition rule keep a draft's uses, and the newer work's definitions, across partners. - A stored list read in order reads its length once, not before every element. draft-reads-stored.test.ts checks where and collisions against the in-memory project. It covers edits, a whole file deleted, a line collision, one name defined twice, and bases before and after a move. 135 of 136 related tests pass; none fail. On website's export (1,387 entries) the answers match Project.load: - status: 17 s to 4.5 s - where: over 60 s to 8.8 s - drafts: 14 s to 5.3 s - collisions: over 60 s to 54 s, measured under the profiler before the last two changesCompare1024 return f.visIndex.get(n) ?? -1;
1027 /** The seq of the atom that wrote each visible line, in order: lines() without ids or text. */
1028 visibleWriters(path: string): number[] {
1029 const graph = this.graph;
capacity231visibleWriters uses the writers the packed layout keeps (disk-first 2; abso Capacity). where asks each agent's view for its visible lines' writers in every file the draft touches. visibleWriters looked each one up again (graph.writerSeqOf), which on a stored graph read the line-atom pages: on typescript-rs that was 2.6 s of where's 4 s in SQLite. The packed layout already keeps them since 230 (visWriter). On typescript-rs adopted fresh, cold: where 39,000 reads to 20,000 and 6.5 s to 3.8 s, matching replay. Named tests: every engine test (288 of 288), where-many-agents, draft-reads-stored, authors-stored, packed-crossings, membership-pages, view-cache, files-reads, project (39 of 39); tsc and biome clean.Compare1030 const { vis, visWriter } = this.#file(path);
1031 // The packed layout keeps them (abso Capacity): looking each up again read a page per few lines on a stored graph.
1032 if (visWriter) return Array.from(visWriter);
1033 return Array.from(vis, (n) => graph.writerSeqOf(n));
init0Start the project1034 }
1036 /** All projected text files, path -> text, in path order. Binary files are in `blobs()`. */
1037 files(): Record<string, string> {
1038 const out: Record<string, string> = {};
1039 for (const path of this.paths()) if (this.#file(path).attrs.blob === null) out[path] = this.text(path);
1040 return out;
1043 /** Binary files, path -> the SHA-256 of their bytes, in path order. */
1044 blobs(): Record<string, string> {
1045 const out: Record<string, string> = {};
1046 for (const path of this.paths()) {
1047 const blob = this.#file(path).attrs.blob;
1048 if (blob !== null) out[path] = blob;
1050 return out;
1053 /**
codex-capacity-policy103Test deterministic replay and account view cache weightCompare1054 * About how many bytes of retained state this view costs (#46). This uses
1055 * approximate ownership costs for containers and wrappers, not V8 heap
1056 * measurements. Graph-owned strings and records count only as references.
1057 * This method only inspects already-created state: it does not lay out files,
1058 * populate lazy caches, enumerate the graph, or count temporary traversal
1059 * containers and shared empty singleton payloads as retained view state.
init0Start the project1060 */
1061 weight(): number {
codex-capacity-policy103Test deterministic replay and account view cache weightCompare1062 let n = this.#in.byteLength;
codex-capacity-chair116Bound repeated indexed view membership lookupsCompare1063 n += 2 * ARRAY_HEADER_BYTES + this.#membershipSeq.byteLength + this.#membershipValue.byteLength;
codex-capacity-chair123Stream mover history when opening persisted viewsCompare1064 if (this.#movers) n += ARRAY_HEADER_BYTES + REFERENCE_BYTES * this.#movers.length;
codex-capacity-policy103Test deterministic replay and account view cache weightCompare1065 n += MAP_HEADER_BYTES; // #files exists from construction.
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare1066 if (this.#stable) n += this.#stable.retainedBytes;
1067 else if (this.#set) n += OBJECT_BYTES + SET_ENTRY_BYTES * this.#set.size;
codex-capacity-policy103Test deterministic replay and account view cache weightCompare1068 if (this.#knownList) n += ARRAY_HEADER_BYTES + REFERENCE_BYTES * this.#knownList.length;
1069 if (this.#relocs) n += MAP_HEADER_BYTES + MAP_ENTRY_BYTES * this.#relocs.size;
1070 if (this.#relocsN) n += MAP_HEADER_BYTES + (MAP_ENTRY_BYTES + OBJECT_BYTES) * this.#relocsN.size;
capacity216Moves picked as walks reach them, and shared's file list from kept shapes (disk-first 2; abso Capacity), for abso's status, drafts and file list. - view.ts: a view picks a moved line's relocation only when a walk to find a line's file reaches that line. That is #relocations' own pick, right whenever the walk goes on to a file's start, since only lines on a loop have their relocation set aside; a walk that comes back to a line it passed resolves every move as before. shareMoves now takes the other view's moves only when this view first needs all of them, such as for a layout, so a view that only finds a few lines' files never resolves them. weight() counts the picks. - pathindex.ts keptPaths: shared's files at a version, folded from version 0 over each version's kept files made and taken out, with no file laid out. Only on a stored writer, and only when every version up to it has a kept row that describes it; otherwise the version is laid out as before. pathsAt uses it. On abso's export (81,855 entries, 1,224 versions), one opened project, answers matching Project.load: - status: 104 s to 5.8 s (under the profiler) - drafts: over 60 s to 5.7 s - files at head: over 60 s to 1.2 s - files at 612: 54 s to 0.3 s version-files.test.ts now also checks the file list at every version against the in-memory project. 124 of 124 related tests pass; tsc clean.Compare1071 n += MAP_ENTRY_BYTES * this.#picked.size;
codex-capacity-policy103Test deterministic replay and account view cache weightCompare1072 for (const f of this.#files.values()) {
1073 n += MAP_ENTRY_BYTES;
1074 if (f !== NO_FILE) {
1075 // FileState and FileAttrs are per laid-out file; typed-array
1076 // headers are separate from their payload byte lengths below.
1077 n += OBJECT_BYTES + OBJECT_BYTES + 2 * ARRAY_HEADER_BYTES;
1078 n += f.seq.byteLength + f.vis.byteLength;
capacity206Each file's line history packed (disk-first 2, lines by file; abso Capacity). A stored graph appends every line written in a file ([n, parent code, writer seq, k, replaces]) and its text, every delete of one of its lines, and every attribute set on it to that file's pages as atoms are added, a run at a time (storedLists appendAll). A view lays a file out from those pages in memory: membership checked once per atom, moves followed from the ones it already resolved, lines moved in from other files read from theirs. Same tree and order as before (packed-files.test.ts checks it against the in-memory graph through edits, deletes and moves). Graphs adopted before have no packs and lay out line by line as before; packFiles: false keeps that path for its tests. On game's export: first shared() 13 s to 2-3.6 s at 20,000 queries, warm 56-82 ms, pathsAt(head) 29-119 ms; files at a version 14 s to 3 s, compare 26 s to 11 s, a path's log 27 s to 4.5 s; every answer the harness finished matches Project.load.Compare1079 if (f.visText) for (const text of f.visText) n += REFERENCE_BYTES + 2 * (text?.length ?? 0);
capacity230Who wrote what, read from the packed layout and each atom's author once (disk-first 2; abso Capacity). On website, with one opened writer, tree with authors took 9.6 s, tree for an agent with authors 9.1 s, and a folder's blame 4.9 s. Replay takes about 0.25 s. Few row reads: the time went on reading the same few large atoms again and again. - tree with authors, a folder's blame and a file's blame look up each atom's author once per call. graph.atom read and parsed the whole atom for every line, and most lines share a few big atoms. - The packed layout keeps each visible line's writer (visWriter), and lines() and buildLines use it instead of looking each line's writer up again. - The packed layout reads each atom's lamport number once per layout instead of once per line. On website adopted fresh, cold: tree with authors 3.2 s, tree for an agent with authors 4.5 s, a folder's blame 2.4 s; all seven tree and blame answers match replay. New test authors-stored: tree with authors (head, an older version, an agent's draft, a folder), folder blame and file blame on a writer-backed project answer as the in-memory one; it fails when the layout records the wrong writer. Named tests: every engine test (288 of 288), authors-stored, history, trail, draft-reads-stored, packed-crossings, version-files, files-reads, view-cache, membership-pages, project (54 of 54); tsc and biome clean.Compare1080 if (f.visWriter) n += 4 * f.visWriter.length;
capacity232Line ids and writers from the packed layout, and a sequence's text read only when used (disk-first 2; abso Capacity). 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.Compare1081 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;
codex-capacity-policy103Test deterministic replay and account view cache weightCompare1084 n += MAP_HEADER_BYTES + (MAP_ENTRY_BYTES + ARRAY_HEADER_BYTES) * f.deletedBy.size;
1085 for (const deleters of f.deletedBy.values()) n += REFERENCE_BYTES * deleters.length;
1086 if (f.seqIndex) n += MAP_HEADER_BYTES + MAP_ENTRY_BYTES * f.seqIndex.size;
1087 if (f.visIndex) n += MAP_HEADER_BYTES + MAP_ENTRY_BYTES * f.visIndex.size;
1090 if (this.#linesCache)
1091 n += OBJECT_BYTES + REFERENCE_BYTES + ARRAY_HEADER_BYTES + 100 * this.#linesCache.lines.length;
1092 if (this.#seqCache) {
1093 n += OBJECT_BYTES + REFERENCE_BYTES + ARRAY_HEADER_BYTES + 120 * this.#seqCache.seq.length;
1094 for (const line of this.#seqCache.seq)
1095 if (line.deletedBy !== NONE) n += ARRAY_HEADER_BYTES + REFERENCE_BYTES * line.deletedBy.length;
1097 if (this.#textCache) n += OBJECT_BYTES + REFERENCE_BYTES + ARRAY_HEADER_BYTES + 2 * this.#textCache.text.length;
init0Start the project1098 return n;
codex-capacity-chair110Keep current-file views and key scans from retaining historical stateCompare1101 #file(path: string, complete = false): FileState {
init0Start the project1102 let state = this.#files.get(path);
codex-capacity-chair110Keep current-file views and key scans from retaining historical stateCompare1103 if (!state || (complete && !state.complete)) {
codex-capacity-chair119Page per-file atom indexes and stream current-view attribute scansCompare1104 state = this.graph.hasAtomsIn(path) ? this.#layout(path, complete) : NO_FILE;
init0Start the project1105 this.#files.set(path, state);
1107 return state;
1111/** The files of a closed set, path -> text. */
1112export function project(graph: Graph, set: Iterable<AtomId>): Record<string, string> {
1113 return new View(graph, set).files();
1116/** Where a node sits in a file's sequence: the index just after it (0 for a start node). */
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare1117export function indexAfter(view: Pick<ReadView, "sequenceIndex">, path: string, node: NodeId): number {
init0Start the project1118 if (isStartNode(node)) return 0;
1119 const i = view.sequenceIndex(path, node);
1120 if (i < 0) throw new EngineError("not-in-view", `line ${node} is not in ${path} in this view`);
1121 return i + 1;