Skip priority decoding for implicit-only child traversal
of shared·codex-capacity-chair··Not checked
Version 134 · Files at version 135
2 files, 35 lines added, 2 removed.
--- a/src/engine/graph.ts
+++ b/src/engine/graph.ts
@@ -665,8 +665,8 @@
665665 const index = new OrderedIndex(this.#storage, "ordered-children", String(code)); 666666 if (this.#storage.read("ordered-children", "format") !== 1) 667667 throw new Error("ordered children require fresh adoption"); 668− if (index.size !== this.#runStartPages!.length(String(code))) throw new Error("ordered child index count mismatch");
669− const cursor = after === undefined ? undefined : this.#childPriority(after);
668+ const count = index.size; 669+ if (count !== this.#runStartPages!.length(String(code))) throw new Error("ordered child index count mismatch"); 670670 let implicit: number | undefined; @@ -675,6 +675,14 @@
675675 this.#lineParent.at(code + 1) === code 677677 implicit = code + 1; 678+ // Most historical run lines have no explicit child. With zero or one 679+ // child, traversal needs no priority decoding or radix lookup. Keep the 680+ // format/count checks above even on this path. 681+ if (count === 0 && (after === undefined || after === implicit)) { 682+ if (implicit !== undefined && after !== implicit) yield implicit; 685+ const cursor = after === undefined ? undefined : this.#childPriority(after); 678686 if (implicit !== undefined && cursor !== undefined && this.#childPriority(implicit) <= cursor) implicit = undefined; 679687 for (const n of index.values(cursor)) { 680688 if (implicit !== undefined && this.#childPriority(implicit) < this.#childPriority(n)) { --- a/src/engine/test/state-source.test.ts
+++ b/src/engine/test/state-source.test.ts
@@ -469,6 +469,31 @@
472+test("implicit ordered successors avoid priority reads but retain index validation", () => { 473+ class ObservedStorage extends SqlState { 475+ override read(collection: string, key: string): unknown { 476+ if (collection === "lamport" || collection.startsWith("replacing:")) this.priorityReads++; 477+ return super.read(collection, key); 480+ const storage = new ObservedStorage(); 482+ const oracle = Repo.init({ "a.txt": "one\ntwo\nthree\n" }); 483+ const graph = new Graph({ storage }); 484+ graph.add(oracle.graph.atom("a0")); 485+ storage.priorityReads = 0; 486+ assert.deepEqual([...graph.orderedChildrenN(0)], [1]); 487+ assert.deepEqual([...graph.orderedChildrenN(0, 1)], []); 488+ assert.deepEqual([...graph.orderedChildrenN(2)], []); 489+ assert.equal(storage.priorityReads, 0, "single-child traversal does not decode sort priority"); 490+ storage.remove("ordered-children", "format"); 491+ assert.throws(() => [...graph.orderedChildrenN(0)], /fresh adoption/); 472497test("ordered layout refuses missing format or child metadata instead of dropping history", () => { 473498 const storage = new SqlState();