{"draft":null,"from":102,"to":103,"files":[{"path":"src/engine/view.ts","added":46,"removed":13,"diff":"--- a/src/engine/view.ts\n+++ b/src/engine/view.ts\n@@ -71,6 +71,16 @@\n const EMPTY_INTS = new Int32Array(0);\n const NO_FILE: FileState = { attrs: NO_ATTRS, seq: EMPTY_INTS, vis: EMPTY_INTS, deletedBy: new Map() };\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+const ARRAY_HEADER_BYTES = 24;\n+const OBJECT_BYTES = 32;\n+const MAP_HEADER_BYTES = 32;\n+const MAP_ENTRY_BYTES = 40;\n+const SET_ENTRY_BYTES = 32;\n+const REFERENCE_BYTES = 8;\n+\n /**\n  * The projection of a closed set. Construct once, then ask for files, lines\n  * and sequences. Throws `not-closed` if some atom's dependency is missing.\n@@ -448,21 +458,44 @@\n \t}\n \n \t/**\n-\t * About how many bytes keeping this view costs (#46): its laid-out files\n-\t * (4 bytes a line, and more for a deleted line and for positions once asked\n-\t * for), and the records it keeps for the file it was last asked about.\n+\t * About how many bytes of retained state this view costs (#46). This uses\n+\t * approximate ownership costs for containers and wrappers, not V8 heap\n+\t * measurements. Graph-owned strings and records count only as references.\n+\t * This method only inspects already-created state: it does not lay out files,\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-\t\tlet n = 0;\n-\t\tfor (const f of this.#files.values())\n-\t\t\tn +=\n-\t\t\t\t4 * (f.seq.length + f.vis.length) +\n-\t\t\t\t40 * f.deletedBy.size +\n-\t\t\t\t24 * ((f.seqIndex?.size ?? 0) + (f.visIndex?.size ?? 0));\n-\t\tn +=\n-\t\t\t100 * (this.#linesCache?.lines.length ?? 0) +\n-\t\t\t120 * (this.#seqCache?.seq.length ?? 0) +\n-\t\t\t2 * (this.#textCache?.text.length ?? 0);\n+\t\tlet n = this.#in.byteLength;\n+\t\tn += ARRAY_HEADER_BYTES + REFERENCE_BYTES * this.#movers.length;\n+\t\tn += MAP_HEADER_BYTES; // #files exists from construction.\n+\t\tn += MAP_HEADER_BYTES; // #fileOf exists from construction.\n+\t\tif (this.#set) n += OBJECT_BYTES + SET_ENTRY_BYTES * this.#set.size;\n+\t\tif (this.#knownList) n += ARRAY_HEADER_BYTES + REFERENCE_BYTES * this.#knownList.length;\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.#fileOf.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+\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\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\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}\n+\t\t}\n+\t\tif (this.#linesCache)\n+\t\t\tn += OBJECT_BYTES + REFERENCE_BYTES + ARRAY_HEADER_BYTES + 100 * this.#linesCache.lines.length;\n+\t\tif (this.#seqCache) {\n+\t\t\tn += OBJECT_BYTES + REFERENCE_BYTES + ARRAY_HEADER_BYTES + 120 * this.#seqCache.seq.length;\n+\t\t\tfor (const line of this.#seqCache.seq)\n+\t\t\t\tif (line.deletedBy !== NONE) n += ARRAY_HEADER_BYTES + REFERENCE_BYTES * line.deletedBy.length;\n+\t\t}\n+\t\tif (this.#textCache) n += OBJECT_BYTES + REFERENCE_BYTES + ARRAY_HEADER_BYTES + 2 * this.#textCache.text.length;\n \t\treturn n;\n \t}\n "}],"unmatched":[]}