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

Versions 231 to 318

Compare

+325 −46 in 28 places
Lines 10–16 at 318 (were 10–16 at 231)
1010// made when a caller asks for them, and the latest asked for is kept.
1111
1212import type { Graph, RelocationInfo } from "./graph.ts";
13−import { isStartNode, seqOf } from "./keys.ts";
13+import { atomId, isStartNode, lineId, seqOf } from "./keys.ts";
1414import { resolveScratchMoves, scratchLayoutNodes } from "./relocation-scratch.ts";
1515import { isClosedSet, StableSet } from "./state-source.ts";
1616import { joinLines } from "./text.ts";
Lines 49–97 at 318 (were 49–60 at 231)
4949/** Structural read boundary shared by historical and transaction-bound projections. */
5050export type ReadView = Omit<
5151 Pick<View, keyof View>,
52− "sameText" | "visibleCount" | "shareMoves" | "fileOfNumber" | "lineNumberOf" | "visibleWriters"
52+ | "sameText"
53+ | "visibleCount"
54+ | "shareMoves"
55+ | "shareFiles"
56+ | "knowPaths"
57+ | "laidOut"
58+ | "forget"
59+ | "placedDifferently"
60+ | "fileOfNumber"
61+ | "lineNumberOf"
62+ | "visibleWriters"
5363> & {
5464 sameText(path: string, other: ReadView): boolean;
5565};
5666
57−const NO_ATTRS: FileAttrs = { exists: false, exec: false, link: null, blob: null };
67+const NO_ATTRS: FileAttrs = {
68+ exists: false,
69+ exec: false,
70+ link: null,
71+ blob: null,
72+};
74+/**
75+ * A file layout's bytes, less its lookup indexes, worked out once per layout (abso Capacity): a layout never changes
76+ * once made, and the view cache weighs every view it holds on every lookup, which summed every line's text again.
77+ */
78+const layoutSizes = new WeakMap<FileState, number>();
79+function layoutBytes(f: FileState): number {
80+ let n = layoutSizes.get(f);
81+ if (n !== undefined) return n;
82+ // FileState and FileAttrs are per laid-out file; typed-array headers are separate from their payload byte lengths.
83+ n = OBJECT_BYTES + OBJECT_BYTES + 2 * ARRAY_HEADER_BYTES;
84+ n += f.seq.byteLength + f.vis.byteLength;
85+ if (f.visText) for (const text of f.visText) n += REFERENCE_BYTES + (text === null ? 0 : stringBytes(text));
86+ if (f.visWriter) n += 4 * f.visWriter.length;
87+ if (f.visK) n += 4 * f.visK.length;
88+ if (f.seqWriter) n += 4 * f.seqWriter.length;
89+ if (f.seqK) n += 4 * f.seqK.length;
90+ n += MAP_HEADER_BYTES + (MAP_ENTRY_BYTES + ARRAY_HEADER_BYTES) * f.deletedBy.size;
91+ for (const deleters of f.deletedBy.values()) n += REFERENCE_BYTES * deleters.length;
92+ layoutSizes.set(f, n);
93+ return n;
94+}
5895const NONE: readonly never[] = Object.freeze([]);
5996
6097interface FileState {
Lines 108–118 at 318 (were 71–76 at 231)
71108 readonly visText?: readonly (string | null)[];
72109 /** Its visible lines' writers' seqs, when laid out from the file's packed history. */
73110 readonly visWriter?: Int32Array;
111+ /** Its visible lines' places in their writers (a line id's k), when laid out from packed history. */
112+ readonly visK?: Int32Array;
113+ /** The same for every line of seq, when complete and laid out from packed history. */
114+ readonly seqWriter?: Int32Array;
115+ readonly seqK?: Int32Array;
74116 /** Positions by n, built the first time they're asked for. */
75117 seqIndex?: Map<number, number>;
76118 visIndex?: Map<number, number>;
Lines 128–144 at 318 (were 86–93 at 231)
86128}
87129
88130const EMPTY_INTS = new Int32Array(0);
89−const NO_FILE: FileState = { attrs: NO_ATTRS, complete: true, seq: EMPTY_INTS, vis: EMPTY_INTS, deletedBy: new Map() };
131+const NO_FILE: FileState = {
132+ attrs: NO_ATTRS,
133+ complete: true,
134+ seq: EMPTY_INTS,
135+ vis: EMPTY_INTS,
136+ deletedBy: new Map(),
137+};
90138
139+/** A count of file uses shared by every view, so a cache can tell which layout across its views was used longest ago. */
140+let fileUses = 0;
91142// Approximate retained-container costs for View.weight(): reference slots,
92143// object headers, and map/set entries. These are cache-budget units, not V8
93144// heap measurements. Referenced Graph strings and records are not charged.
Lines 148–163 at 318 (were 97–103 at 231)
97148const MAP_ENTRY_BYTES = 40;
98149const SET_ENTRY_BYTES = 32;
99150const REFERENCE_BYTES = 8;
151+const STRING_HEADER_BYTES = 16;
100152/**
153+ * What V8 holds for a string of its own (abso Capacity, measured on abso's layouts): a header, then one byte a
154+ * character when every character fits in Latin-1 and two otherwise, rounded up to 8.
155+ */
156+export function stringBytes(text: string): number {
157+ const chars = /[^\u0000-\u00ff]/.test(text) ? 2 * text.length : text.length;
158+ return (STRING_HEADER_BYTES + chars + 7) & ~7;
159+}
160+/**
101161 * Moved lines a view resolves once and keeps (abso Capacity): a stored graph otherwise resolved every move again on
102162 * disk for each file it laid out. Game's whole history has 290; past this many, the view goes back to that.
103163 */
Lines 184–193 at 318 (were 124–130 at 231)
124184 readonly #graph: Graph;
125185 #seen = 0;
126186 /** Movers in seq order, with the numbers of the lines each moves, in its moves' order. */
127− readonly movers: { readonly seq: number; readonly lines: readonly number[] }[] = [];
187+ readonly movers: {
188+ readonly seq: number;
189+ readonly lines: readonly number[];
190+ }[] = [];
128191 /** Every relocation of each moved line, by the line's number, in seq order. */
129192 readonly byLine = new Map<number, MoveEntry[]>();
130193 readonly #climbed = new Map<number, number>();
Lines 196–209 at 318 (were 133–141 at 231)
133196 this.#graph = graph;
134197 }
135198
199+ /** The graph's accepted count when movers were last taken in: nothing to read while it's the same. */
200+ #stamp = -1;
136202 /** Take in movers the graph gained since. */
137203 update(): this {
138204 const graph = this.#graph;
205+ if (this.#stamp === graph.accepted) return this;
206+ this.#stamp = graph.accepted;
139207 const all = graph.movers();
140208 if (this.#seen === all.length) return this;
141209 for (; this.#seen < all.length; this.#seen++) {
Lines 211–222 at 318 (were 143–149 at 231)
143211 const lines: number[] = [];
144212 graph.atom(id).moves!.forEach((m, k) => {
145213 const n = graph.lineN(m.line);
146− const r: RelocationInfo = Object.freeze({ atom: id, line: m.line, parent: m.parent, k });
214+ const r: RelocationInfo = Object.freeze({
215+ atom: id,
216+ line: m.line,
217+ parent: m.parent,
218+ k,
219+ });
147220 const entry: MoveEntry = { n, r, parent: graph.codeOf(m.parent)! };
148221 const list = this.byLine.get(n);
149222 if (list) list.push(entry);
Lines 457–494 at 318 (were 384–389 at 231)
384457 this.#movesFrom = from;
385458 }
386459
460+ /**
461+ * Files laid out as another view lays them out (abso Capacity): a draft's view over its base's, for every file the
462+ * draft doesn't touch. The caller knows what the draft is; `except` is asked once, when a file is first needed, for
463+ * the files the draft touches, or undefined when nothing can be shared (a draft that moves lines). Without it, an
464+ * agent's tree, files and blame laid out every file of the project again for each agent.
465+ */
466+ shareFiles(from: View, except: () => ReadonlySet<string> | undefined): void {
467+ if (from.graph !== this.graph || from === this || this.#filesFrom !== undefined) return;
468+ this.#filesFrom = { from, except };
469+ }
470+ #filesFrom: { from: View; except: () => ReadonlySet<string> | undefined } | null | undefined;
472+ /**
473+ * The files this view's set has, from what the project keeps for a published version (abso Capacity): hasFile
474+ * answers from it, not a layout of the file. Collisions resolving an import tried up to seven names, and each one
475+ * laid its file out. `paths` is asked once, when first needed; undefined lays files out as before.
476+ */
477+ knowPaths(paths: () => ReadonlySet<string> | undefined): void {
478+ if (this.#pathsFrom === undefined) this.#pathsFrom = paths;
479+ }
480+ #pathsFrom: (() => ReadonlySet<string> | undefined) | undefined;
481+ #knownPaths: ReadonlySet<string> | null | undefined;
482+ #filesShared: { from: View; except: ReadonlySet<string> } | null | undefined;
483+ #sharedFiles(): { from: View; except: ReadonlySet<string> } | null {
484+ if (this.#filesShared === undefined) {
485+ const share = this.#filesFrom;
486+ const except = share ? share.except() : undefined;
487+ this.#filesShared = share && except ? { from: share.from, except } : null;
488+ }
489+ return this.#filesShared;
490+ }
387492 #takeShared(): void {
388493 const from = this.#movesFrom;
389494 if (!from) return;
Lines 544–553 at 318 (were 439–445 at 231)
439544 if (this.#relocsN) return this.#relocsN;
440545 const out = new Map<number, { readonly r: RelocationInfo; readonly parent: number }>();
441546 for (const [line, r] of this.#relocations())
442− out.set(this.graph.lineN(line), { r, parent: this.graph.codeOf(r.parent)! });
547+ out.set(this.graph.lineN(line), {
548+ r,
549+ parent: this.graph.codeOf(r.parent)!,
550+ });
443551 this.#relocsN = out;
444552 return out;
445553 }
Lines 566–594 at 318 (were 458–463 at 231)
458566 return parent;
459567 }
460568
569+ /**
570+ * The files where a moved line sits, in this view or in `other`, when the two place it differently: a different
571+ * relocation wins, or a different parent (abso Capacity). Besides the files a draft's atoms name, these are the only
572+ * ones a draft's moves can lay out differently from its base, since a line's descendants follow it. Undefined when
573+ * either view resolves its moves in scratch, which keeps no map of them to compare.
574+ */
575+ placedDifferently(other: View): Set<string> | undefined {
576+ if (this.#scratchMoves() || other.#scratchMoves()) return undefined;
577+ const here = this.#hasMoves ? this.#relocationsN() : undefined;
578+ const there = other.#hasMoves ? other.#relocationsN() : undefined;
579+ const files = new Set<string>();
580+ const add = (n: number) => {
581+ files.add(this.#fileOfN(n));
582+ files.add(other.#fileOfN(n));
583+ };
584+ for (const [n, x] of here ?? []) {
585+ const y = there?.get(n);
586+ if (!y || y.parent !== x.parent || y.r.atom !== x.r.atom) add(n);
587+ }
588+ for (const n of there?.keys() ?? []) if (!here?.has(n)) add(n);
589+ return files;
590+ }
461592 /** Whether any atom in the set moves lines. */
462593 hasMoves(): boolean {
463594 return this.#hasMoves;
Lines 649–661 at 318 (were 518–524 at 231)
518649 for (const n of graph.eachChildN(code)) {
519650 const seq = graph.writerSeqOf(n);
520651 if (!this.#has(seq) || relocs?.has(n)) continue;
521− out.push({ n, replaces: graph.replacesN(n) ? 1 : 0, lamport: graph.lamportOfSeq(seq), seq, k: graph.kOf(n) });
652+ out.push({
653+ n,
654+ replaces: graph.replacesN(n) ? 1 : 0,
655+ lamport: graph.lamportOfSeq(seq),
656+ seq,
657+ k: graph.kOf(n),
658+ });
522659 }
523660 if (relocs) {
524661 // The lines this set's moves put under each node, from the moves it already resolved: no row read per node
Lines 671–683 at 318 (were 534–540 at 231)
534671 for (const n of this.#movedInto.get(code) ?? NO_LINES) {
535672 const r = relocs.get(n)!.r;
536673 const seq = graph.atom(r.atom).seq;
537− out.push({ n, replaces: 0, lamport: graph.lamportOfSeq(seq), seq, k: r.k });
674+ out.push({
675+ n,
676+ replaces: 0,
677+ lamport: graph.lamportOfSeq(seq),
678+ seq,
679+ k: r.k,
680+ });
538681 }
539682 }
540683 // A line's replacements (runs of atoms that deleted it) first, then the
Lines 785–808 at 318 (were 642–653 at 231)
642785 const graph = this.graph;
643786 const attrs = this.#attributes(path);
644787 const start = graph.startCodeOf(path);
645− if (start === undefined) return { attrs, complete, seq: EMPTY_INTS, vis: EMPTY_INTS, deletedBy: new Map() };
788+ if (start === undefined)
789+ return {
790+ attrs,
791+ complete,
792+ seq: EMPTY_INTS,
793+ vis: EMPTY_INTS,
794+ deletedBy: new Map(),
795+ };
646796 const relocs = this.#hasMoves ? this.#relocationsN() : undefined;
647797 const files = new Set<number>([-1 - start, ...(this.#movedInFrom().get(path) ?? [])]);
648798 const children = new Map<number, Child[]>();
649− const texts = new Map<number, string | null>();
799+ // Where each line's text is: its file and its place in that file's packed history. Texts are read after the walk,
800+ // only for the lines it shows (abso Capacity): every text a file and its moved-in sources ever had was read for
801+ // every layout, and abso's worker files, split out of index.ts, read all of index.ts's history each.
802+ const textFile = new Map<number, number>();
803+ const textPlace = new Map<number, number>();
650804 const writers = new Map<number, number>();
805+ const places = new Map<number, number>();
651806 const deleters = new Map<number, number[]>();
652807 // Each atom's lamport once per layout: most lines share a few atoms, and a stored graph reads it from a page.
653808 const lamports = new Map<number, number>();
Lines 815–864 at 318 (were 660–691 at 231)
660815 return lamport;
661816 };
662817 for (const file of files) {
663− const lineTexts = graph.packedTexts(file);
664− for (const [n, parent, seq, k, replaces] of graph.packedLines(file)) {
665− const text = lineTexts.next().value as string | null;
818+ // The file's history decoded once and kept by the graph (abso Capacity): each view of it read every page again.
819+ const history = graph.packedHistory(file);
820+ const lines = history.lines;
821+ for (let i = 0, place = 0; i < lines.length; i += 5, place++) {
822+ const n = lines[i]!;
823+ const parent = lines[i + 1]!;
824+ const seq = lines[i + 2]!;
825+ const k = lines[i + 3]!;
826+ const replaces = lines[i + 4]!;
666827 if (!this.#has(seq)) continue;
667828 const moved = relocs?.get(n);
668829 let at = parent;
669830 let child: Child = { n, replaces, lamport: lamportOf(seq), seq, k };
670831 if (moved) {
671832 const mover = graph.atom(moved.r.atom).seq;
672− child = { n, replaces: 0, lamport: lamportOf(mover), seq: mover, k: moved.r.k };
833+ child = {
834+ n,
835+ replaces: 0,
836+ lamport: lamportOf(mover),
837+ seq: mover,
838+ k: moved.r.k,
839+ };
673840 at = moved.parent;
674841 }
675842 const list = children.get(at);
676843 if (list) list.push(child);
677844 else children.set(at, [child]);
678− texts.set(n, text);
845+ textFile.set(n, file);
846+ textPlace.set(n, place);
679847 writers.set(n, seq);
848+ places.set(n, k);
680849 }
681− for (const [n, deleter] of graph.packedDeletes(file)) {
850+ const dels = history.deletes;
851+ for (let at = 0; at < dels.length; at += 2) {
852+ const n = dels[at]!;
853+ const deleter = dels[at + 1]!;
682854 if (!this.#has(deleter)) continue;
683855 const by = deleters.get(n);
684856 if (by) by.push(deleter);
685857 else deleters.set(n, [deleter]);
686858 }
687859 // Runs written elsewhere under this file's lines follow them; the loop reads their files too.
688− for (const [parent, into] of graph.packedCrossings(file)) if (texts.has(parent)) files.add(into);
860+ const crossings = history.crossings;
861+ for (let at = 0; at < crossings.length; at += 2) if (writers.has(crossings[at]!)) files.add(crossings[at + 1]!);
689862 }
690863 const order = (a: Child, b: Child) =>
691864 b.replaces - a.replaces || b.lamport - a.lamport || b.seq - a.seq || a.k - b.k;
Lines 867–888 at 318 (were 694–700 at 231)
694867 const vis: number[] = [];
695868 const visText: (string | null)[] = [];
696869 const visWriter: number[] = [];
870+ const visK: number[] = [];
871+ const seqWriter: number[] = [];
872+ const seqK: number[] = [];
697873 const deletedBy = new Map<number, readonly number[]>();
874+ // The text pages read for this layout, by file and page: each at most once.
875+ const pages = new Map<number, Map<number, readonly (string | null)[]>>();
876+ const textOf = (n: number): string | null => {
877+ const file = textFile.get(n)!;
878+ const place = textPlace.get(n)!;
879+ const page = Math.floor(place / 256);
880+ let byPage = pages.get(file);
881+ if (!byPage) pages.set(file, (byPage = new Map()));
882+ let texts = byPage.get(page);
883+ if (!texts) byPage.set(page, (texts = graph.packedTextPage(file, page)));
884+ return texts[place % 256] ?? null;
885+ };
698886 const stack: number[] = [];
699887 const push = (code: number) => {
700888 const list = children.get(code);
Lines 898–912 at 318 (were 710–719 at 231)
710898 if (complete) deletedBy.set(seq.length, by.length > 1 ? by.sort(priority) : by);
711899 } else {
712900 vis.push(n);
713− visText.push(texts.get(n) ?? null);
901+ visText.push(textOf(n));
714902 visWriter.push(writers.get(n)!);
903+ visK.push(places.get(n)!);
715904 }
716− if (complete) seq.push(n);
905+ if (complete) {
906+ seq.push(n);
907+ seqWriter.push(writers.get(n)!);
908+ seqK.push(places.get(n)!);
909+ }
717910 push(n);
718911 }
719912 return {
Lines 917–924 at 318 (were 724–729 at 231)
724917 deletedBy,
725918 visText,
726919 visWriter: Int32Array.from(visWriter),
920+ visK: Int32Array.from(visK),
921+ ...(complete ? { seqWriter: Int32Array.from(seqWriter), seqK: Int32Array.from(seqK) } : {}),
727922 };
728923 }
729924
Lines 982–994 at 318 (were 787–793 at 231)
787982 if (complete) seq.push(n);
788983 }
789984
790− return { attrs, complete, seq: Int32Array.from(seq), vis: Int32Array.from(vis), deletedBy };
985+ return {
986+ attrs,
987+ complete,
988+ seq: Int32Array.from(seq),
989+ vis: Int32Array.from(vis),
990+ deletedBy,
991+ };
791992 }
792993
793994 get #known(): string[] {
Lines 1007–1032 at 318 (were 806–816 at 231)
8061007
8071008 /** Files with at least one visible line, sorted. */
8081009 paths(): string[] {
1010+ // Without walking every file the graph has ever had (abso Capacity): a draft's view over its base's has the base's
1011+ // files, with the ones its draft touches checked here; a published version's are kept (knowPaths).
1012+ const shared = this.#filesFrom === undefined ? null : this.#sharedFiles();
1013+ if (shared) {
1014+ const out = shared.from.paths().filter((p) => !shared.except.has(p));
1015+ for (const p of shared.except) if (this.hasFile(p)) out.push(p);
1016+ return out.sort();
1017+ }
1018+ if (this.#pathsFrom !== undefined) {
1019+ if (this.#knownPaths === undefined) this.#knownPaths = this.#pathsFrom() ?? null;
1020+ if (this.#knownPaths) return [...this.#knownPaths].sort();
1021+ }
8091022 if (this.#stable) {
8101023 const paths: string[] = [];
8111024 for (const path of this.graph.knownFiles()) {
8121025 if (this.hasFile(path)) paths.push(path);
813− else this.#files.delete(path);
1026+ else {
1027+ this.#files.delete(path);
1028+ this.#used.delete(path);
1029+ }
8141030 }
8151031 return paths.sort();
8161032 }
Lines 1050–1064 at 318 (were 834–839 at 231)
8341050
8351051 /** Whether the file exists in this projection (has a visible line). */
8361052 hasFile(path: string): boolean {
1053+ if (!this.#files.has(path)) {
1054+ // A file the draft doesn't touch exists as it does in the base; a published version's files are kept.
1055+ const shared = this.#filesFrom === undefined ? null : this.#sharedFiles();
1056+ if (shared && !shared.except.has(path)) return shared.from.hasFile(path);
1057+ if (this.#pathsFrom !== undefined) {
1058+ if (this.#knownPaths === undefined) this.#knownPaths = this.#pathsFrom() ?? null;
1059+ if (this.#knownPaths) return this.#knownPaths.has(path);
1060+ }
1061+ }
8371062 const attrs = this.attrs(path);
8381063 return attrs.exists || attrs.link !== null || attrs.blob !== null || this.#file(path).vis.length > 0;
8391064 }
Lines 1095–1137 at 318 (were 870–901 at 231)
8701095 }
8711096
8721097 *lineChunks(path: string): IterableIterator<() => Iterable<string>> {
873− for (const n of this.#file(path).vis) yield () => this.graph.textChunks(n);
1098+ // The texts the packed layout already holds, read a page at a time (abso Capacity, 714): a record's diff read each
1099+ // line's own row, 11,873 statements for abso's index.ts. Only a line too long to pack is read in chunks.
1100+ const { vis, visText } = this.#file(path);
1101+ for (let i = 0; i < vis.length; i++) {
1102+ const packed = visText?.[i];
1103+ if (packed != null) yield () => [packed];
1104+ else yield () => this.graph.textChunks(vis[i]!);
1105+ }
8741106 }
8751107
8761108 /** Visible lines without retaining their text in the view cache. */
8771109 *visibleLines(path: string): IterableIterator<VisibleLine> {
8781110 const graph = this.graph;
8791111 for (const n of this.#file(path).vis)
880− yield { id: graph.lineIdOf(n), text: graph.textOf(n), atom: graph.idOfSeq(graph.writerSeqOf(n)) };
1112+ yield {
1113+ id: graph.lineIdOf(n),
1114+ text: graph.textOf(n),
1115+ atom: atomId(graph.writerSeqOf(n)),
1116+ };
8811117 }
8821118
8831119 /** Atom-building line handles; text is loaded only when requested. */
8841120 buildLines(path: string): readonly VisibleLine[] {
8851121 const graph = this.graph;
8861122 // Texts and writers the packed layout already holds are not read again (abso Capacity).
887− const { vis, visText, visWriter } = this.#file(path);
1123+ const { vis, visText, visWriter, visK } = this.#file(path);
8881124 const lines: VisibleLine[] = new Array(vis.length);
8891125 for (let i = 0; i < vis.length; i++) {
8901126 const n = vis[i]!;
8911127 const packed = visText?.[i];
8921128 lines[i] = {
893− id: graph.lineIdOf(n),
1129+ id: visWriter && visK ? lineId(atomId(visWriter[i]!), visK[i]!) : graph.lineIdOf(n),
8941130 textChunks: () => graph.textChunks(n),
8951131 get text() {
8961132 return packed ?? graph.textOf(n);
8971133 },
898− atom: graph.idOfSeq(visWriter ? visWriter[i]! : graph.writerSeqOf(n)),
1134+ atom: atomId(visWriter ? visWriter[i]! : graph.writerSeqOf(n)),
8991135 };
9001136 }
9011137 return lines;
Lines 1141–1156 at 318 (were 905–918 at 231)
9051141 lines(path: string): readonly VisibleLine[] {
9061142 if (this.#linesCache?.path === path) return this.#linesCache.lines;
9071143 const graph = this.graph;
908− const { vis, visText, visWriter } = this.#file(path);
1144+ const { vis, visText, visWriter, visK } = this.#file(path);
9091145 const lines: VisibleLine[] = new Array(vis.length);
1146+ // Writer seqs come from the graph's own layout, so they're named with atomId, not checked by idOfSeq (abso 738):
1147+ // on a stored graph its check read the atom count once a line, about 0.9 s of a warm draft-state on abso.
9101148 for (let i = 0; i < vis.length; i++) {
9111149 const n = vis[i]!;
9121150 lines[i] = {
913− id: graph.lineIdOf(n),
1151+ id: visWriter && visK ? lineId(atomId(visWriter[i]!), visK[i]!) : graph.lineIdOf(n),
9141152 text: visText?.[i] ?? graph.textOf(n),
915− atom: graph.idOfSeq(visWriter ? visWriter[i]! : graph.writerSeqOf(n)),
1153+ atom: atomId(visWriter ? visWriter[i]! : graph.writerSeqOf(n)),
9161154 };
9171155 }
9181156 this.#linesCache = { path, lines };
Lines 1163–1184 at 318 (were 925–938 at 231)
9251163 const graph = this.graph;
9261164 const f = this.#file(path, true);
9271165 const out: SeqLine[] = new Array(f.seq.length);
1166+ // Ids and writers from the packed layout, and each text read only when asked (abso Capacity): callers walk a few
1167+ // lines of a file's history, and reading every line's text was a row each on a stored graph.
1168+ const { seqWriter, seqK } = f;
9281169 for (let i = 0; i < f.seq.length; i++) {
9291170 const n = f.seq[i]!;
9301171 const by = f.deletedBy.get(i);
1172+ const writer = seqWriter ? seqWriter[i]! : graph.writerSeqOf(n);
1173+ let text: string | undefined;
9311174 out[i] = {
932− id: graph.lineIdOf(n),
933− text: graph.textOf(n),
934− atom: graph.idOfSeq(graph.writerSeqOf(n)),
935− deletedBy: by ? by.map((s) => graph.idOfSeq(s)) : NONE,
1175+ id: seqWriter && seqK ? lineId(atomId(writer), seqK[i]!) : graph.lineIdOf(n),
1176+ get text() {
1177+ text ??= graph.textOf(n);
1178+ return text;
1179+ },
1180+ atom: atomId(writer),
1181+ deletedBy: by ? by.map((s) => atomId(s)) : NONE,
9361182 visible: by === undefined,
9371183 };
9381184 }
Lines 1263–1274 at 318 (were 1017–1025 at 231)
10171263
10181264 /** Binary files, path -> the SHA-256 of their bytes, in path order. */
10191265 blobs(): Record<string, string> {
1266+ // From attributes alone (abso Capacity): a file with a blob exists, so no file is laid out to find them. Going
1267+ // through paths() laid out every file in the set, and shared() asks for blobs on every call.
10201268 const out: Record<string, string> = {};
1021− for (const path of this.paths()) {
1022− const blob = this.#file(path).attrs.blob;
1269+ const candidates = this.#stable ? [...this.graph.knownFiles()].sort() : this.#known;
1270+ for (const path of candidates) {
1271+ const blob = this.attrs(path).blob;
10231272 if (blob !== null) out[path] = blob;
10241273 }
10251274 return out;
Lines 1282–1288 at 318 (were 1033–1039 at 231)
10331282 * populate lazy caches, enumerate the graph, or count temporary traversal
10341283 * containers and shared empty singleton payloads as retained view state.
10351284 */
1036− weight(): number {
1285+ weight(seen?: Set<object>): number {
10371286 let n = this.#in.byteLength;
10381287 n += 2 * ARRAY_HEADER_BYTES + this.#membershipSeq.byteLength + this.#membershipValue.byteLength;
10391288 if (this.#movers) n += ARRAY_HEADER_BYTES + REFERENCE_BYTES * this.#movers.length;
Lines 1293–1305 at 318 (were 1044–1060 at 231)
10441293 if (this.#relocs) n += MAP_HEADER_BYTES + MAP_ENTRY_BYTES * this.#relocs.size;
10451294 if (this.#relocsN) n += MAP_HEADER_BYTES + (MAP_ENTRY_BYTES + OBJECT_BYTES) * this.#relocsN.size;
10461295 n += MAP_ENTRY_BYTES * this.#picked.size;
1296+ n += MAP_ENTRY_BYTES * this.#used.size;
10471297 for (const f of this.#files.values()) {
10481298 n += MAP_ENTRY_BYTES;
10491299 if (f !== NO_FILE) {
1050− // FileState and FileAttrs are per laid-out file; typed-array
1051− // headers are separate from their payload byte lengths below.
1052− n += OBJECT_BYTES + OBJECT_BYTES + 2 * ARRAY_HEADER_BYTES;
1053− n += f.seq.byteLength + f.vis.byteLength;
1054− if (f.visText) for (const text of f.visText) n += REFERENCE_BYTES + 2 * (text?.length ?? 0);
1055− if (f.visWriter) n += 4 * f.visWriter.length;
1056− n += MAP_HEADER_BYTES + (MAP_ENTRY_BYTES + ARRAY_HEADER_BYTES) * f.deletedBy.size;
1057− for (const deleters of f.deletedBy.values()) n += REFERENCE_BYTES * deleters.length;
1300+ // A layout another view counted already (`seen`, across a cache's views) isn't counted again.
1301+ if (!seen?.has(f)) n += layoutBytes(f);
1302+ seen?.add(f);
10581303 if (f.seqIndex) n += MAP_HEADER_BYTES + MAP_ENTRY_BYTES * f.seqIndex.size;
10591304 if (f.visIndex) n += MAP_HEADER_BYTES + MAP_ENTRY_BYTES * f.visIndex.size;
10601305 }
Lines 1318–1362 at 318 (were 1073–1083 at 231)
10731318 #file(path: string, complete = false): FileState {
10741319 let state = this.#files.get(path);
10751320 if (!state || (complete && !state.complete)) {
1076− state = this.graph.hasAtomsIn(path) ? this.#layout(path, complete) : NO_FILE;
1321+ const shared = this.#filesFrom === undefined ? null : this.#sharedFiles();
1322+ if (shared && !shared.except.has(path)) state = shared.from.#file(path, complete);
1323+ else state = this.graph.hasAtomsIn(path) ? this.#layout(path, complete) : NO_FILE;
10771324 this.#files.set(path, state);
10781325 }
1326+ if (state !== NO_FILE) this.#used.set(path, ++fileUses);
10791327 return state;
10801328 }
1330+ /** When each laid-out file was last used (fileUses). */
1331+ readonly #used = new Map<string, number>();
1333+ /**
1334+ * Each laid-out file: its layout, when it was last used (a count shared by every view) and what it holds, for a
1335+ * cache that trims the least recently used layouts across its views before whole views (views.ts, abso Capacity).
1336+ */
1337+ *laidOut(): IterableIterator<{
1338+ path: string;
1339+ layout: object;
1340+ used: number;
1341+ bytes: number;
1342+ }> {
1343+ for (const [path, f] of this.#files) {
1344+ if (f === NO_FILE) continue;
1345+ let bytes = 2 * MAP_ENTRY_BYTES + layoutBytes(f);
1346+ if (f.seqIndex) bytes += MAP_HEADER_BYTES + MAP_ENTRY_BYTES * f.seqIndex.size;
1347+ if (f.visIndex) bytes += MAP_HEADER_BYTES + MAP_ENTRY_BYTES * f.visIndex.size;
1348+ yield { path, layout: f, used: this.#used.get(path) ?? 0, bytes };
1349+ }
1350+ }
1352+ /** Let go of a file's layout: the next ask lays it out again, the same. */
1353+ forget(path: string): void {
1354+ this.#files.delete(path);
1355+ this.#used.delete(path);
1356+ if (this.#linesCache?.path === path) this.#linesCache = undefined;
1357+ if (this.#seqCache?.path === path) this.#seqCache = undefined;
1358+ if (this.#textCache?.path === path) this.#textCache = undefined;
1359+ }
10811360}
10821361
10831362/** The files of a closed set, path -> text. */
MCP
compare on this site's /mcp
CLI
abso diff 231 318 src/engine/view.ts --json
JSON
/christopher/abso-core/compare/231..318?file=src%2Fengine%2Fview.ts&format=json