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 249 --json
JSON
/christopher/abso-core/blame/src/engine/view.ts?version=249&format=json
1,203 linescapacity 46% · First import 31% · codex-capacity-chair 20% · codex-capacity-policy 3%Last change capacity in version 249,

1,203 lines from 39 changes in 36 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>,
capacity245Collisions step 1: whether a file exists, without laying it out (abso Capacity, issue 664). A published version's view on a writer answers hasFile from the kept path list (PathIndex.keptPathSet, the set pathsAt already answers from), and a draft's view asks its base for every file the draft doesn't touch. Resolving an import tried up to seven file names in collisions, and each check laid the whole file out. On the abso export (collisions, my machine): the first call lays out 130 files instead of 407, 13.4 s instead of 15.2 s; a warm call 7.7 s instead of 8.3 s (step 2 is most of what's left). Same answer as replay. Heap after a full warm run: 76.9 MB against 76.5 MB on 244. test/known-paths.test.ts: every name at versions 0 to 2 and in four drafts, against the in-memory project, before and after every file is read: a version that deletes a file and renames one with record, one that moves lines into a new file, and drafts that delete, rename, move lines and add.Compare52 | "sameText"
53 | "visibleCount"
54 | "shareMoves"
55 | "shareFiles"
56 | "knowPaths"
57 | "fileOfNumber"
58 | "lineNumberOf"
59 | "visibleWriters"
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 changesCompare60> & {
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare61 sameText(path: string, other: ReadView): boolean;
62};
init0Start the project64const NO_ATTRS: FileAttrs = { exists: false, exec: false, link: null, blob: null };
capacity241The view cache counts a file layout two views share once (disk-first 2; abso Capacity). Testing found collisions on abso slower with 240 than with 234 (warm 7.3 to 12.3 s). Since 235 a draft's view takes its base view's layout of every file the draft doesn't touch, so many cached views hold the same layouts. The cache counted each view's layouts in full, so the 24 MB budget filled with copies. That evicted views the next call needed, and a kept writer laid abso's drafts out again on every collisions call. - ViewCache keeps the newest views that fit the budget, as evicting oldest first does, counting a layout already counted for a newer view once (View.weight(seen)). - A layout's own bytes are worked out once per layout (layoutBytes): the cache weighs every view on every lookup, which summed every line's text again. On abso adopted fresh, one kept writer, against 240 on the same database: collisions 17.5 s to 11.9 s cold, 11.3 s to 6.1 s on the next call (49,000 and 19,000 reads, from 71,000 and 41,000). Both match replay. Heap after the run is the same with and without (about 125 to 130 MB with the kept writer); that's not from this change, and I'm reporting it separately. Named tests: view-cache (the eviction tests as before), every engine test (290 of 290), every worker/project test (341 of 341); tsc and biome clean.Compare65
66/**
67 * A file layout's bytes, less its lookup indexes, worked out once per layout (abso Capacity): a layout never changes
68 * once made, and the view cache weighs every view it holds on every lookup, which summed every line's text again.
69 */
70const layoutSizes = new WeakMap<FileState, number>();
71function layoutBytes(f: FileState): number {
72 let n = layoutSizes.get(f);
73 if (n !== undefined) return n;
74 // FileState and FileAttrs are per laid-out file; typed-array headers are separate from their payload byte lengths.
75 n = OBJECT_BYTES + OBJECT_BYTES + 2 * ARRAY_HEADER_BYTES;
76 n += f.seq.byteLength + f.vis.byteLength;
capacity247A kept reader settles after each read; line texts weigh what V8 holds (abso Capacity, issue 664). What a kept reader held on abso, measured per question without the answer itself (heap snapshot after tree with authors, 56.9 MB held): the view cache 38.3 MB against its 24 MB budget, the agents read 6.5 to 7.7 MB, the move skeleton 2.4 MB, the state cache 2.3 MB; the rest is the engine's indexes. - Project.afterRead: the view cache trimmed to its budget (ViewCache.trim) and the agents the read decoded let go (WriterAgents.release). Views grow while a call lays files out and the cache weighed them only when asked for again; a read-only reader never flushed its agents, so it held every agent's news told. - View weight: a laid-out line's text counts a 16-byte header and a byte a character (two outside Latin-1), rounded to 8, as V8 holds it. It counted 8 and two a character, so abso's whole shared layout (22.7 MB held) weighed about 28 MB, over the budget alone: once trimmed, it was laid out again for every question (blame folder 2.5 s became 14.4 s). Full warm run on the abso export: held heap at most 41.7 MB (was 56.9), 24 to 29 MB between the big reads (was 32 to 37); every answer the same. Status and drafts take about 30 ms more (agents read again); blame folder 1.7 s instead of 2.5 s. Tests: view-cache (trim reweighs growth with no further hit), after-read (new: reads before and after it, and a write after it, against the in-memory project), and the collision, path and compare tests: 21 of 21.Compare77 if (f.visText) for (const text of f.visText) n += REFERENCE_BYTES + (text === null ? 0 : stringBytes(text));
capacity241The view cache counts a file layout two views share once (disk-first 2; abso Capacity). Testing found collisions on abso slower with 240 than with 234 (warm 7.3 to 12.3 s). Since 235 a draft's view takes its base view's layout of every file the draft doesn't touch, so many cached views hold the same layouts. The cache counted each view's layouts in full, so the 24 MB budget filled with copies. That evicted views the next call needed, and a kept writer laid abso's drafts out again on every collisions call. - ViewCache keeps the newest views that fit the budget, as evicting oldest first does, counting a layout already counted for a newer view once (View.weight(seen)). - A layout's own bytes are worked out once per layout (layoutBytes): the cache weighs every view on every lookup, which summed every line's text again. On abso adopted fresh, one kept writer, against 240 on the same database: collisions 17.5 s to 11.9 s cold, 11.3 s to 6.1 s on the next call (49,000 and 19,000 reads, from 71,000 and 41,000). Both match replay. Heap after the run is the same with and without (about 125 to 130 MB with the kept writer); that's not from this change, and I'm reporting it separately. Named tests: view-cache (the eviction tests as before), every engine test (290 of 290), every worker/project test (341 of 341); tsc and biome clean.Compare78 if (f.visWriter) n += 4 * f.visWriter.length;
79 if (f.visK) n += 4 * f.visK.length;
80 if (f.seqWriter) n += 4 * f.seqWriter.length;
81 if (f.seqK) n += 4 * f.seqK.length;
82 n += MAP_HEADER_BYTES + (MAP_ENTRY_BYTES + ARRAY_HEADER_BYTES) * f.deletedBy.size;
83 for (const deleters of f.deletedBy.values()) n += REFERENCE_BYTES * deleters.length;
84 layoutSizes.set(f, n);
85 return n;
init0Start the project87const NONE: readonly never[] = Object.freeze([]);
89interface FileState {
90 readonly attrs: FileAttrs;
codex-capacity-chair110Keep current-file views and key scans from retaining historical stateCompare91 /** Full history is retained only when a sequence caller explicitly requests it. */
92 readonly complete: boolean;
init0Start the project93 /** The file's sequence, tombstones included: each line's n. */
94 readonly seq: Int32Array;
95 /** Its visible lines' n, in order. */
96 readonly vis: Int32Array;
97 /** For each deleted position in seq: the seqs of the atoms in the set that delete it, by priority. */
98 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.Compare99 /** Its visible lines' text, when laid out from the file's packed history: null for a line too long to pack. */
100 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.Compare101 /** Its visible lines' writers' seqs, when laid out from the file's packed history. */
102 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.Compare103 /** Its visible lines' places in their writers (a line id's k), when laid out from packed history. */
104 readonly visK?: Int32Array;
105 /** The same for every line of seq, when complete and laid out from packed history. */
106 readonly seqWriter?: Int32Array;
107 readonly seqK?: Int32Array;
init0Start the project108 /** Positions by n, built the first time they're asked for. */
109 seqIndex?: Map<number, number>;
110 visIndex?: Map<number, number>;
113interface Child {
114 readonly n: number;
115 /** 1 when the child's atom deleted the parent (the child replaces it), else 0. A moved line is 0. */
116 readonly replaces: number;
117 readonly lamport: number;
118 readonly seq: number;
119 readonly k: number;
122const EMPTY_INTS = new Int32Array(0);
codex-capacity-chair110Keep current-file views and key scans from retaining historical stateCompare123const NO_FILE: FileState = { attrs: NO_ATTRS, complete: true, seq: EMPTY_INTS, vis: EMPTY_INTS, deletedBy: new Map() };
init0Start the project124
codex-capacity-policy103Test deterministic replay and account view cache weightCompare125// Approximate retained-container costs for View.weight(): reference slots,
126// object headers, and map/set entries. These are cache-budget units, not V8
127// heap measurements. Referenced Graph strings and records are not charged.
128const ARRAY_HEADER_BYTES = 24;
129const OBJECT_BYTES = 32;
130const MAP_HEADER_BYTES = 32;
131const MAP_ENTRY_BYTES = 40;
132const SET_ENTRY_BYTES = 32;
133const REFERENCE_BYTES = 8;
capacity247A kept reader settles after each read; line texts weigh what V8 holds (abso Capacity, issue 664). What a kept reader held on abso, measured per question without the answer itself (heap snapshot after tree with authors, 56.9 MB held): the view cache 38.3 MB against its 24 MB budget, the agents read 6.5 to 7.7 MB, the move skeleton 2.4 MB, the state cache 2.3 MB; the rest is the engine's indexes. - Project.afterRead: the view cache trimmed to its budget (ViewCache.trim) and the agents the read decoded let go (WriterAgents.release). Views grow while a call lays files out and the cache weighed them only when asked for again; a read-only reader never flushed its agents, so it held every agent's news told. - View weight: a laid-out line's text counts a 16-byte header and a byte a character (two outside Latin-1), rounded to 8, as V8 holds it. It counted 8 and two a character, so abso's whole shared layout (22.7 MB held) weighed about 28 MB, over the budget alone: once trimmed, it was laid out again for every question (blame folder 2.5 s became 14.4 s). Full warm run on the abso export: held heap at most 41.7 MB (was 56.9), 24 to 29 MB between the big reads (was 32 to 37); every answer the same. Status and drafts take about 30 ms more (agents read again); blame folder 1.7 s instead of 2.5 s. Tests: view-cache (trim reweighs growth with no further hit), after-read (new: reads before and after it, and a write after it, against the in-memory project), and the collision, path and compare tests: 21 of 21.Compare134const STRING_HEADER_BYTES = 16;
135/**
136 * What V8 holds for a string of its own (abso Capacity, measured on abso's layouts): a header, then one byte a
137 * character when every character fits in Latin-1 and two otherwise, rounded up to 8.
138 */
capacity249Collisions step 3: each draft's definition work kept between calls, under a hard 4 MB budget (abso Capacity, issue 664). KeptParts (kept-parts.ts) holds what draft collisions work out about each draft and each pair of drafts: the names a draft's new lines use, the definitions a draft's changes touch before and after (the changed-definition rule), and the names two drafts both define in a file. Each entry is weighed as the view cache weighs views (line ids, texts, names: view.ts's stringBytes) and the whole stays under 4 MB, oldest out first; an entry over the budget isn't kept. Keys name everything an entry depends on: shared's version, the draft's base and its atoms. Each collisions call drops every entry it didn't use, so a draft that changes, an agent that leaves or shared moving on drops theirs at once. On a stored writer only; the publish check (land.ts) and the in-memory project work as before. On the abso export (my machine): a warm collisions call takes 322 ms instead of 3.4 s, with the same answer as replay. A full warm run's held heap is at most 42.9 MB (41.7 MB without it), and all 33 answers match. Tests: kept-parts (new: the budget, oldest out first, an oversized entry never kept, a round dropping what it didn't use) and collisions-kept-views, which now runs through the kept parts on the writer (a draft changing, shared moving on, a draft dropped, each asked twice against the in-memory project). With the collision, definition, path and view tests: 47 of 47.Compare139export function stringBytes(text: string): number {
capacity247A kept reader settles after each read; line texts weigh what V8 holds (abso Capacity, issue 664). What a kept reader held on abso, measured per question without the answer itself (heap snapshot after tree with authors, 56.9 MB held): the view cache 38.3 MB against its 24 MB budget, the agents read 6.5 to 7.7 MB, the move skeleton 2.4 MB, the state cache 2.3 MB; the rest is the engine's indexes. - Project.afterRead: the view cache trimmed to its budget (ViewCache.trim) and the agents the read decoded let go (WriterAgents.release). Views grow while a call lays files out and the cache weighed them only when asked for again; a read-only reader never flushed its agents, so it held every agent's news told. - View weight: a laid-out line's text counts a 16-byte header and a byte a character (two outside Latin-1), rounded to 8, as V8 holds it. It counted 8 and two a character, so abso's whole shared layout (22.7 MB held) weighed about 28 MB, over the budget alone: once trimmed, it was laid out again for every question (blame folder 2.5 s became 14.4 s). Full warm run on the abso export: held heap at most 41.7 MB (was 56.9), 24 to 29 MB between the big reads (was 32 to 37); every answer the same. Status and drafts take about 30 ms more (agents read again); blame folder 1.7 s instead of 2.5 s. Tests: view-cache (trim reweighs growth with no further hit), after-read (new: reads before and after it, and a write after it, against the in-memory project), and the collision, path and compare tests: 21 of 21.Compare140 const chars = /[^\u0000-\u00ff]/.test(text) ? 2 * text.length : text.length;
141 return (STRING_HEADER_BYTES + chars + 7) & ~7;
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.Compare143/**
144 * Moved lines a view resolves once and keeps (abso Capacity): a stored graph otherwise resolved every move again on
145 * disk for each file it laid out. Game's whole history has 290; past this many, the view goes back to that.
146 */
147export const MOVED_LINES_KEPT = 20_000;
148class TooManyMoves extends Error {}
149const 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.Compare150/** Nodes whose nearest moved line above a graph remembers, at most: about 40 bytes each. */
151const CLIMB_MEMO = 200_000;
codex-capacity-policy103Test deterministic replay and account view cache weightCompare152
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.Compare153/** One relocation of a moved line, with its line's number and its new parent's code. */
154interface MoveEntry {
155 readonly n: number;
156 readonly r: RelocationInfo;
157 readonly parent: number;
init0Start the project160/**
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.Compare161 * A graph's moves, whatever the set (abso Capacity): each mover's moved lines, each moved line's relocations in seq
162 * order, and for any node the nearest node at or above it, by where lines were written, that a move ever relocated,
163 * or its file's start. Worked out once per graph and extended as it grows. A view's moves then resolve over the moved
164 * lines alone: before, every view walked each moved line's file up to its start, a read per line.
165 */
166class MoveSkeleton {
167 readonly #graph: Graph;
168 #seen = 0;
169 /** Movers in seq order, with the numbers of the lines each moves, in its moves' order. */
170 readonly movers: { readonly seq: number; readonly lines: readonly number[] }[] = [];
171 /** Every relocation of each moved line, by the line's number, in seq order. */
172 readonly byLine = new Map<number, MoveEntry[]>();
173 readonly #climbed = new Map<number, number>();
175 constructor(graph: Graph) {
176 this.#graph = graph;
177 }
capacity238Collisions: deleted lines found by number, and the move index skips graphs that gained nothing (disk-first 2; abso Capacity). Collisions on website took 20.7 s cold with one opened writer (replay 0.4 s), and 46 s on typescript-rs (replay 5 s). - touchedFiles finds each deleted line's file by its number where the view can (fileOfNumber). A draft deleting a big file has thousands; making each one's id only to look its number up again was most of the time. - Graph.accepted counts the atoms a graph object has taken in, in memory. The move index (MoveSkeleton) is brought up to date on every lookup of a line's file. It now reads the movers list only when that count has changed: checking the stored list's length and last mover each time cost 3.3 s of collisions on website. A rolled-back add still counts, which only makes it look again. On website adopted fresh, cold: collisions 20.7 s to 9.6 s. On typescript-rs: 46 s to 11.7 s. Both match replay, and all 27 typescript-rs answers match. Still slow: reading every draft atom's write keys, a row per key once there are more than 256 (75,000 rows on website). Named tests: every engine test (288 of 288), every worker/project test (341 of 341); tsc and biome clean.Compare179 /** The graph's accepted count when movers were last taken in: nothing to read while it's the same. */
180 #stamp = -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.Compare182 /** Take in movers the graph gained since. */
183 update(): this {
184 const graph = this.#graph;
capacity238Collisions: deleted lines found by number, and the move index skips graphs that gained nothing (disk-first 2; abso Capacity). Collisions on website took 20.7 s cold with one opened writer (replay 0.4 s), and 46 s on typescript-rs (replay 5 s). - touchedFiles finds each deleted line's file by its number where the view can (fileOfNumber). A draft deleting a big file has thousands; making each one's id only to look its number up again was most of the time. - Graph.accepted counts the atoms a graph object has taken in, in memory. The move index (MoveSkeleton) is brought up to date on every lookup of a line's file. It now reads the movers list only when that count has changed: checking the stored list's length and last mover each time cost 3.3 s of collisions on website. A rolled-back add still counts, which only makes it look again. On website adopted fresh, cold: collisions 20.7 s to 9.6 s. On typescript-rs: 46 s to 11.7 s. Both match replay, and all 27 typescript-rs answers match. Still slow: reading every draft atom's write keys, a row per key once there are more than 256 (75,000 rows on website). Named tests: every engine test (288 of 288), every worker/project test (341 of 341); tsc and biome clean.Compare185 if (this.#stamp === graph.accepted) return this;
186 this.#stamp = graph.accepted;
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.Compare187 const all = graph.movers();
188 if (this.#seen === all.length) return this;
189 for (; this.#seen < all.length; this.#seen++) {
190 const id = all[this.#seen]!;
191 const lines: number[] = [];
192 graph.atom(id).moves!.forEach((m, k) => {
193 const n = graph.lineN(m.line);
194 const r: RelocationInfo = Object.freeze({ atom: id, line: m.line, parent: m.parent, k });
195 const entry: MoveEntry = { n, r, parent: graph.codeOf(m.parent)! };
196 const list = this.byLine.get(n);
197 if (list) list.push(entry);
198 else this.byLine.set(n, [entry]);
199 lines.push(n);
200 });
201 this.movers.push({ seq: seqOf(id), lines });
202 }
203 // A new moved line can sit between a node and the one it climbed to.
204 this.#climbed.clear();
205 return this;
206 }
208 /** The nearest node at or above this one, by where lines were written, that a move ever relocated; or its file's start. */
209 climb(code: number): number {
210 const walked: number[] = [];
211 let c = code;
212 while (c >= 0 && !this.byLine.has(c)) {
213 const known = this.#climbed.get(c);
214 if (known !== undefined) {
215 c = known;
216 break;
217 }
218 walked.push(c);
219 c = this.#graph.parentCodeOf(c);
220 }
221 if (this.#climbed.size + walked.length > CLIMB_MEMO) this.#climbed.clear();
222 for (const w of walked) this.#climbed.set(w, c);
223 return c;
224 }
227const skeletons = new WeakMap<Graph, MoveSkeleton>();
228function skeletonOf(graph: Graph): MoveSkeleton {
229 let skeleton = skeletons.get(graph);
230 if (!skeleton) skeletons.set(graph, (skeleton = new MoveSkeleton(graph)));
231 return skeleton.update();
234/**
init0Start the project235 * The projection of a closed set. Construct once, then ask for files, lines
236 * and sequences. Throws `not-closed` if some atom's dependency is missing.
237 * Each file is laid out the first time it is asked for, so a view of a large
238 * set costs little until files are read.
239 */
240export class View {
241 readonly graph: Graph;
242 /** 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 adoptionCompare243 #set: AtomSet | undefined;
244 readonly #stable: StableSet<AtomId> | undefined;
codex-capacity-chair116Bound repeated indexed view membership lookupsCompare245 /** Fixed-size memo for immutable indexed membership, independent of history size. */
246 #membershipSeq = new Float64Array(256).fill(-1);
247 #membershipValue = new Uint8Array(256);
init0Start the project248 #files = new Map<string, FileState>();
249 /** Every file the set wrote in, sorted; worked out the first time it's asked for. */
250 #knownList: string[] | undefined;
251 /** 1 for each atom (by seq) in the set. */
252 #in: Uint8Array;
253 /** Atoms in the set that move lines. */
codex-capacity-chair123Stream mover history when opening persisted viewsCompare254 #movers: AtomId[] | undefined;
255 #hasMoves = false;
init0Start the project256 /** Each moved line's relocation that counts in this set; built on first use. */
257 #relocs: Map<LineId, RelocationInfo> | undefined;
258 /** The same, by n, with the new parent's code. */
259 #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.Compare260 /** The moved lines under each node, by its code, made from the relocations on first use. */
261 #movedInto: Map<number, number[]> | undefined;
262 /** Whether this view's moves are too many to keep, so they're resolved on disk per layout; undefined until asked. */
263 #movesOnDisk: boolean | undefined;
init0Start the project264 /** The latest records asked for: one file's lines, one file's sequence, one file's text. */
265 #linesCache: { path: string; lines: readonly VisibleLine[] } | undefined;
266 #seqCache: { path: string; seq: readonly SeqLine[] } | undefined;
267 #textCache: { path: string; text: string } | undefined;
269 constructor(graph: Graph, set: Iterable<AtomId>) {
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare270 this.graph = graph;
271 if (set instanceof StableSet) {
272 this.#stable = set;
273 this.#set = set;
274 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.Compare275 // A set kept closed when it was written needs no proof here (abso Capacity).
276 for (const id of isClosedSet(set) ? [] : set) {
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare277 const atom = graph.atom(id);
278 for (const dependency of atom.deps) {
279 graph.atom(dependency);
280 if (!set.has(dependency))
281 throw new EngineError("not-closed", `set is not closed: ${id} depends on ${dependency}`);
282 }
283 }
codex-capacity-chair123Stream mover history when opening persisted viewsCompare284 for (const id of graph.movers()) {
285 if (set.has(id)) {
286 this.#hasMoves = true;
287 break;
288 }
289 }
290 this.#relocs = this.#hasMoves ? undefined : new Map();
291 this.#relocsN = this.#hasMoves ? undefined : new Map();
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare292 return;
293 }
init0Start the project294 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.Compare295 // An atom's number is in its id (abso Capacity): reading the atom for it read the whole history on a stored graph.
296 const seqIn = (id: AtomId): number => {
297 const seq = seqOf(id);
298 return seq >= 0 && seq < inSet.length && graph.idOfSeq(seq) === id ? seq : graph.atom(id).seq;
299 };
300 for (const id of set) inSet[seqIn(id)] = 1;
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare301 // Validate one atom at a time. Keeping all decoded atoms here defeats
302 // storage-backed Graph reads even though the view only needs membership.
303 for (let seq = 0; seq < inSet.length; seq++) {
304 if (inSet[seq] !== 1) continue;
305 const atom = graph.atom(graph.idOfSeq(seq));
init0Start the project306 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.Compare307 if (inSet[seqIn(d)] !== 1) throw new EngineError("not-closed", `set is not closed: ${atom.id} depends on ${d}`);
init0Start the project308 }
309 }
310 this.graph = graph;
311 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.Compare312 this.#movers = graph.movers().filter((id) => inSet[seqOf(id)] === 1);
codex-capacity-chair123Stream mover history when opening persisted viewsCompare313 this.#hasMoves = this.#movers.length > 0;
init0Start the project314 this.#relocs = this.#movers.length === 0 ? new Map() : undefined;
315 this.#relocsN = this.#movers.length === 0 ? new Map() : undefined;
316 }
318 /** The set of atoms this view projects. */
319 get set(): AtomSet {
320 if (!this.#set) {
321 const out = new Set<AtomId>();
322 for (let seq = 0; seq < this.#in.length; seq++) if (this.#in[seq] === 1) out.add(this.graph.idOfSeq(seq));
323 this.#set = out;
324 }
325 return this.#set;
326 }
328 /** Whether the atom with this seq is in the set. */
329 #has(seq: number): boolean {
codex-capacity-chair116Bound repeated indexed view membership lookupsCompare330 if (this.#stable) {
331 const slot = seq % this.#membershipSeq.length;
332 if (this.#membershipSeq[slot] === seq) return this.#membershipValue[slot] === 1;
333 const present = this.#stable.has(this.graph.idOfSeq(seq));
334 this.#membershipSeq[slot] = seq;
335 this.#membershipValue[slot] = present ? 1 : 0;
336 return present;
337 }
init0Start the project338 return seq < this.#in.length && this.#in[seq] === 1;
339 }
341 /**
342 * The relocation that counts for each moved line: the newest (by priority)
343 * in the set. Two moves made apart can loop lines into each other, so no
344 * start node reaches them; then the oldest relocation on the loop is
345 * ignored, and the next newest of that line counts, until none loop.
346 */
347 #relocations(): Map<LineId, RelocationInfo> {
348 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.Compare349 this.#takeShared();
350 if (this.#relocs) return this.#relocs;
init0Start the project351 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.Compare352 const skeleton = skeletonOf(graph);
init0Start the project353 const stronger = (a: RelocationInfo, b: RelocationInfo): boolean => graph.comparePriority(a.atom, b.atom) > 0;
codex-capacity-chair126Identify suppressed relocation cycles across persistent readsCompare354 const identity = (r: RelocationInfo): string => JSON.stringify([r.atom, r.k]);
355 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.Compare356 const pick = (n: number): MoveEntry | undefined => {
357 let best: MoveEntry | undefined;
358 for (const e of skeleton.byLine.get(n) ?? []) {
359 if (this.#has(seqOf(e.r.atom)) && !ignored.has(identity(e.r)) && (!best || stronger(e.r, best.r))) best = e;
init0Start the project360 }
361 return best;
362 };
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.Compare363 // By the moved line's number, in the order its movers come (seq order, then each mover's moves).
364 const relocs = new Map<number, MoveEntry>();
365 for (const mover of skeleton.movers) {
366 if (!this.#has(mover.seq)) continue;
367 for (const n of mover.lines) {
368 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.Compare369 if (graph.hasOrderedChildren && relocs.size > MOVED_LINES_KEPT) throw new TooManyMoves();
init0Start the project370 }
371 }
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.Compare372 // From a node, the next node that matters for loops: a line moved in this set, or a file's start.
373 const hop = (code: number): number => {
374 let c = skeleton.climb(code);
375 while (c >= 0 && !relocs.has(c)) c = skeleton.climb(graph.parentCodeOf(c));
376 return c;
377 };
378 const step = (n: number): number => {
379 const e = relocs.get(n);
380 return hop(e ? e.parent : graph.parentCodeOf(n));
381 };
382 // Two moves made apart can loop lines into each other, so no start node reaches them; then the oldest
383 // relocation on the loop is ignored, and the next newest of that line counts, until none loop.
384 const reaches = new Set<number>();
init0Start the project385 for (const line of [...relocs.keys()]) {
386 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.Compare387 const path: number[] = [];
388 const onPath = new Map<number, number>();
389 let cur = line;
init0Start the project390 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.Compare391 while (cur >= 0 && !reaches.has(cur)) {
init0Start the project392 const at = onPath.get(cur);
393 if (at !== undefined) {
394 loopAt = at;
395 break;
396 }
397 onPath.set(cur, path.length);
398 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.Compare399 cur = step(cur);
init0Start the project400 }
401 if (loopAt < 0) {
402 for (const l of path) reaches.add(l);
403 break;
404 }
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.Compare405 let weakest: MoveEntry | undefined;
init0Start the project406 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.Compare407 const e = relocs.get(l);
408 if (e && (!weakest || stronger(weakest.r, e.r))) weakest = e;
init0Start the project409 }
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.Compare410 ignored.add(identity(weakest!.r));
411 const next = pick(weakest!.n);
412 if (next) relocs.set(weakest!.n, next);
413 else relocs.delete(weakest!.n);
init0Start the project414 }
415 }
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.Compare416 this.#relocsN = new Map([...relocs].map(([n, e]) => [n, { r: e.r, parent: e.parent }]));
417 this.#relocs = new Map([...relocs.values()].map((e) => [e.r.line, e.r]));
418 return this.#relocs;
init0Start the project419 }
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.Compare420
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.Compare421 /** The view whose moves this one may take, until it needs them all; then the view it took them from. */
422 #movesFrom: View | undefined;
423 #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.Compare425 /**
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 changesCompare426 * 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.Compare427 * moves then resolve the same, and every line sits where it sits there. Checked when this view first needs all its
428 * 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.Compare429 */
430 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.Compare431 if (from.graph !== this.graph || from.#hasMoves !== this.#hasMoves || !this.#hasMoves || this.#relocs) return;
432 this.#movesFrom = from;
433 }
capacity235A draft's view takes its base view's layout of every file the draft doesn't touch (disk-first 2; abso Capacity). An agent's tree, files and folder blame lay out every file in the agent's view, and tree also lays out the base to see which files the draft changed. Each layout read the file's packed history again, though every file the draft doesn't touch lays out exactly as in the draft's base. - View.shareFiles(from, except): a view lays out a file by taking from's layout of it, unless the file is in except. except is worked out once, when a file is first needed. - Project.#agentView sets it for a draft's view over its base's when the draft moves nothing (its moves are then the base's, as shareMoves already relies on). The touched files are touchedFiles over the draft's atoms, in both views: the files they write, delete in, set attributes on, and, where moves count, the files their deleted lines and their runs' parents sit in. On abso adopted fresh, one kept writer: an agent's tree with authors 23.4 s to 12 to 14 s. It's still slow because a whole abso layout is bigger than the views' byte budget, so it isn't kept between calls. New test agent-views-shared: after a published move of a function into another file, drafts that edit a moved line, delete one, change another file, set an attribute, or move lines themselves each read every file (text, attributes, writers) as the in-memory project does, read twice; it fails when the touched files are taken from where lines were written only. Named tests: every engine test (288 of 288), every worker/project test (338 of 338); typescript-rs, all 27 answers match replay; tsc and biome clean.Compare435 /**
436 * Files laid out as another view lays them out (abso Capacity): a draft's view over its base's, for every file the
437 * draft doesn't touch. The caller knows what the draft is; `except` is asked once, when a file is first needed, for
438 * the files the draft touches, or undefined when nothing can be shared (a draft that moves lines). Without it, an
439 * agent's tree, files and blame laid out every file of the project again for each agent.
440 */
441 shareFiles(from: View, except: () => ReadonlySet<string> | undefined): void {
442 if (from.graph !== this.graph || from === this || this.#filesFrom !== undefined) return;
443 this.#filesFrom = { from, except };
444 }
445 #filesFrom: { from: View; except: () => ReadonlySet<string> | undefined } | null | undefined;
capacity245Collisions step 1: whether a file exists, without laying it out (abso Capacity, issue 664). A published version's view on a writer answers hasFile from the kept path list (PathIndex.keptPathSet, the set pathsAt already answers from), and a draft's view asks its base for every file the draft doesn't touch. Resolving an import tried up to seven file names in collisions, and each check laid the whole file out. On the abso export (collisions, my machine): the first call lays out 130 files instead of 407, 13.4 s instead of 15.2 s; a warm call 7.7 s instead of 8.3 s (step 2 is most of what's left). Same answer as replay. Heap after a full warm run: 76.9 MB against 76.5 MB on 244. test/known-paths.test.ts: every name at versions 0 to 2 and in four drafts, against the in-memory project, before and after every file is read: a version that deletes a file and renames one with record, one that moves lines into a new file, and drafts that delete, rename, move lines and add.Compare446
447 /**
448 * The files this view's set has, from what the project keeps for a published version (abso Capacity): hasFile
449 * answers from it, not a layout of the file. Collisions resolving an import tried up to seven names, and each one
450 * laid its file out. `paths` is asked once, when first needed; undefined lays files out as before.
451 */
452 knowPaths(paths: () => ReadonlySet<string> | undefined): void {
453 if (this.#pathsFrom === undefined) this.#pathsFrom = paths;
454 }
455 #pathsFrom: (() => ReadonlySet<string> | undefined) | undefined;
456 #knownPaths: ReadonlySet<string> | null | undefined;
capacity235A draft's view takes its base view's layout of every file the draft doesn't touch (disk-first 2; abso Capacity). An agent's tree, files and folder blame lay out every file in the agent's view, and tree also lays out the base to see which files the draft changed. Each layout read the file's packed history again, though every file the draft doesn't touch lays out exactly as in the draft's base. - View.shareFiles(from, except): a view lays out a file by taking from's layout of it, unless the file is in except. except is worked out once, when a file is first needed. - Project.#agentView sets it for a draft's view over its base's when the draft moves nothing (its moves are then the base's, as shareMoves already relies on). The touched files are touchedFiles over the draft's atoms, in both views: the files they write, delete in, set attributes on, and, where moves count, the files their deleted lines and their runs' parents sit in. On abso adopted fresh, one kept writer: an agent's tree with authors 23.4 s to 12 to 14 s. It's still slow because a whole abso layout is bigger than the views' byte budget, so it isn't kept between calls. New test agent-views-shared: after a published move of a function into another file, drafts that edit a moved line, delete one, change another file, set an attribute, or move lines themselves each read every file (text, attributes, writers) as the in-memory project does, read twice; it fails when the touched files are taken from where lines were written only. Named tests: every engine test (288 of 288), every worker/project test (338 of 338); typescript-rs, all 27 answers match replay; tsc and biome clean.Compare457 #filesShared: { from: View; except: ReadonlySet<string> } | null | undefined;
458 #sharedFiles(): { from: View; except: ReadonlySet<string> } | null {
459 if (this.#filesShared === undefined) {
460 const share = this.#filesFrom;
461 const except = share ? share.except() : undefined;
462 this.#filesShared = share && except ? { from: share.from, except } : null;
463 }
464 return this.#filesShared;
465 }
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.Compare467 #takeShared(): void {
468 const from = this.#movesFrom;
469 if (!from) return;
470 this.#movesFrom = undefined;
471 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 changesCompare472 for (const id of this.graph.movers()) {
473 const seq = seqOf(id);
474 if (this.#has(seq) !== from.#has(seq)) return;
475 }
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.Compare476 this.#relocs = from.#relocations();
477 this.#relocsN = from.#relocationsN();
478 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.Compare479 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.Compare480 }
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.Compare481
482 /** Moved lines' relocations picked one at a time, before the view resolves them all (null: not moved here). */
483 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.Compare484
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.Compare485 /**
486 * The relocation of moved line n that counts here, as #relocations picks it before any loop: right whenever the
487 * walk that reached n goes on to a file's start, since only lines on a loop have their relocation set aside.
488 */
489 #pickOne(n: number): MoveEntry | undefined {
490 let picked = this.#picked.get(n);
491 if (picked === undefined) {
492 const graph = this.graph;
493 let best: MoveEntry | undefined;
494 for (const e of skeletonOf(graph).byLine.get(n) ?? []) {
495 if (this.#has(seqOf(e.r.atom)) && (!best || graph.comparePriority(e.r.atom, best.r.atom) > 0)) best = e;
496 }
497 this.#picked.set(n, (picked = best ?? null));
498 }
499 return picked ?? undefined;
500 }
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.Compare502 /** Whether moves are resolved on disk for each layout: only a stored graph's view with more than MOVED_LINES_KEPT. */
503 #scratchMoves(): boolean {
504 if (!this.#hasMoves || !this.graph.hasOrderedChildren) return false;
505 if (this.#movesOnDisk === undefined) {
506 try {
507 this.#relocations();
508 this.#movesOnDisk = false;
509 } catch (error) {
510 if (!(error instanceof TooManyMoves)) throw error;
511 this.#movesOnDisk = true;
512 }
513 }
514 return this.#movesOnDisk;
515 }
init0Start the project517 /** The relocations by n, with each new parent's code. */
518 #relocationsN(): Map<number, { readonly r: RelocationInfo; readonly parent: number }> {
519 if (this.#relocsN) return this.#relocsN;
520 const out = new Map<number, { readonly r: RelocationInfo; readonly parent: number }>();
521 for (const [line, r] of this.#relocations())
522 out.set(this.graph.lineN(line), { r, parent: this.graph.codeOf(r.parent)! });
523 this.#relocsN = out;
524 return out;
525 }
527 /** The node a line hangs off in this set: where it was written, or where a move put it. */
528 parentOf(line: LineId): NodeId {
codex-capacity-chair132Bound persistent relocation projection memory with rollback-only scratchCompare529 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.Compare530 if (this.#scratchMoves())
codex-capacity-chair132Bound persistent relocation projection memory with rollback-only scratchCompare531 return this.graph.withProjectionScratch((scratch) =>
532 resolveScratchMoves(this.graph, (id) => this.#has(this.graph.atom(id).seq), scratch).parent(line),
533 );
codex-capacity-chair123Stream mover history when opening persisted viewsCompare534 const r = this.#hasMoves ? this.#relocations().get(line) : undefined;
init0Start the project535 if (r) return r.parent;
536 const parent = this.graph.lineParent(line);
537 if (parent === undefined) throw new EngineError("unknown-line", `no line ${line}`);
538 return parent;
539 }
541 /** Whether any atom in the set moves lines. */
542 hasMoves(): boolean {
codex-capacity-chair123Stream mover history when opening persisted viewsCompare543 return this.#hasMoves;
init0Start the project544 }
546 /** The file a line is in, in this set: the one its chain of parents reaches. */
547 fileOf(line: LineId): string {
548 const n = this.graph.lineN(line);
549 if (n < 0) throw new EngineError("unknown-line", `no line ${line}`);
550 return this.#fileOfN(n);
551 }
553 #fileOfN(n: number): string {
554 const graph = this.graph;
codex-capacity-chair123Stream mover history when opening persisted viewsCompare555 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.Compare556 if (this.#scratchMoves())
codex-capacity-chair132Bound persistent relocation projection memory with rollback-only scratchCompare557 return graph.withProjectionScratch((scratch) => {
558 const moves = resolveScratchMoves(graph, (id) => this.#has(graph.atom(id).seq), scratch);
559 let current = graph.nodeOf(n);
560 while (!isStartNode(current)) current = moves.parent(current);
561 return current.slice(1);
562 });
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.Compare563 return this.#fileOfCode(n);
564 }
566 /** The file a node sits in, in this set: up by where lines were written, through the moves that count here. */
567 #fileOfCode(code: number): string {
568 const graph = this.graph;
569 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.Compare570 if (!this.#relocsN) {
571 // One moved line at a time, until a walk comes back to a line it passed: then moves loop, and are resolved whole.
572 const passed = new Set<number>();
573 let c = code;
574 for (;;) {
575 c = skeleton.climb(c);
576 if (c < 0) return graph.nodeOf(c).slice(1);
577 if (passed.has(c)) break;
578 passed.add(c);
579 const e = this.#pickOne(c);
580 c = e ? e.parent : graph.parentCodeOf(c);
581 }
582 }
init0Start the project583 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.Compare584 let c = code;
585 for (;;) {
586 c = skeleton.climb(c);
587 if (c < 0) return graph.nodeOf(c).slice(1);
588 const e = relocs.get(c);
589 c = e ? e.parent : graph.parentCodeOf(c);
init0Start the project590 }
591 }
593 /** The lines hanging off a node in this set, in layout order. */
594 #children(code: number): Child[] {
595 const graph = this.graph;
codex-capacity-chair123Stream mover history when opening persisted viewsCompare596 const relocs = this.#hasMoves ? this.#relocationsN() : undefined;
init0Start the project597 const out: Child[] = [];
codex-capacity-chair130Stream paged child history into layout filteringCompare598 for (const n of graph.eachChildN(code)) {
init0Start the project599 const seq = graph.writerSeqOf(n);
600 if (!this.#has(seq) || relocs?.has(n)) continue;
601 out.push({ n, replaces: graph.replacesN(n) ? 1 : 0, lamport: graph.lamportOfSeq(seq), seq, k: graph.kOf(n) });
602 }
603 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.Compare604 // The lines this set's moves put under each node, from the moves it already resolved: no row read per node
605 // (abso Capacity).
606 if (!this.#movedInto) {
607 this.#movedInto = new Map();
608 for (const [n, { parent }] of relocs) {
609 const into = this.#movedInto.get(parent);
610 if (into) into.push(n);
611 else this.#movedInto.set(parent, [n]);
612 }
613 }
614 for (const n of this.#movedInto.get(code) ?? NO_LINES) {
615 const r = relocs.get(n)!.r;
init0Start the project616 const seq = graph.atom(r.atom).seq;
617 out.push({ n, replaces: 0, lamport: graph.lamportOfSeq(seq), seq, k: r.k });
618 }
619 }
620 // A line's replacements (runs of atoms that deleted it) first, then the
621 // rest; each group in descending priority (lamport, then seq); lines of
622 // one atom keep k order. A replacement already outranks every insertion
623 // after the line that reads it (it depends on them, or conflicts with
624 // them); the grouping also puts it above a `before` insertion, which
625 // doesn't read the line above, so the new text lands in the replaced
626 // line's place. A moved line ranks like an insertion by the moving atom.
627 if (out.length > 1)
628 out.sort((a, b) => b.replaces - a.replaces || b.lamport - a.lamport || b.seq - a.seq || a.k - b.k);
629 return out;
630 }
codex-capacity-chair131Bound persisted no-move layout with ordered successor traversalCompare632 /** Parent/successor traversal keeps no history-sized ancestry or sibling frontier. */
633 *#layoutNodes(start: number): IterableIterator<number> {
634 const graph = this.graph;
635 if (graph.hasOrderedChildren && !this.#hasMoves) {
636 const first = (parent: number, after?: number): number | undefined => {
637 for (const n of graph.orderedChildrenN(parent, after)) if (this.#has(graph.writerSeqOf(n))) return n;
638 return undefined;
639 };
640 let n = first(start);
641 while (n !== undefined) {
642 yield n;
643 const child = first(n);
644 if (child !== undefined) {
645 n = child;
646 continue;
647 }
648 let previous = n;
649 for (;;) {
650 const parent = graph.parentCodeOf(previous);
651 const sibling = first(parent, previous);
652 if (sibling !== undefined) {
653 n = sibling;
654 break;
655 }
656 if (parent === start) {
657 n = undefined;
658 break;
659 }
660 if (parent < 0 || parent >= previous) throw new Error("invalid persistent layout ancestry");
661 previous = parent;
662 }
663 }
664 return;
665 }
init0Start the project666 const stack: number[] = [];
codex-capacity-chair131Bound persisted no-move layout with ordered successor traversalCompare667 const push = (parent: number): void => {
668 const children = this.#children(parent);
669 for (let i = children.length - 1; i >= 0; i--) stack.push(children[i]!.n);
670 };
671 push(start);
672 while (stack.length) {
673 const n = stack.pop()!;
674 yield n;
675 push(n);
676 }
677 }
init0Start the project679 /** 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 stateCompare680 #layout(path: string, complete: boolean): FileState {
init0Start the project681 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.Compare682 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.Compare683 if (this.#scratchMoves())
codex-capacity-chair132Bound persistent relocation projection memory with rollback-only scratchCompare684 return graph.withProjectionScratch((scratch) =>
685 this.#layoutResolved(
686 path,
687 complete,
688 scratchLayoutNodes(graph, (id) => this.#has(graph.atom(id).seq), scratch, `^${path}`),
689 ),
690 );
691 return this.#layoutResolved(path, complete);
692 }
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.Compare694 /** For each path, the files that lines moved into it were written in: worked out once per view. */
695 #movedFrom: Map<string, Set<number>> | undefined;
696 #movedInFrom(): Map<string, Set<number>> {
697 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.Compare698 this.#relocations();
699 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.Compare700 const graph = this.graph;
701 const out = new Map<string, Set<number>>();
702 if (this.#hasMoves) {
703 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.Compare704 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.Compare705 for (const [n, { parent }] of relocs) {
706 const into = fileOf(parent);
707 let from = out.get(into);
708 if (!from) out.set(into, (from = new Set()));
709 from.add(graph.writtenInIndex(n));
710 }
711 }
712 this.#movedFrom = out;
713 return out;
714 }
716 /**
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.Compare717 * Lay one file out from its packed history (abso Capacity, Graph.packedLines): the lines written in it, in the files
718 * its moved-in lines came from, and in the files runs under any of those lines were written in, read a page at a
719 * 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.Compare720 */
721 #layoutPacked(path: string, complete: boolean): FileState {
722 const graph = this.graph;
723 const attrs = this.#attributes(path);
724 const start = graph.startCodeOf(path);
725 if (start === undefined) return { attrs, complete, seq: EMPTY_INTS, vis: EMPTY_INTS, deletedBy: new Map() };
726 const relocs = this.#hasMoves ? this.#relocationsN() : undefined;
727 const files = new Set<number>([-1 - start, ...(this.#movedInFrom().get(path) ?? [])]);
728 const children = new Map<number, Child[]>();
729 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.Compare730 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.Compare731 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.Compare732 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.Compare733 // Each atom's lamport once per layout: most lines share a few atoms, and a stored graph reads it from a page.
734 const lamports = new Map<number, number>();
735 const lamportOf = (seq: number): number => {
736 let lamport = lamports.get(seq);
737 if (lamport === undefined) {
738 lamport = graph.lamportOfSeq(seq);
739 lamports.set(seq, lamport);
740 }
741 return lamport;
742 };
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.Compare743 for (const file of files) {
744 const lineTexts = graph.packedTexts(file);
745 for (const [n, parent, seq, k, replaces] of graph.packedLines(file)) {
746 const text = lineTexts.next().value as string | null;
747 if (!this.#has(seq)) continue;
748 const moved = relocs?.get(n);
749 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.Compare750 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.Compare751 if (moved) {
752 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.Compare753 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.Compare754 at = moved.parent;
755 }
756 const list = children.get(at);
757 if (list) list.push(child);
758 else children.set(at, [child]);
759 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.Compare760 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.Compare761 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.Compare762 }
763 for (const [n, deleter] of graph.packedDeletes(file)) {
764 if (!this.#has(deleter)) continue;
765 const by = deleters.get(n);
766 if (by) by.push(deleter);
767 else deleters.set(n, [deleter]);
768 }
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.Compare769 // Runs written elsewhere under this file's lines follow them; the loop reads their files too.
770 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.Compare771 }
772 const order = (a: Child, b: Child) =>
773 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.Compare774 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.Compare775 const seq: number[] = [];
776 const vis: number[] = [];
777 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.Compare778 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.Compare779 const visK: number[] = [];
780 const seqWriter: number[] = [];
781 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.Compare782 const deletedBy = new Map<number, readonly number[]>();
783 const stack: number[] = [];
784 const push = (code: number) => {
785 const list = children.get(code);
786 if (!list) return;
787 if (list.length > 1) list.sort(order);
788 for (let i = list.length - 1; i >= 0; i--) stack.push(list[i]!.n);
789 };
790 push(start);
791 while (stack.length) {
792 const n = stack.pop()!;
793 const by = deleters.get(n);
794 if (by) {
795 if (complete) deletedBy.set(seq.length, by.length > 1 ? by.sort(priority) : by);
796 } else {
797 vis.push(n);
798 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.Compare799 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.Compare800 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.Compare801 }
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.Compare802 if (complete) {
803 seq.push(n);
804 seqWriter.push(writers.get(n)!);
805 seqK.push(places.get(n)!);
806 }
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.Compare807 push(n);
808 }
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.Compare809 return {
810 attrs,
811 complete,
812 seq: Int32Array.from(seq),
813 vis: Int32Array.from(vis),
814 deletedBy,
815 visText,
816 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.Compare817 visK: Int32Array.from(visK),
818 ...(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.Compare819 };
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.Compare820 }
codex-capacity-chair140Avoid line projection for file attribute queriesCompare822 #attributes(path: string): FileAttrs {
codex-capacity-chair132Bound persistent relocation projection memory with rollback-only scratchCompare823 const graph = this.graph;
init0Start the project824 // For each attribute, the highest-priority setter in the set wins.
825 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.Compare826 const file = graph.packedFiles ? graph.pathIndexOf(path) : undefined;
827 if (graph.packedFiles) {
828 for (const [seq, name, value] of file === undefined ? [] : graph.packedAttrs(file)) {
829 if (!this.#has(seq)) continue;
830 const id = graph.idOfSeq(seq);
831 const best = setters.get(name);
832 if (!best || graph.comparePriority(best.id, id) < 0) setters.set(name, { id, value });
833 }
834 return {
835 exists: setters.get("exists")?.value === "1",
836 exec: setters.get("exec")?.value === "1",
837 link: setters.get("link")?.value ?? null,
838 blob: setters.get("blob")?.value ?? null,
839 };
840 }
codex-capacity-chair119Page per-file atom indexes and stream current-view attribute scansCompare841 for (const id of graph.eachAtomIn(path)) {
init0Start the project842 if (!this.#has(graph.atom(id).seq)) continue;
843 for (const a of graph.atom(id).attrs ?? []) {
844 if (a.file !== path) continue;
845 const best = setters.get(a.name);
846 if (!best || graph.comparePriority(best.id, id) < 0) setters.set(a.name, { id, value: a.value });
847 }
848 }
codex-capacity-chair140Avoid line projection for file attribute queriesCompare849
850 return {
init0Start the project851 exists: setters.get("exists")?.value === "1",
852 exec: setters.get("exec")?.value === "1",
853 link: setters.get("link")?.value ?? null,
854 blob: setters.get("blob")?.value ?? null,
855 };
codex-capacity-chair140Avoid line projection for file attribute queriesCompare856 }
init0Start the project857
codex-capacity-chair132Bound persistent relocation projection memory with rollback-only scratchCompare858 #layoutResolved(path: string, complete: boolean, nodes?: Iterable<number>): FileState {
codex-capacity-chair140Avoid line projection for file attribute queriesCompare859 const graph = this.graph;
860 const attrs = this.#attributes(path);
init0Start the project861 const seq: number[] = [];
862 const vis: number[] = [];
863 const deletedBy = new Map<number, readonly number[]>();
codex-capacity-chair131Bound persisted no-move layout with ordered successor traversalCompare864
init0Start the project865 const start = graph.startCodeOf(path);
866 const priority = (a: number, b: number) => graph.lamportOfSeq(a) - graph.lamportOfSeq(b) || a - b;
codex-capacity-chair132Bound persistent relocation projection memory with rollback-only scratchCompare867 for (const n of nodes ?? (start === undefined ? [] : this.#layoutNodes(start))) {
codex-capacity-chair128Page deletion history and short-circuit current visibilityCompare868 let deleted = false;
869 const by: number[] = [];
870 for (const deleter of graph.eachDeleterSeqOf(n)) {
871 if (!this.#has(deleter)) continue;
872 deleted = true;
873 if (!complete) break;
874 by.push(deleter);
875 }
876 if (deleted) {
877 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 stateCompare878 } else vis.push(n);
879 if (complete) seq.push(n);
init0Start the project880 }
codex-capacity-chair140Avoid line projection for file attribute queriesCompare881
codex-capacity-chair110Keep current-file views and key scans from retaining historical stateCompare882 return { attrs, complete, seq: Int32Array.from(seq), vis: Int32Array.from(vis), deletedBy };
init0Start the project883 }
885 get #known(): string[] {
886 if (!this.#knownList) {
887 const known = new Set<string>();
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare888 if (this.#stable) {
889 for (const id of this.#stable) for (const file of this.graph.filesOf(id)) known.add(file);
890 } else {
891 for (let seq = 0; seq < this.#in.length; seq++)
892 if (this.#in[seq] === 1) for (const file of this.graph.filesOf(this.graph.idOfSeq(seq))) known.add(file);
893 }
init0Start the project894 this.#knownList = [...known].sort();
895 }
896 return this.#knownList;
897 }
899 /** Files with at least one visible line, sorted. */
900 paths(): string[] {
codex-capacity-chair118Avoid retaining deleted historical paths in indexed current viewsCompare901 if (this.#stable) {
902 const paths: string[] = [];
903 for (const path of this.graph.knownFiles()) {
904 if (this.hasFile(path)) paths.push(path);
905 else this.#files.delete(path);
906 }
907 return paths.sort();
908 }
init0Start the project909 return this.#known.filter((p) => this.hasFile(p));
910 }
912 /** Every file the set has ever written a line in, including fully deleted ones. */
913 knownPaths(): string[] {
914 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.Compare915 }
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 changesCompare917 /** The file line n sits in, in this set: fileOf by the line's number, with no lookup of its id. */
918 fileOfNumber(n: number): string {
919 return this.#fileOfN(n);
920 }
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.Compare922 /** How many visible lines a file has. */
923 visibleCount(path: string): number {
924 return this.#file(path).vis.length;
init0Start the project925 }
927 /** Whether the file exists in this projection (has a visible line). */
928 hasFile(path: string): boolean {
capacity245Collisions step 1: whether a file exists, without laying it out (abso Capacity, issue 664). A published version's view on a writer answers hasFile from the kept path list (PathIndex.keptPathSet, the set pathsAt already answers from), and a draft's view asks its base for every file the draft doesn't touch. Resolving an import tried up to seven file names in collisions, and each check laid the whole file out. On the abso export (collisions, my machine): the first call lays out 130 files instead of 407, 13.4 s instead of 15.2 s; a warm call 7.7 s instead of 8.3 s (step 2 is most of what's left). Same answer as replay. Heap after a full warm run: 76.9 MB against 76.5 MB on 244. test/known-paths.test.ts: every name at versions 0 to 2 and in four drafts, against the in-memory project, before and after every file is read: a version that deletes a file and renames one with record, one that moves lines into a new file, and drafts that delete, rename, move lines and add.Compare929 if (!this.#files.has(path)) {
930 // A file the draft doesn't touch exists as it does in the base; a published version's files are kept.
931 const shared = this.#filesFrom === undefined ? null : this.#sharedFiles();
932 if (shared && !shared.except.has(path)) return shared.from.hasFile(path);
933 if (this.#pathsFrom !== undefined) {
934 if (this.#knownPaths === undefined) this.#knownPaths = this.#pathsFrom() ?? null;
935 if (this.#knownPaths) return this.#knownPaths.has(path);
936 }
937 }
codex-capacity-chair140Avoid line projection for file attribute queriesCompare938 const attrs = this.attrs(path);
939 return attrs.exists || attrs.link !== null || attrs.blob !== null || this.#file(path).vis.length > 0;
init0Start the project940 }
942 /** A file's attributes: kept while empty, executable, a link's target. */
943 attrs(path: string): FileAttrs {
codex-capacity-chair140Avoid line projection for file attribute queriesCompare944 return this.#files.get(path)?.attrs ?? this.#attributes(path);
init0Start the project945 }
947 /** The projected text of a file ("" if it has no visible lines). */
948 text(path: string): string {
949 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.Compare950 const { vis, visText } = this.#file(path);
init0Start the project951 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.Compare952 for (let i = 0; i < vis.length; i++) lines[i] = visText?.[i] ?? this.graph.textOf(vis[i]!);
init0Start the project953 const text = joinLines(lines);
954 this.#textCache = { path, text };
955 return text;
956 }
958 /** 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)Compare959 sameText(path: string, other: ReadView): boolean {
960 if (!(other instanceof View)) {
961 const a = this.lines(path),
962 b = other.lines(path);
963 return a.length === b.length && a.every((line, i) => line.text === b[i]!.text);
964 }
init0Start the project965 const a = this.#file(path).vis;
966 const b = other.#file(path).vis;
967 if (a.length !== b.length) return false;
968 for (let i = 0; i < a.length; i++)
969 if (a[i] !== b[i] && this.graph.textOf(a[i]!) !== this.graph.textOf(b[i]!)) return false;
970 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.Compare971 }
973 *lineChunks(path: string): IterableIterator<() => Iterable<string>> {
974 for (const n of this.#file(path).vis) yield () => this.graph.textChunks(n);
975 }
977 /** Visible lines without retaining their text in the view cache. */
978 *visibleLines(path: string): IterableIterator<VisibleLine> {
979 const graph = this.graph;
980 for (const n of this.#file(path).vis)
981 yield { id: graph.lineIdOf(n), text: graph.textOf(n), atom: graph.idOfSeq(graph.writerSeqOf(n)) };
982 }
984 /** Atom-building line handles; text is loaded only when requested. */
985 buildLines(path: string): readonly VisibleLine[] {
986 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.Compare987 // 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.Compare988 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.Compare989 const lines: VisibleLine[] = new Array(vis.length);
990 for (let i = 0; i < vis.length; i++) {
991 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.Compare992 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.Compare993 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.Compare994 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.Compare995 textChunks: () => graph.textChunks(n),
996 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.Compare997 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.Compare998 },
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.Compare999 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.Compare1000 };
1002 return lines;
init0Start the project1003 }
1005 /** Visible lines with their ids. */
1006 lines(path: string): readonly VisibleLine[] {
1007 if (this.#linesCache?.path === path) return this.#linesCache.lines;
1008 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.Compare1009 const { vis, visText, visWriter, visK } = this.#file(path);
init0Start the project1010 const lines: VisibleLine[] = new Array(vis.length);
1011 for (let i = 0; i < vis.length; i++) {
1012 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.Compare1013 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.Compare1014 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.Compare1015 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.Compare1016 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.Compare1017 };
init0Start the project1018 }
1019 this.#linesCache = { path, lines };
1020 return lines;
1023 /** The full linearized sequence of a file, tombstones included. */
1024 sequence(path: string): readonly SeqLine[] {
1025 if (this.#seqCache?.path === path) return this.#seqCache.seq;
1026 const graph = this.graph;
codex-capacity-chair110Keep current-file views and key scans from retaining historical stateCompare1027 const f = this.#file(path, true);
init0Start the project1028 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.Compare1029 // Ids and writers from the packed layout, and each text read only when asked (abso Capacity): callers walk a few
1030 // lines of a file's history, and reading every line's text was a row each on a stored graph.
1031 const { seqWriter, seqK } = f;
init0Start the project1032 for (let i = 0; i < f.seq.length; i++) {
1033 const n = f.seq[i]!;
1034 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.Compare1035 const writer = seqWriter ? seqWriter[i]! : graph.writerSeqOf(n);
1036 let text: string | undefined;
init0Start the project1037 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.Compare1038 id: seqWriter && seqK ? lineId(graph.idOfSeq(writer), seqK[i]!) : graph.lineIdOf(n),
1039 get text() {
1040 text ??= graph.textOf(n);
1041 return text;
1042 },
1043 atom: graph.idOfSeq(writer),
init0Start the project1044 deletedBy: by ? by.map((s) => graph.idOfSeq(s)) : NONE,
1045 visible: by === undefined,
1046 };
1048 this.#seqCache = { path, seq: out };
1049 return out;
codex-capacity-chair138Find reason-warning neighbors without materializing file historyCompare1052 /** Two visible neighbours without retaining the file's historical sequence. */
1053 visibleNeighbours(path: string, line: LineId): LineId[] {
1054 const graph = this.graph;
1055 const target = graph.lineN(line);
1056 const start = graph.startCodeOf(path);
1057 if (target < 0 || start === undefined) return [];
1058 const scan = (nodes: Iterable<number>): LineId[] => {
1059 let previous: LineId | undefined;
1060 let found = false;
1061 for (const n of nodes) {
1062 if (n === target) {
1063 found = true;
1064 continue;
1066 let deleted = false;
1067 for (const seq of graph.eachDeleterSeqOf(n))
1068 if (this.#has(seq)) {
1069 deleted = true;
1070 break;
1072 if (deleted) continue;
1073 const id = graph.lineIdOf(n);
1074 if (found) return previous === undefined ? [id] : [previous, id];
1075 previous = id;
1077 return found && previous !== undefined ? [previous] : [];
1078 };
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.Compare1079 if (this.#scratchMoves())
codex-capacity-chair138Find reason-warning neighbors without materializing file historyCompare1080 return graph.withProjectionScratch((scratch) =>
1081 scan(scratchLayoutNodes(graph, (id) => this.#has(graph.atom(id).seq), scratch, graph.nodeOf(start))),
1082 );
1083 return scan(this.#layoutNodes(start));
init0Start the project1086 /** Index of a line in `sequence(path)`, or -1. */
1087 sequenceIndex(path: string, line: LineId): number {
codex-capacity-chair110Keep current-file views and key scans from retaining historical stateCompare1088 const f = this.#file(path, true);
init0Start the project1089 if (!f.seqIndex) {
1090 f.seqIndex = new Map();
1091 for (let i = 0; i < f.seq.length; i++) f.seqIndex.set(f.seq[i]!, i);
1093 return f.seqIndex.get(this.graph.lineN(line)) ?? -1;
1096 /** Index of a line in `lines(path)` (0-based visible line number), or -1 if not visible. */
1097 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 changesCompare1098 return this.lineNumberOf(path, this.graph.lineN(line));
1101 /** lineNumber by the line's number, with no lookup of its id. */
1102 lineNumberOf(path: string, n: number): number {
init0Start the project1103 const f = this.#file(path);
1104 if (!f.visIndex) {
1105 f.visIndex = new Map();
1106 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 changesCompare1108 return f.visIndex.get(n) ?? -1;
1111 /** The seq of the atom that wrote each visible line, in order: lines() without ids or text. */
1112 visibleWriters(path: string): number[] {
1113 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.Compare1114 const { vis, visWriter } = this.#file(path);
1115 // The packed layout keeps them (abso Capacity): looking each up again read a page per few lines on a stored graph.
1116 if (visWriter) return Array.from(visWriter);
1117 return Array.from(vis, (n) => graph.writerSeqOf(n));
init0Start the project1118 }
1120 /** All projected text files, path -> text, in path order. Binary files are in `blobs()`. */
1121 files(): Record<string, string> {
1122 const out: Record<string, string> = {};
1123 for (const path of this.paths()) if (this.#file(path).attrs.blob === null) out[path] = this.text(path);
1124 return out;
1127 /** Binary files, path -> the SHA-256 of their bytes, in path order. */
1128 blobs(): Record<string, string> {
capacity233A view's blobs come from file attributes alone (disk-first 2; abso Capacity). EngineProject.shared() lists shared's binary files on every call, and the Worker reads shared().version before and after most operations. View.blobs went through paths(), which lays out every file in the set to see whether it exists. On abso's export with a fresh writer, that was about 15 s on the first call. A file with a blob attribute exists, so blobs now reads each candidate path's attributes (the packed attribute history) and lays nothing out. Same files, same order. On abso adopted fresh: the harness's first read (status, shared, paths) went from about 20 s to 3 s. New test blobs-stored: a file binary from the start, one that turns binary and back to text, and one deleted; a stored writer's blob list matches the in-memory project's at every version and in each agent's draft. Named tests: every engine test (288 of 288), blobs-stored, blobs, attributes, project-file, files-reads, draft-reads-stored, authors-stored, project, version-files (46 of 46); tsc and biome clean.Compare1129 // From attributes alone (abso Capacity): a file with a blob exists, so no file is laid out to find them. Going
1130 // through paths() laid out every file in the set, and shared() asks for blobs on every call.
init0Start the project1131 const out: Record<string, string> = {};
capacity233A view's blobs come from file attributes alone (disk-first 2; abso Capacity). EngineProject.shared() lists shared's binary files on every call, and the Worker reads shared().version before and after most operations. View.blobs went through paths(), which lays out every file in the set to see whether it exists. On abso's export with a fresh writer, that was about 15 s on the first call. A file with a blob attribute exists, so blobs now reads each candidate path's attributes (the packed attribute history) and lays nothing out. Same files, same order. On abso adopted fresh: the harness's first read (status, shared, paths) went from about 20 s to 3 s. New test blobs-stored: a file binary from the start, one that turns binary and back to text, and one deleted; a stored writer's blob list matches the in-memory project's at every version and in each agent's draft. Named tests: every engine test (288 of 288), blobs-stored, blobs, attributes, project-file, files-reads, draft-reads-stored, authors-stored, project, version-files (46 of 46); tsc and biome clean.Compare1132 const candidates = this.#stable ? [...this.graph.knownFiles()].sort() : this.#known;
1133 for (const path of candidates) {
1134 const blob = this.attrs(path).blob;
init0Start the project1135 if (blob !== null) out[path] = blob;
1137 return out;
1140 /**
codex-capacity-policy103Test deterministic replay and account view cache weightCompare1141 * About how many bytes of retained state this view costs (#46). This uses
1142 * approximate ownership costs for containers and wrappers, not V8 heap
1143 * measurements. Graph-owned strings and records count only as references.
1144 * This method only inspects already-created state: it does not lay out files,
1145 * populate lazy caches, enumerate the graph, or count temporary traversal
1146 * containers and shared empty singleton payloads as retained view state.
init0Start the project1147 */
capacity241The view cache counts a file layout two views share once (disk-first 2; abso Capacity). Testing found collisions on abso slower with 240 than with 234 (warm 7.3 to 12.3 s). Since 235 a draft's view takes its base view's layout of every file the draft doesn't touch, so many cached views hold the same layouts. The cache counted each view's layouts in full, so the 24 MB budget filled with copies. That evicted views the next call needed, and a kept writer laid abso's drafts out again on every collisions call. - ViewCache keeps the newest views that fit the budget, as evicting oldest first does, counting a layout already counted for a newer view once (View.weight(seen)). - A layout's own bytes are worked out once per layout (layoutBytes): the cache weighs every view on every lookup, which summed every line's text again. On abso adopted fresh, one kept writer, against 240 on the same database: collisions 17.5 s to 11.9 s cold, 11.3 s to 6.1 s on the next call (49,000 and 19,000 reads, from 71,000 and 41,000). Both match replay. Heap after the run is the same with and without (about 125 to 130 MB with the kept writer); that's not from this change, and I'm reporting it separately. Named tests: view-cache (the eviction tests as before), every engine test (290 of 290), every worker/project test (341 of 341); tsc and biome clean.Compare1148 weight(seen?: Set<object>): number {
codex-capacity-policy103Test deterministic replay and account view cache weightCompare1149 let n = this.#in.byteLength;
codex-capacity-chair116Bound repeated indexed view membership lookupsCompare1150 n += 2 * ARRAY_HEADER_BYTES + this.#membershipSeq.byteLength + this.#membershipValue.byteLength;
codex-capacity-chair123Stream mover history when opening persisted viewsCompare1151 if (this.#movers) n += ARRAY_HEADER_BYTES + REFERENCE_BYTES * this.#movers.length;
codex-capacity-policy103Test deterministic replay and account view cache weightCompare1152 n += MAP_HEADER_BYTES; // #files exists from construction.
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare1153 if (this.#stable) n += this.#stable.retainedBytes;
1154 else if (this.#set) n += OBJECT_BYTES + SET_ENTRY_BYTES * this.#set.size;
codex-capacity-policy103Test deterministic replay and account view cache weightCompare1155 if (this.#knownList) n += ARRAY_HEADER_BYTES + REFERENCE_BYTES * this.#knownList.length;
1156 if (this.#relocs) n += MAP_HEADER_BYTES + MAP_ENTRY_BYTES * this.#relocs.size;
1157 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.Compare1158 n += MAP_ENTRY_BYTES * this.#picked.size;
codex-capacity-policy103Test deterministic replay and account view cache weightCompare1159 for (const f of this.#files.values()) {
1160 n += MAP_ENTRY_BYTES;
1161 if (f !== NO_FILE) {
capacity241The view cache counts a file layout two views share once (disk-first 2; abso Capacity). Testing found collisions on abso slower with 240 than with 234 (warm 7.3 to 12.3 s). Since 235 a draft's view takes its base view's layout of every file the draft doesn't touch, so many cached views hold the same layouts. The cache counted each view's layouts in full, so the 24 MB budget filled with copies. That evicted views the next call needed, and a kept writer laid abso's drafts out again on every collisions call. - ViewCache keeps the newest views that fit the budget, as evicting oldest first does, counting a layout already counted for a newer view once (View.weight(seen)). - A layout's own bytes are worked out once per layout (layoutBytes): the cache weighs every view on every lookup, which summed every line's text again. On abso adopted fresh, one kept writer, against 240 on the same database: collisions 17.5 s to 11.9 s cold, 11.3 s to 6.1 s on the next call (49,000 and 19,000 reads, from 71,000 and 41,000). Both match replay. Heap after the run is the same with and without (about 125 to 130 MB with the kept writer); that's not from this change, and I'm reporting it separately. Named tests: view-cache (the eviction tests as before), every engine test (290 of 290), every worker/project test (341 of 341); tsc and biome clean.Compare1162 // A layout another view counted already (`seen`, across a cache's views) isn't counted again.
1163 if (!seen?.has(f)) n += layoutBytes(f);
1164 seen?.add(f);
codex-capacity-policy103Test deterministic replay and account view cache weightCompare1165 if (f.seqIndex) n += MAP_HEADER_BYTES + MAP_ENTRY_BYTES * f.seqIndex.size;
1166 if (f.visIndex) n += MAP_HEADER_BYTES + MAP_ENTRY_BYTES * f.visIndex.size;
1169 if (this.#linesCache)
1170 n += OBJECT_BYTES + REFERENCE_BYTES + ARRAY_HEADER_BYTES + 100 * this.#linesCache.lines.length;
1171 if (this.#seqCache) {
1172 n += OBJECT_BYTES + REFERENCE_BYTES + ARRAY_HEADER_BYTES + 120 * this.#seqCache.seq.length;
1173 for (const line of this.#seqCache.seq)
1174 if (line.deletedBy !== NONE) n += ARRAY_HEADER_BYTES + REFERENCE_BYTES * line.deletedBy.length;
1176 if (this.#textCache) n += OBJECT_BYTES + REFERENCE_BYTES + ARRAY_HEADER_BYTES + 2 * this.#textCache.text.length;
init0Start the project1177 return n;
codex-capacity-chair110Keep current-file views and key scans from retaining historical stateCompare1180 #file(path: string, complete = false): FileState {
init0Start the project1181 let state = this.#files.get(path);
codex-capacity-chair110Keep current-file views and key scans from retaining historical stateCompare1182 if (!state || (complete && !state.complete)) {
capacity235A draft's view takes its base view's layout of every file the draft doesn't touch (disk-first 2; abso Capacity). An agent's tree, files and folder blame lay out every file in the agent's view, and tree also lays out the base to see which files the draft changed. Each layout read the file's packed history again, though every file the draft doesn't touch lays out exactly as in the draft's base. - View.shareFiles(from, except): a view lays out a file by taking from's layout of it, unless the file is in except. except is worked out once, when a file is first needed. - Project.#agentView sets it for a draft's view over its base's when the draft moves nothing (its moves are then the base's, as shareMoves already relies on). The touched files are touchedFiles over the draft's atoms, in both views: the files they write, delete in, set attributes on, and, where moves count, the files their deleted lines and their runs' parents sit in. On abso adopted fresh, one kept writer: an agent's tree with authors 23.4 s to 12 to 14 s. It's still slow because a whole abso layout is bigger than the views' byte budget, so it isn't kept between calls. New test agent-views-shared: after a published move of a function into another file, drafts that edit a moved line, delete one, change another file, set an attribute, or move lines themselves each read every file (text, attributes, writers) as the in-memory project does, read twice; it fails when the touched files are taken from where lines were written only. Named tests: every engine test (288 of 288), every worker/project test (338 of 338); typescript-rs, all 27 answers match replay; tsc and biome clean.Compare1183 const shared = this.#filesFrom === undefined ? null : this.#sharedFiles();
1184 if (shared && !shared.except.has(path)) state = shared.from.#file(path, complete);
1185 else state = this.graph.hasAtomsIn(path) ? this.#layout(path, complete) : NO_FILE;
init0Start the project1186 this.#files.set(path, state);
1188 return state;
1192/** The files of a closed set, path -> text. */
1193export function project(graph: Graph, set: Iterable<AtomId>): Record<string, string> {
1194 return new View(graph, set).files();
1197/** 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)Compare1198export function indexAfter(view: Pick<ReadView, "sequenceIndex">, path: string, node: NodeId): number {
init0Start the project1199 if (isStartNode(node)) return 0;
1200 const i = view.sequenceIndex(path, node);
1201 if (i < 0) throw new EngineError("not-in-view", `line ${node} is not in ${path} in this view`);
1202 return i + 1;