{"version":116,"agent":"codex-capacity-chair","message":"Bound repeated indexed view membership lookups","time":1791830067862,"timeIso":"2026-10-12T18:34:27.862Z","changes":3,"change":1284,"files":["src/engine/test/view.test.ts","src/engine/view.ts"],"draft":null,"diff":[{"path":"src/engine/test/view.test.ts","added":26,"removed":0,"diff":"--- a/src/engine/test/view.test.ts\n+++ b/src/engine/test/view.test.ts\n@@ -8,6 +8,21 @@\n import { lines, Repo } from \"./helpers.ts\";\n \n describe(\"View\", () => {\n+\tit(\"reuses indexed membership across a long run of lines without a history-sized memo\", () => {\n+\t\tconst repo = Repo.init({ \"long.txt\": \"line\\n\".repeat(1000) });\n+\t\tclass CountingSet extends StableOverlaySet<AtomId> {\n+\t\t\tcalls = 0;\n+\t\t\toverride has(id: AtomId): boolean {\n+\t\t\t\tthis.calls++;\n+\t\t\t\treturn super.has(id);\n+\t\t\t}\n+\t\t}\n+\t\tconst set = new CountingSet([\"a0\"]);\n+\t\tconst view = new View(repo.graph, set);\n+\t\tset.calls = 0;\n+\t\tassert.equal(view.text(\"long.txt\"), \"line\\n\".repeat(1000));\n+\t\tassert.ok(set.calls <= 2, `membership was queried ${set.calls} times for one atom`);\n+\t});\n \tit(\"immutable indexed membership avoids a history-sized bitmap and remains a snapshot\", () => {\n \t\tclass RangeMembership extends StableSet<AtomId> {\n \t\t\treadonly retainedBytes = 64;\n@@ -41,6 +56,17 @@\n \t\tassert.equal(first.set.has(\"a80\"), false);\n \t\tassert.throws(() => new View(repo.graph, new StableOverlaySet<AtomId>([\"a1\"])), /not closed/);\n \t});\n+\tit(\"membership memo collisions preserve both included and excluded historical atoms\", () => {\n+\t\tconst repo = Repo.init({ \"f.txt\": \"0\\n\" });\n+\t\tfor (let i = 1; i <= 257; i++) repo.edit({ edits: [{ file: \"f.txt\", old: `${i - 1}\\n`, new: `${i}\\n` }] });\n+\t\tconst old = new View(repo.graph, new StableOverlaySet<AtomId>([\"a0\"]));\n+\t\tassert.equal(old.text(\"f.txt\"), \"0\\n\");\n+\t\tassert.deepEqual(\n+\t\t\told.sequence(\"f.txt\").map((line) => line.text),\n+\t\t\t[\"0\"],\n+\t\t);\n+\t\tassert.equal(repo.view().text(\"f.txt\"), \"257\\n\");\n+\t});\n \tit(\"keeps deleted lines as tombstones in the full sequence\", () => {\n \t\tconst repo = Repo.init({ \"f.txt\": lines(\"one\", \"two\", \"three\") });\n \t\tconst del = repo.edit({ edits: [{ file: \"f.txt\", old: \"two\\n\", new: \"\" }] });"},{"path":"src/engine/view.ts","added":12,"removed":1,"diff":"--- a/src/engine/view.ts\n+++ b/src/engine/view.ts\n@@ -95,6 +95,9 @@\n \t/** The set, made from #in the first time it's asked for: a view keeps a byte per atom, not a copy of the set (#46). */\n \t#set: AtomSet | undefined;\n \treadonly #stable: StableSet<AtomId> | undefined;\n+\t/** Fixed-size memo for immutable indexed membership, independent of history size. */\n+\t#membershipSeq = new Float64Array(256).fill(-1);\n+\t#membershipValue = new Uint8Array(256);\n \t#files = new Map<string, FileState>();\n \t/** Every file the set wrote in, sorted; worked out the first time it's asked for. */\n \t#knownList: string[] | undefined;\n@@ -165,7 +168,14 @@\n \n \t/** Whether the atom with this seq is in the set. */\n \t#has(seq: number): boolean {\n-\t\tif (this.#stable) return this.#stable.has(this.graph.idOfSeq(seq));\n+\t\tif (this.#stable) {\n+\t\t\tconst slot = seq % this.#membershipSeq.length;\n+\t\t\tif (this.#membershipSeq[slot] === seq) return this.#membershipValue[slot] === 1;\n+\t\t\tconst present = this.#stable.has(this.graph.idOfSeq(seq));\n+\t\t\tthis.#membershipSeq[slot] = seq;\n+\t\t\tthis.#membershipValue[slot] = present ? 1 : 0;\n+\t\t\treturn present;\n+\t\t}\n \t\treturn seq < this.#in.length && this.#in[seq] === 1;\n \t}\n \n@@ -498,6 +508,7 @@\n \t */\n \tweight(): number {\n \t\tlet n = this.#in.byteLength;\n+\t\tn += 2 * ARRAY_HEADER_BYTES + this.#membershipSeq.byteLength + this.#membershipValue.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."}],"ci":null}