Lines 71–86 at 103 (were 71–76 at 102)
7171const EMPTY_INTS = new Int32Array(0); 7272const NO_FILE: FileState = { attrs: NO_ATTRS, seq: EMPTY_INTS, vis: EMPTY_INTS, deletedBy: new Map() }; 74+// Approximate retained-container costs for View.weight(): reference slots, 75+// object headers, and map/set entries. These are cache-budget units, not V8 76+// heap measurements. Referenced Graph strings and records are not charged. 77+const ARRAY_HEADER_BYTES = 24; 78+const OBJECT_BYTES = 32; 79+const MAP_HEADER_BYTES = 32; 80+const MAP_ENTRY_BYTES = 40; 81+const SET_ENTRY_BYTES = 32; 82+const REFERENCE_BYTES = 8; 7585 * The projection of a closed set. Construct once, then ask for files, lines 7686 * and sequences. Throws `not-closed` if some atom's dependency is missing. Lines 458–501 at 103 (were 448–468 at 102)
451− * About how many bytes keeping this view costs (#46): its laid-out files
452− * (4 bytes a line, and more for a deleted line and for positions once asked
453− * for), and the records it keeps for the file it was last asked about.
461+ * About how many bytes of retained state this view costs (#46). This uses 462+ * approximate ownership costs for containers and wrappers, not V8 heap 463+ * measurements. Graph-owned strings and records count only as references. 464+ * This method only inspects already-created state: it does not lay out files, 465+ * populate lazy caches, enumerate the graph, or count temporary traversal 466+ * containers and shared empty singleton payloads as retained view state. 455468 weight(): number { 456− let n = 0;
457− for (const f of this.#files.values())
458− n +=
459− 4 * (f.seq.length + f.vis.length) +
460− 40 * f.deletedBy.size +
461− 24 * ((f.seqIndex?.size ?? 0) + (f.visIndex?.size ?? 0));
462− n +=
463− 100 * (this.#linesCache?.lines.length ?? 0) +
464− 120 * (this.#seqCache?.seq.length ?? 0) +
465− 2 * (this.#textCache?.text.length ?? 0);
469+ let n = this.#in.byteLength; 470+ n += ARRAY_HEADER_BYTES + REFERENCE_BYTES * this.#movers.length; 471+ n += MAP_HEADER_BYTES; // #files exists from construction. 472+ n += MAP_HEADER_BYTES; // #fileOf exists from construction. 473+ if (this.#set) n += OBJECT_BYTES + SET_ENTRY_BYTES * this.#set.size; 474+ if (this.#knownList) n += ARRAY_HEADER_BYTES + REFERENCE_BYTES * this.#knownList.length; 475+ if (this.#relocs) n += MAP_HEADER_BYTES + MAP_ENTRY_BYTES * this.#relocs.size; 476+ if (this.#relocsN) n += MAP_HEADER_BYTES + (MAP_ENTRY_BYTES + OBJECT_BYTES) * this.#relocsN.size; 477+ n += MAP_ENTRY_BYTES * this.#fileOf.size; 478+ for (const f of this.#files.values()) { 479+ n += MAP_ENTRY_BYTES; 480+ if (f !== NO_FILE) { 481+ // FileState and FileAttrs are per laid-out file; typed-array 482+ // headers are separate from their payload byte lengths below. 483+ n += OBJECT_BYTES + OBJECT_BYTES + 2 * ARRAY_HEADER_BYTES; 484+ n += f.seq.byteLength + f.vis.byteLength; 485+ n += MAP_HEADER_BYTES + (MAP_ENTRY_BYTES + ARRAY_HEADER_BYTES) * f.deletedBy.size; 486+ for (const deleters of f.deletedBy.values()) n += REFERENCE_BYTES * deleters.length; 487+ if (f.seqIndex) n += MAP_HEADER_BYTES + MAP_ENTRY_BYTES * f.seqIndex.size; 488+ if (f.visIndex) n += MAP_HEADER_BYTES + MAP_ENTRY_BYTES * f.visIndex.size; 491+ if (this.#linesCache) 492+ n += OBJECT_BYTES + REFERENCE_BYTES + ARRAY_HEADER_BYTES + 100 * this.#linesCache.lines.length; 493+ if (this.#seqCache) { 494+ n += OBJECT_BYTES + REFERENCE_BYTES + ARRAY_HEADER_BYTES + 120 * this.#seqCache.seq.length; 495+ for (const line of this.#seqCache.seq) 496+ if (line.deletedBy !== NONE) n += ARRAY_HEADER_BYTES + REFERENCE_BYTES * line.deletedBy.length; 498+ if (this.#textCache) n += OBJECT_BYTES + REFERENCE_BYTES + ARRAY_HEADER_BYTES + 2 * this.#textCache.text.length;