{"draft":null,"from":262,"to":263,"files":[{"path":"src/engine/view.ts","added":37,"removed":1,"diff":"--- a/src/engine/view.ts\n+++ b/src/engine/view.ts\n@@ -54,6 +54,8 @@\n \t| \"shareMoves\"\n \t| \"shareFiles\"\n \t| \"knowPaths\"\n+\t| \"laidOut\"\n+\t| \"forget\"\n \t| \"fileOfNumber\"\n \t| \"lineNumberOf\"\n \t| \"visibleWriters\"\n@@ -122,6 +124,9 @@\n const EMPTY_INTS = new Int32Array(0);\n const NO_FILE: FileState = { attrs: NO_ATTRS, complete: true, seq: EMPTY_INTS, vis: EMPTY_INTS, deletedBy: new Map() };\n \n+/** A count of file uses shared by every view, so a cache can tell which layout across its views was used longest ago. */\n+let fileUses = 0;\n+\n // Approximate retained-container costs for View.weight(): reference slots,\n // object headers, and map/set entries. These are cache-budget units, not V8\n // heap measurements. Referenced Graph strings and records are not charged.\n@@ -914,7 +919,10 @@\n \t\t\tconst paths: string[] = [];\n \t\t\tfor (const path of this.graph.knownFiles()) {\n \t\t\t\tif (this.hasFile(path)) paths.push(path);\n-\t\t\t\telse this.#files.delete(path);\n+\t\t\t\telse {\n+\t\t\t\t\tthis.#files.delete(path);\n+\t\t\t\t\tthis.#used.delete(path);\n+\t\t\t\t}\n \t\t\t}\n \t\t\treturn paths.sort();\n \t\t}\n@@ -1168,6 +1176,7 @@\n \t\tif (this.#relocs) n += MAP_HEADER_BYTES + MAP_ENTRY_BYTES * this.#relocs.size;\n \t\tif (this.#relocsN) n += MAP_HEADER_BYTES + (MAP_ENTRY_BYTES + OBJECT_BYTES) * this.#relocsN.size;\n \t\tn += MAP_ENTRY_BYTES * this.#picked.size;\n+\t\tn += MAP_ENTRY_BYTES * this.#used.size;\n \t\tfor (const f of this.#files.values()) {\n \t\t\tn += MAP_ENTRY_BYTES;\n \t\t\tif (f !== NO_FILE) {\n@@ -1197,8 +1206,35 @@\n \t\t\telse state = this.graph.hasAtomsIn(path) ? this.#layout(path, complete) : NO_FILE;\n \t\t\tthis.#files.set(path, state);\n \t\t}\n+\t\tif (state !== NO_FILE) this.#used.set(path, ++fileUses);\n \t\treturn state;\n \t}\n+\n+\t/** When each laid-out file was last used (fileUses). */\n+\treadonly #used = new Map<string, number>();\n+\n+\t/**\n+\t * Each laid-out file: its layout, when it was last used (a count shared by every view) and what it holds, for a\n+\t * cache that trims the least recently used layouts across its views before whole views (views.ts, abso Capacity).\n+\t */\n+\t*laidOut(): IterableIterator<{ path: string; layout: object; used: number; bytes: number }> {\n+\t\tfor (const [path, f] of this.#files) {\n+\t\t\tif (f === NO_FILE) continue;\n+\t\t\tlet bytes = 2 * MAP_ENTRY_BYTES + layoutBytes(f);\n+\t\t\tif (f.seqIndex) bytes += MAP_HEADER_BYTES + MAP_ENTRY_BYTES * f.seqIndex.size;\n+\t\t\tif (f.visIndex) bytes += MAP_HEADER_BYTES + MAP_ENTRY_BYTES * f.visIndex.size;\n+\t\t\tyield { path, layout: f, used: this.#used.get(path) ?? 0, bytes };\n+\t\t}\n+\t}\n+\n+\t/** Let go of a file's layout: the next ask lays it out again, the same. */\n+\tforget(path: string): void {\n+\t\tthis.#files.delete(path);\n+\t\tthis.#used.delete(path);\n+\t\tif (this.#linesCache?.path === path) this.#linesCache = undefined;\n+\t\tif (this.#seqCache?.path === path) this.#seqCache = undefined;\n+\t\tif (this.#textCache?.path === path) this.#textCache = undefined;\n+\t}\n }\n \n /** The files of a closed set, path -> text. */"}],"unmatched":[]}