{"version":241,"agent":"capacity","message":"The view cache counts a file layout two views share once (disk-first 2; abso Capacity).\n\nTesting 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.\n\n- 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)).\n- 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.\n\nOn 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.\n\nNamed 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.","time":1792070260689,"timeIso":"2026-10-15T13:17:40.689Z","changes":2,"change":3730,"files":["src/engine/view.ts","worker/project/views.ts"],"draft":null,"diff":[{"path":"src/engine/view.ts","added":26,"removed":12,"diff":"--- a/src/engine/view.ts\n+++ b/src/engine/view.ts\n@@ -55,6 +55,28 @@\n };\n \n const NO_ATTRS: FileAttrs = { exists: false, exec: false, link: null, blob: null };\n+\n+/**\n+ * A file layout's bytes, less its lookup indexes, worked out once per layout (abso Capacity): a layout never changes\n+ * once made, and the view cache weighs every view it holds on every lookup, which summed every line's text again.\n+ */\n+const layoutSizes = new WeakMap<FileState, number>();\n+function layoutBytes(f: FileState): number {\n+\tlet n = layoutSizes.get(f);\n+\tif (n !== undefined) return n;\n+\t// FileState and FileAttrs are per laid-out file; typed-array headers are separate from their payload byte lengths.\n+\tn = OBJECT_BYTES + OBJECT_BYTES + 2 * ARRAY_HEADER_BYTES;\n+\tn += f.seq.byteLength + f.vis.byteLength;\n+\tif (f.visText) for (const text of f.visText) n += REFERENCE_BYTES + 2 * (text?.length ?? 0);\n+\tif (f.visWriter) n += 4 * f.visWriter.length;\n+\tif (f.visK) n += 4 * f.visK.length;\n+\tif (f.seqWriter) n += 4 * f.seqWriter.length;\n+\tif (f.seqK) n += 4 * f.seqK.length;\n+\tn += MAP_HEADER_BYTES + (MAP_ENTRY_BYTES + ARRAY_HEADER_BYTES) * f.deletedBy.size;\n+\tfor (const deleters of f.deletedBy.values()) n += REFERENCE_BYTES * deleters.length;\n+\tlayoutSizes.set(f, n);\n+\treturn n;\n+}\n const NONE: readonly never[] = Object.freeze([]);\n \n interface FileState {\n@@ -1087,7 +1109,7 @@\n \t * populate lazy caches, enumerate the graph, or count temporary traversal\n \t * containers and shared empty singleton payloads as retained view state.\n \t */\n-\tweight(): number {\n+\tweight(seen?: Set<object>): number {\n \t\tlet n = this.#in.byteLength;\n \t\tn += 2 * ARRAY_HEADER_BYTES + this.#membershipSeq.byteLength + this.#membershipValue.byteLength;\n \t\tif (this.#movers) n += ARRAY_HEADER_BYTES + REFERENCE_BYTES * this.#movers.length;\n@@ -1101,17 +1123,9 @@\n \t\tfor (const f of this.#files.values()) {\n \t\t\tn += MAP_ENTRY_BYTES;\n \t\t\tif (f !== NO_FILE) {\n-\t\t\t\t// FileState and FileAttrs are per laid-out file; typed-array\n-\t\t\t\t// headers are separate from their payload byte lengths below.\n-\t\t\t\tn += OBJECT_BYTES + OBJECT_BYTES + 2 * ARRAY_HEADER_BYTES;\n-\t\t\t\tn += f.seq.byteLength + f.vis.byteLength;\n-\t\t\t\tif (f.visText) for (const text of f.visText) n += REFERENCE_BYTES + 2 * (text?.length ?? 0);\n-\t\t\t\tif (f.visWriter) n += 4 * f.visWriter.length;\n-\t\t\t\tif (f.visK) n += 4 * f.visK.length;\n-\t\t\t\tif (f.seqWriter) n += 4 * f.seqWriter.length;\n-\t\t\t\tif (f.seqK) n += 4 * f.seqK.length;\n-\t\t\t\tn += MAP_HEADER_BYTES + (MAP_ENTRY_BYTES + ARRAY_HEADER_BYTES) * f.deletedBy.size;\n-\t\t\t\tfor (const deleters of f.deletedBy.values()) n += REFERENCE_BYTES * deleters.length;\n+\t\t\t\t// A layout another view counted already (`seen`, across a cache's views) isn't counted again.\n+\t\t\t\tif (!seen?.has(f)) n += layoutBytes(f);\n+\t\t\t\tseen?.add(f);\n \t\t\t\tif (f.seqIndex) n += MAP_HEADER_BYTES + MAP_ENTRY_BYTES * f.seqIndex.size;\n \t\t\t\tif (f.visIndex) n += MAP_HEADER_BYTES + MAP_ENTRY_BYTES * f.visIndex.size;\n \t\t\t}"},{"path":"worker/project/views.ts","added":16,"removed":4,"diff":"--- a/worker/project/views.ts\n+++ b/worker/project/views.ts\n@@ -44,11 +44,23 @@\n \t * large generated file add up. At most VIEW_COUNT.\n \t */\n \t#trim(): void {\n+\t\t// The newest views that fit, as evicting oldest first leaves them. A file layout two views share (a draft's view\n+\t\t// takes its base's, View.shareFiles) counts once (abso Capacity): counted per view, they filled the budget twice\n+\t\t// over, and a kept writer laid abso's drafts out again on every collisions call.\n+\t\tconst seen = new Set<object>();\n \t\tlet total = 0;\n-\t\tfor (const v of this.#cache.values()) total += v.weight();\n-\t\tfor (const [key, v] of this.#cache) {\n-\t\t\tif (total <= VIEW_BUDGET && this.#cache.size <= VIEW_COUNT) break;\n-\t\t\ttotal -= v.weight();\n+\t\tlet kept = 0;\n+\t\tlet full = false;\n+\t\tfor (const [key, v] of [...this.#cache].reverse()) {\n+\t\t\tif (!full) {\n+\t\t\t\tconst w = v.weight(seen);\n+\t\t\t\tif (total + w <= VIEW_BUDGET && kept < VIEW_COUNT) {\n+\t\t\t\t\ttotal += w;\n+\t\t\t\t\tkept++;\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\t\t\t\tfull = true;\n+\t\t\t}\n \t\t\tthis.#cache.delete(key);\n \t\t}\n \t}"}],"ci":null}