Who wrote what, read from the packed layout and each atom's author once (disk-first 2; abso Capacity). Version 230 of shared· capacity· Oct 15 (2026-10-15 09:11 UTC) · Not checked
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.
Version 229 · Files at version 230
4 files, 125 lines added, 13 removed.
--- a/src/engine/view.ts
+++ b/src/engine/view.ts
@@ -69,6 +69,8 @@
69 69 readonly deletedBy: ReadonlyMap<number, readonly number[]>; 70 70 /** Its visible lines' text, when laid out from the file's packed history: null for a line too long to pack. */ 71 71 readonly visText?: readonly (string | null)[]; 72 + /** Its visible lines' writers' seqs, when laid out from the file's packed history. */ 73 + readonly visWriter?: Int32Array; 72 74 /** Positions by n, built the first time they're asked for. */ 73 75 seqIndex?: Map<number, number>; 74 76 visIndex?: Map<number, number>; @@ -645,7 +647,18 @@
645 647 const files = new Set<number>([-1 - start, ...(this.#movedInFrom().get(path) ?? [])]); 646 648 const children = new Map<number, Child[]>(); 647 649 const texts = new Map<number, string | null>(); 650 + const writers = new Map<number, number>(); 648 651 const deleters = new Map<number, number[]>(); 652 + // Each atom's lamport once per layout: most lines share a few atoms, and a stored graph reads it from a page. 653 + const lamports = new Map<number, number>(); 654 + const lamportOf = (seq: number): number => { 655 + let lamport = lamports.get(seq); 656 + if (lamport === undefined) { 657 + lamport = graph.lamportOfSeq(seq); 658 + lamports.set(seq, lamport); 649 662 for (const file of files) { 650 663 const lineTexts = graph.packedTexts(file); 651 664 for (const [n, parent, seq, k, replaces] of graph.packedLines(file)) { @@ -653,16 +666,17 @@
653 666 if (!this.#has(seq)) continue; 654 667 const moved = relocs?.get(n); 656 − let child: Child = { n, replaces, lamport: graph.lamportOfSeq(seq), seq, k };
669 + let child: Child = { n, replaces, lamport: lamportOf(seq), seq, k }; 658 671 const mover = graph.atom(moved.r.atom).seq; 659 − child = { n, replaces: 0, lamport: graph.lamportOfSeq(mover), seq: mover, k: moved.r.k };
672 + child = { n, replaces: 0, lamport: lamportOf(mover), seq: mover, k: moved.r.k }; 660 673 at = moved.parent; 662 675 const list = children.get(at); 663 676 if (list) list.push(child); 664 677 else children.set(at, [child]); 665 678 texts.set(n, text); 679 + writers.set(n, seq); 667 681 for (const [n, deleter] of graph.packedDeletes(file)) { 668 682 if (!this.#has(deleter)) continue; @@ -675,10 +689,11 @@
676 690 const order = (a: Child, b: Child) => 677 691 b.replaces - a.replaces || b.lamport - a.lamport || b.seq - a.seq || a.k - b.k; 678 − const priority = (a: number, b: number) => graph.lamportOfSeq(a) - graph.lamportOfSeq(b) || a - b;
692 + const priority = (a: number, b: number) => lamportOf(a) - lamportOf(b) || a - b; 679 693 const seq: number[] = []; 680 694 const vis: number[] = []; 681 695 const visText: (string | null)[] = []; 696 + const visWriter: number[] = []; 682 697 const deletedBy = new Map<number, readonly number[]>(); 683 698 const stack: number[] = []; 684 699 const push = (code: number) => { @@ -696,11 +711,20 @@
698 713 visText.push(texts.get(n) ?? null); 714 + visWriter.push(writers.get(n)!); 700 716 if (complete) seq.push(n); 703 − return { attrs, complete, seq: Int32Array.from(seq), vis: Int32Array.from(vis), deletedBy, visText };
722 + seq: Int32Array.from(seq), 723 + vis: Int32Array.from(vis), 726 + visWriter: Int32Array.from(visWriter), 706 730 #attributes(path: string): FileAttrs { @@ -859,8 +883,8 @@
859 883 /** Atom-building line handles; text is loaded only when requested. */ 860 884 buildLines(path: string): readonly VisibleLine[] { 861 885 const graph = this.graph; 862 − // Texts the packed layout already holds are not read again (abso Capacity).
863 − const { vis, visText } = this.#file(path);
886 + // Texts and writers the packed layout already holds are not read again (abso Capacity). 887 + const { vis, visText, visWriter } = this.#file(path); 864 888 const lines: VisibleLine[] = new Array(vis.length); 865 889 for (let i = 0; i < vis.length; i++) { 866 890 const n = vis[i]!; @@ -871,7 +895,7 @@
872 896 return packed ?? graph.textOf(n); 874 − atom: graph.idOfSeq(graph.writerSeqOf(n)),
898 + atom: graph.idOfSeq(visWriter ? visWriter[i]! : graph.writerSeqOf(n)), @@ -881,14 +905,14 @@
881 905 lines(path: string): readonly VisibleLine[] { 882 906 if (this.#linesCache?.path === path) return this.#linesCache.lines; 883 907 const graph = this.graph; 884 − const { vis, visText } = this.#file(path);
908 + const { vis, visText, visWriter } = this.#file(path); 885 909 const lines: VisibleLine[] = new Array(vis.length); 886 910 for (let i = 0; i < vis.length; i++) { 887 911 const n = vis[i]!; 889 913 id: graph.lineIdOf(n), 890 914 text: visText?.[i] ?? graph.textOf(n), 891 − atom: graph.idOfSeq(graph.writerSeqOf(n)),
915 + atom: graph.idOfSeq(visWriter ? visWriter[i]! : graph.writerSeqOf(n)), 894 918 this.#linesCache = { path, lines }; @@ -1025,6 +1049,7 @@
1025 1049 n += OBJECT_BYTES + OBJECT_BYTES + 2 * ARRAY_HEADER_BYTES; 1026 1050 n += f.seq.byteLength + f.vis.byteLength; 1027 1051 if (f.visText) for (const text of f.visText) n += REFERENCE_BYTES + 2 * (text?.length ?? 0); 1052 + if (f.visWriter) n += 4 * f.visWriter.length; 1028 1053 n += MAP_HEADER_BYTES + (MAP_ENTRY_BYTES + ARRAY_HEADER_BYTES) * f.deletedBy.size; 1029 1054 for (const deleters of f.deletedBy.values()) n += REFERENCE_BYTES * deleters.length; 1030 1055 if (f.seqIndex) n += MAP_HEADER_BYTES + MAP_ENTRY_BYTES * f.seqIndex.size; --- a/worker/project/blame.ts
+++ b/worker/project/blame.ts
@@ -91,11 +91,21 @@
91 91 const first = Math.max(1, from ?? 1); 92 92 const last = Math.min(all.length, to ?? all.length); 93 93 const graph = project.graph; 94 + // Each atom's author once (abso Capacity): on a stored writer, graph.atom reads and parses the whole atom, and 95 + // most lines share a few big atoms. 96 + const authors = new Map<AtomId, string>(); 97 + const authorOf = (id: AtomId): string => { 98 + const known = authors.get(id); 99 + if (known !== undefined) return known; 100 + const author = graph.atom(id).author; 101 + authors.set(id, author); 94 104 const rows: BlameLine[] = all.slice(first - 1, last).map((l, i) => ({ 98 − author: graph.atom(l.atom).author,
108 + author: authorOf(l.atom), 99 109 version: project.versionOf(l.atom) ?? null, 100 110 ...(project.publishOf(l.atom) === undefined ? { unpublished: true as const } : {}), @@ -380,6 +390,16 @@
380 390 const key = pathKey(want.join("/")); 381 391 const graph = project.graph; 382 392 const counts = new Map<string, number>(); 393 + // Each atom's author once (abso Capacity): on a stored writer, graph.atom reads and parses the whole atom, and 394 + // most lines share a few big atoms. 395 + const authors = new Map<AtomId, string>(); 396 + const authorOf = (id: AtomId): string => { 397 + const known = authors.get(id); 398 + if (known !== undefined) return known; 399 + const author = graph.atom(id).author; 400 + authors.set(id, author); 385 405 let stored: string | undefined; @@ -390,7 +410,7 @@
390 410 stored ??= parts.slice(0, want.length).join("/"); 392 412 for (const l of view.lines(path)) { 393 − const author = graph.atom(l.atom).author;
413 + const author = authorOf(l.atom); 394 414 counts.set(author, (counts.get(author) ?? 0) + 1); --- a/worker/project/history.ts
+++ b/worker/project/history.ts
@@ -2,7 +2,7 @@
2 2 // (pathLife), and where lines went (follow). They read through HistoryHost, the one seam the derived tables 3 3 // (abso issues 48 and 79) plug into: today the host is the project in memory. 5 − import type { Graph, LineId, ReadView } from "../../src/engine/index.ts";
5 + import type { AtomId, Graph, LineId, ReadView } from "../../src/engine/index.ts"; 6 6 import { pathKey } from "./pathkey.ts"; 7 7 import { checkReadPath, differs, type LastChange, ProjectError, utf8Bytes } from "./project.ts"; 8 8 import { last, SHARED, type Space } from "./spaces.ts"; @@ -121,6 +121,16 @@
123 123 const paths = (agent ? undefined : h.keptPaths?.(space, version)) ?? view.paths(); 124 + // Each atom's author once (abso Capacity): on a stored writer, graph.atom reads and parses the whole atom, and 125 + // most lines share a few big atoms. 126 + const authors = new Map<AtomId, string>(); 127 + const authorOf = (id: AtomId): string => { 128 + const known = authors.get(id); 129 + if (known !== undefined) return known; 130 + const author = graph.atom(id).author; 131 + authors.set(id, author); 124 134 for (const path of paths) { 125 135 const e = entryOf(path); @@ -131,7 +141,7 @@
131 141 if (options.authors) { 132 142 const counts = (e.authors ??= new Map()); 133 143 for (const l of view.lines(path)) { 134 − const author = graph.atom(l.atom).author;
144 + const author = authorOf(l.atom); 135 145 counts.set(author, (counts.get(author) ?? 0) + 1); 137 147 const blob = view.attrs(path).blob; --- /dev/null
+++ b/worker/project/test/authors-stored.test.ts
@@ -0,0 +1,57 @@
1 + // Who wrote what, on a writer-backed project (abso Capacity): tree with authors, a folder's blame and a file's blame 2 + // take each line's writer from the packed layout and each atom's author once. They must answer as the in-memory 3 + // project does, at the head, at an older version and in an agent's draft. 5 + import assert from "node:assert/strict"; 6 + import { test } from "node:test"; 7 + import { storedArray } from "../../../src/engine/state-source.ts"; 8 + import { SqlState } from "../../../src/engine/test/storage-helper.ts"; 9 + import { blame, folderBlame } from "../blame.ts"; 10 + import { MemoryStore, Project } from "../project.ts"; 11 + import type { Entry, ProjectStore } from "../project-types.ts"; 14 + const storage = new SqlState(); 15 + const entries = storedArray<Entry>(storage, "canonical-log"); 16 + const store: ProjectStore = { 18 + for (const entry of batch) entries.push(entry); 21 + return new Project(store, { writerStorage: storage }); 24 + function history(project: Project) { 26 + project.init({ "src/a.ts": "one\ntwo\nthree\n", "src/b.ts": "b\n", "README.md": "readme\n" }, t); 27 + project.record("ann", { "src/a.ts": "one\nTWO\nthree\nfour\n" }, ++t); 28 + assert.equal(project.publish("ann", "Ann's lines", ++t).ok, true); 30 + project.record("bob", { "src/b.ts": "b\nbob's\n", "src/c.ts": "new\n" }, ++t); 31 + assert.equal(project.publish("bob", "Bob's lines", ++t).ok, true); 33 + project.record("cy", { "src/a.ts": "one\nTWO\nthree\nfour\nfive\n" }, ++t); 36 + test("tree with authors and blame read the same from disk as from memory", () => { 37 + const oracle = new Project(new MemoryStore()); 38 + const project = writer(); 41 + for (const options of [{ authors: true }, { authors: true, version: 1 }, { authors: true, agent: "cy" }]) 42 + assert.deepEqual(project.tree("", options), oracle.tree("", options), JSON.stringify(options)); 43 + assert.deepEqual(project.tree("src", { authors: true }), oracle.tree("src", { authors: true })); 44 + for (const [folder, version, where] of [ 47 + ["src", undefined, { agent: "cy" }], 49 + assert.deepEqual(folderBlame(project, folder, version, where), folderBlame(oracle, folder, version, where)); 50 + assert.deepEqual(blame(project, "src/a.ts"), blame(oracle, "src/a.ts")); 52 + blame(project, "src/a.ts", undefined, undefined, undefined, { agent: "cy" }), 53 + blame(oracle, "src/a.ts", undefined, undefined, undefined, { agent: "cy" }), 55 + const authors = oracle.tree("", { authors: true }).entries.find((e) => e.name === "src")?.authors ?? []; 56 + assert.ok(authors.length >= 2, "more than one author wrote src");