{"version":274,"agent":"capacity","message":"Cold reads (abso Capacity, issue 664): a packed layout reads only the text pages holding a line it shows; definition code stays in memory up to 4 MB; a stored array's element read skips its length read.\n\n- Layout: each line's file and place are kept and texts are read after the walk, a page at a time, only for shown lines. Every text a file and the files its moved-in lines came from ever had was read for every layout; abso's worker files, split out of index.ts, each read all of index.ts's history. Cold compare 612 to 1224 on abso read text pages 17,080 times, now 2,856.\n- Definition code: at 64 KB every large file's parsed code went row by row into scratch and back (25,000 rows each for index.ts). The visible lines are already in memory, so 4 MB at most doubles a file's text for the call. withDefinitionCode takes the limit; its scratch test passes 64 KB.\n- storedArray: set writes the row and the length together and nothing shrinks, so no row lies past the length; half of a cold layout's reads were the length.\n\nSide by side on abso's export, same machine, three rounds: cold collisions 10.5 s to 6.2 s, cold compare 12.6 s to 8.6 s. tsc clean; view, state-cache, state-source, graph, graph-long-text, graph-line-chunks, graph-move-write-membership, definition-code, definitions, changed-definition, collisions-kept-views and draft-reads-stored tests: 73 pass.","time":1792103593251,"timeIso":"2026-10-15T22:33:13.251Z","changes":5,"change":4138,"files":["src/engine/graph.ts","src/engine/state-source.ts","src/engine/view.ts","worker/project/definition-code.ts","worker/project/test/definition-code.test.ts"],"draft":null,"diff":[{"path":"src/engine/graph.ts","added":7,"removed":0,"diff":"--- a/src/engine/graph.ts\n+++ b/src/engine/graph.ts\n@@ -691,6 +691,13 @@\n \t*packedTexts(file: number): IterableIterator<string | null> {\n \t\tyield* this.#fileTexts!.values(String(file));\n \t}\n+\t/**\n+\t * The texts at positions [page * 256, (page + 1) * 256) of packedTexts(file) (abso Capacity): a layout reads only the\n+\t * pages holding a line it shows.\n+\t */\n+\tpackedTextPage(file: number, page: number): readonly (string | null)[] {\n+\t\treturn this.#fileTexts!.pageAt(String(file), page);\n+\t}\n \t*packedDeletes(file: number): IterableIterator<PackedDelete> {\n \t\tyield* this.#fileDeletes!.values(String(file));\n \t}"},{"path":"src/engine/state-source.ts","added":11,"removed":1,"diff":"--- a/src/engine/state-source.ts\n+++ b/src/engine/state-source.ts\n@@ -348,7 +348,9 @@\n \treturn new Proxy([] as T[], {\n \t\tget(target, key, receiver) {\n \t\t\tif (key === \"length\") return length();\n-\t\t\tif (indexKey(key)) return Number(key) < length() ? read(key) : undefined;\n+\t\t\t// No length read first (abso Capacity): set writes the row and the length together and nothing shrinks, so no\n+\t\t\t// row lies past the length. Half of a cold layout's reads were this length.\n+\t\t\tif (indexKey(key)) return read(key);\n \t\t\treturn Reflect.get(target, key, receiver);\n \t\t},\n \t\tset(_target, key, value) {\n@@ -419,6 +421,14 @@\n \t\t\t}\n \t\t\tfor (const [key] of storage.entries(`${name}:lengths`)) yield key;\n \t\t},\n+\t\t/** Values [index * PAGE, (index + 1) * PAGE) of `key`'s list: one page, not the whole list (abso Capacity). */\n+\t\tpageAt(key: string, index: number): readonly V[] {\n+\t\t\tconst count = length(key);\n+\t\t\tconst values = page(key, index);\n+\t\t\tif (values.length !== Math.min(pageSize, count - index * pageSize))\n+\t\t\t\tthrow new Error(`incomplete writer list page in ${name}`);\n+\t\t\treturn values;\n+\t\t},\n \t\t*values(key: string): IterableIterator<V> {\n \t\t\tconst count = length(key);\n \t\t\tfor (let start = 0; start < count; start += pageSize) {"},{"path":"src/engine/view.ts","added":23,"removed":6,"diff":"--- a/src/engine/view.ts\n+++ b/src/engine/view.ts\n@@ -755,7 +755,11 @@\n \t\tconst relocs = this.#hasMoves ? this.#relocationsN() : undefined;\n \t\tconst files = new Set<number>([-1 - start, ...(this.#movedInFrom().get(path) ?? [])]);\n \t\tconst children = new Map<number, Child[]>();\n-\t\tconst texts = new Map<number, string | null>();\n+\t\t// Where each line's text is: its file and its place in that file's packed history. Texts are read after the walk,\n+\t\t// only for the lines it shows (abso Capacity): every text a file and its moved-in sources ever had was read for\n+\t\t// every layout, and abso's worker files, split out of index.ts, read all of index.ts's history each.\n+\t\tconst textFile = new Map<number, number>();\n+\t\tconst textPlace = new Map<number, number>();\n \t\tconst writers = new Map<number, number>();\n \t\tconst places = new Map<number, number>();\n \t\tconst deleters = new Map<number, number[]>();\n@@ -770,9 +774,9 @@\n \t\t\treturn lamport;\n \t\t};\n \t\tfor (const file of files) {\n-\t\t\tconst lineTexts = graph.packedTexts(file);\n+\t\t\tlet place = -1;\n \t\t\tfor (const [n, parent, seq, k, replaces] of graph.packedLines(file)) {\n-\t\t\t\tconst text = lineTexts.next().value as string | null;\n+\t\t\t\tplace++;\n \t\t\t\tif (!this.#has(seq)) continue;\n \t\t\t\tconst moved = relocs?.get(n);\n \t\t\t\tlet at = parent;\n@@ -785,7 +789,8 @@\n \t\t\t\tconst list = children.get(at);\n \t\t\t\tif (list) list.push(child);\n \t\t\t\telse children.set(at, [child]);\n-\t\t\t\ttexts.set(n, text);\n+\t\t\t\ttextFile.set(n, file);\n+\t\t\t\ttextPlace.set(n, place);\n \t\t\t\twriters.set(n, seq);\n \t\t\t\tplaces.set(n, k);\n \t\t\t}\n@@ -796,7 +801,7 @@\n \t\t\t\telse deleters.set(n, [deleter]);\n \t\t\t}\n \t\t\t// Runs written elsewhere under this file's lines follow them; the loop reads their files too.\n-\t\t\tfor (const [parent, into] of graph.packedCrossings(file)) if (texts.has(parent)) files.add(into);\n+\t\t\tfor (const [parent, into] of graph.packedCrossings(file)) if (writers.has(parent)) files.add(into);\n \t\t}\n \t\tconst order = (a: Child, b: Child) =>\n \t\t\tb.replaces - a.replaces || b.lamport - a.lamport || b.seq - a.seq || a.k - b.k;\n@@ -809,6 +814,18 @@\n \t\tconst seqWriter: number[] = [];\n \t\tconst seqK: number[] = [];\n \t\tconst deletedBy = new Map<number, readonly number[]>();\n+\t\t// The text pages read for this layout, by file and page: each at most once.\n+\t\tconst pages = new Map<number, Map<number, readonly (string | null)[]>>();\n+\t\tconst textOf = (n: number): string | null => {\n+\t\t\tconst file = textFile.get(n)!;\n+\t\t\tconst place = textPlace.get(n)!;\n+\t\t\tconst page = Math.floor(place / 256);\n+\t\t\tlet byPage = pages.get(file);\n+\t\t\tif (!byPage) pages.set(file, (byPage = new Map()));\n+\t\t\tlet texts = byPage.get(page);\n+\t\t\tif (!texts) byPage.set(page, (texts = graph.packedTextPage(file, page)));\n+\t\t\treturn texts[place % 256] ?? null;\n+\t\t};\n \t\tconst stack: number[] = [];\n \t\tconst push = (code: number) => {\n \t\t\tconst list = children.get(code);\n@@ -824,7 +841,7 @@\n \t\t\t\tif (complete) deletedBy.set(seq.length, by.length > 1 ? by.sort(priority) : by);\n \t\t\t} else {\n \t\t\t\tvis.push(n);\n-\t\t\t\tvisText.push(texts.get(n) ?? null);\n+\t\t\t\tvisText.push(textOf(n));\n \t\t\t\tvisWriter.push(writers.get(n)!);\n \t\t\t\tvisK.push(places.get(n)!);\n \t\t\t}"},{"path":"worker/project/definition-code.ts","added":9,"removed":1,"diff":"--- a/worker/project/definition-code.ts\n+++ b/worker/project/definition-code.ts\n@@ -2,11 +2,19 @@\n import { StoredText } from \"../../src/engine/stored-text.ts\";\n import { eachCodeLine } from \"./names.ts\";\n \n+/**\n+ * Characters of parsed code kept in memory before the rest goes to scratch (abso Capacity). The visible lines it is\n+ * parsed from are already in memory, so this at most doubles a file's text for the call; at 64 KB, every large file's\n+ * code went row by row into scratch and back, 25,000 rows each for abso's index.ts, a third of a cold collisions call.\n+ */\n+export const DEFINITION_CODE_IN_MEMORY = 4_000_000;\n+\n /** Parsed code is temporary derived data, discarded with the scratch transaction. */\n export function withDefinitionCode<T>(\n \tview: ReadView,\n \tvisible: readonly VisibleLine[],\n \toperation: (code: readonly string[]) => T,\n+\tinMemory = DEFINITION_CODE_IN_MEMORY,\n ): T {\n \tfunction* source() {\n \t\tfor (const line of visible) yield line.text;\n@@ -16,7 +24,7 @@\n \tlet prefix: string[] = [];\n \tlet size = 0;\n \tlet pending = iterator.next();\n-\twhile (!pending.done && size + pending.value.length + 1 <= 65536) {\n+\twhile (!pending.done && size + pending.value.length + 1 <= inMemory) {\n \t\tprefix.push(pending.value);\n \t\tsize += pending.value.length + 1;\n \t\tpending = iterator.next();"},{"path":"worker/project/test/definition-code.test.ts","added":13,"removed":5,"diff":"--- a/worker/project/test/definition-code.test.ts\n+++ b/worker/project/test/definition-code.test.ts\n@@ -39,18 +39,26 @@\n \tconst rows = () => storage.db.prepare(\"SELECT * FROM state ORDER BY collection,key\").all();\n \tconst before = rows();\n \tlet escaped: readonly string[] = [];\n-\twithDefinitionCode(view, view.buildLines(\"f.ts\"), (code) => {\n-\t\tescaped = code;\n+\twithDefinitionCode(\n+\t\tview,\n+\t\tview.buildLines(\"f.ts\"),\n+\t\t(code) => {\n+\t\t\tescaped = code;\n \t\tassert.deepEqual(code.slice(0, 4), expected.slice(0, 4));\n \t\tfor (let i = code.length - 1; i >= 0; i--) assert.equal(code[i], expected[i]);\n-\t\tfor (let i = 0; i < code.length; i++) assert.equal(code[i], expected[i]);\n-\t});\n+\t\t\tfor (let i = 0; i < code.length; i++) assert.equal(code[i], expected[i]);\n+\t\t},\n+\t\t65536,\n+\t);\n \tassert.throws(() => escaped[0], /scope has ended/);\n \tassert.deepEqual(rows(), before);\n \tassert.deepEqual(definitionsIn(view), definitionsIn(new View(memory, [\"a0\"])));\n \tassert.deepEqual(definedTwice(view, \"f.ts\"), definedTwice(new View(memory, [\"a0\"]), \"f.ts\"));\n \tassert.deepEqual(rows(), before);\n \tstorage.failWrite = storage.writes + 2;\n-\tassert.throws(() => withDefinitionCode(view, view.buildLines(\"f.ts\"), () => []), /injected storage failure/);\n+\tassert.throws(\n+\t\t() => withDefinitionCode(view, view.buildLines(\"f.ts\"), () => [], 65536),\n+\t\t/injected storage failure/,\n+\t);\n \tassert.deepEqual(rows(), before);\n });"}],"ci":null}