A kept reader settles after each read; line texts weigh what V8 holds (abso Capacity, issue 664). Version 247 of shared· capacity· Oct 15 (2026-10-15 16:20 UTC) · Not checked
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.
Version 246 · Files at version 247
6 files, 105 lines added, 1 removed.
--- a/src/engine/view.ts
+++ b/src/engine/view.ts
@@ -74,7 +74,7 @@
74 74 // FileState and FileAttrs are per laid-out file; typed-array headers are separate from their payload byte lengths. 75 75 n = OBJECT_BYTES + OBJECT_BYTES + 2 * ARRAY_HEADER_BYTES; 76 76 n += f.seq.byteLength + f.vis.byteLength; 77 − if (f.visText) for (const text of f.visText) n += REFERENCE_BYTES + 2 * (text?.length ?? 0);
77 + if (f.visText) for (const text of f.visText) n += REFERENCE_BYTES + (text === null ? 0 : stringBytes(text)); 78 78 if (f.visWriter) n += 4 * f.visWriter.length; 79 79 if (f.visK) n += 4 * f.visK.length; 80 80 if (f.seqWriter) n += 4 * f.seqWriter.length; @@ -131,7 +131,16 @@
131 131 const MAP_ENTRY_BYTES = 40; 132 132 const SET_ENTRY_BYTES = 32; 133 133 const REFERENCE_BYTES = 8; 134 + const STRING_HEADER_BYTES = 16; 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. 139 + function stringBytes(text: string): number { 140 + const chars = /[^\u0000-\u00ff]/.test(text) ? 2 * text.length : text.length; 141 + return (STRING_HEADER_BYTES + chars + 7) & ~7; 135 144 * Moved lines a view resolves once and keeps (abso Capacity): a stored graph otherwise resolved every move again on 136 145 * disk for each file it laid out. Game's whole history has 290; past this many, the view goes back to that. --- a/worker/project/project.ts
+++ b/worker/project/project.ts
@@ -2811,6 +2811,17 @@
2811 2811 return this.#viewAt(this.#shared, last(this.#shared)); 2815 + * After each read of a reader kept between calls, one that changed nothing (abso Capacity): the cached views back 2816 + * under their budget, since views grow while a call lays files out and the cache weighs them only when they are 2817 + * asked for again (on abso, a tree with authors left 38 MB of views held against the 24 MB budget), and the agents 2818 + * the read decoded let go, read again from storage by the next call (7 MB on abso, every agent's news told). 2820 + afterRead(): void { 2821 + this.#views.trim(); 2822 + if (this.#agents instanceof WriterAgents) this.#agents.release(); 2814 2825 /** A view of a set, cached by the set's exact contents (views.ts). */ 2815 2826 #view(set: ReadonlySet<AtomId>): ReadView { 2816 2827 this.#views.assertUnkeyedAllowed(); --- /dev/null
+++ b/worker/project/test/after-read.test.ts
@@ -0,0 +1,57 @@
1 + // A reader kept between calls settles after each read (abso Capacity, Project.afterRead): the cached views trimmed 2 + // to their budget and the agents it decoded let go. The next reads must answer as before, from storage, and a 3 + // write after it must still see every agent as stored. 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 { MemoryStore, Project } from "../project.ts"; 10 + import type { Entry, ProjectStore } from "../project-types.ts"; 13 + const storage = new SqlState(); 14 + const entries = storedArray<Entry>(storage, "canonical-log"); 15 + const store: ProjectStore = { 17 + for (const entry of batch) entries.push(entry); 20 + return new Project(store, { writerStorage: storage }); 23 + const SHAPES = "export function area(r: number) {\n return 3.14 * r * r;\n}\n"; 24 + const IMPORT = 'import { area } from "./shapes";\n'; 26 + function history(project: Project) { 27 + project.init({ "src/shapes.ts": SHAPES, "src/main.ts": IMPORT, "notes.md": "notes\n" }, 0); 28 + project.edit("ann", { file: "src/shapes.ts", old: "area(r: number)", new: "area(r: number, scale = 1)" }, 1); 29 + project.record("bob", { "src/main.ts": `${IMPORT}export const a = area(2);\n` }, 2); 30 + project.record("cy", { "notes.md": "notes\nmore\n" }, 3); 33 + const reads = (project: Project) => ({ 34 + status: project.status(), 35 + collisions: project.collisions(), 36 + tree: project.tree("", { authors: true }), 37 + bob: project.draftOf("bob")!.view.text("src/main.ts"), 40 + test("reads after afterRead answer as before it, and a write after it sees every agent", () => { 41 + const oracle = new Project(new MemoryStore()); 42 + const project = writer(); 45 + const expected = reads(oracle); 46 + assert.deepEqual(reads(project), expected); 48 + assert.deepEqual(reads(project), expected, "after afterRead"); 51 + for (const p of [oracle, project]) { 52 + p.record("cy", { "notes.md": "notes\nmore\nand more\n" }, 4); 53 + assert.equal(p.publish("ann", "Add a scale", 5).ok, true); 55 + assert.deepEqual(reads(project), reads(oracle), "a write after afterRead"); 56 + assert.ok(expected.collisions.collisions.some((c) => c.kind === "definition")); --- a/worker/project/test/view-cache.test.ts
+++ b/worker/project/test/view-cache.test.ts
@@ -103,6 +103,20 @@
106 + test("trim reweighs growth with no further hit and evicts until the views fit (abso Capacity)", () => { 107 + withControlledWeights((control) => { 108 + const cache = new ViewCache(new Graph()); 109 + control.setIncomingWeights([10_000_000, 10_000_000]); 110 + const growing = get(cache, "growing"); 111 + const newer = get(cache, "newer"); 112 + // A call lays files out in the older view after the cache last weighed it, and nothing asks for it again. 113 + control.setWeight(growing, 16_000_000); 115 + assert.equal(get(cache, "newer"), newer); 116 + assert.notEqual(get(cache, "growing"), growing); 106 120 test("an oversized view is returned but not retained", () => { 107 121 withControlledWeights((control) => { 108 122 const cache = new ViewCache(new Graph()); --- a/worker/project/views.ts
+++ b/worker/project/views.ts
@@ -39,6 +39,14 @@
42 + * Weigh every cached view again and evict until they fit (abso Capacity): views grow while a call lays files out, 43 + * and #get weighs a view only when it is asked for again. A kept reader trims after each call. 42 50 * Keep the cached views under VIEW_BUDGET bytes (the website project, #43, 43 51 * #46): each view holds every line its files ever had, so a few views of a 44 52 * large generated file add up. At most VIEW_COUNT. --- a/worker/project/writer-agents.ts
+++ b/worker/project/writer-agents.ts
@@ -47,6 +47,11 @@
50 + /** Let go of the agents read, when nothing changed them: a reader kept between calls (abso Capacity). */ 52 + this.#touched.clear(); 51 56 for (const [key, value] of this.#touched) super.set(key, value); 52 57 this.#touched.clear();