Links: the reviewer's reading order uses descendants; jobs gather phrases in one place
descendantsInOrder was a copy of model.ts's descendants. A job worked out the phrases to look up for a set of nodes the same way three times. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014yB6q4BHMwptTX3YFtkRab
This commit is contained in:
1 parent
9f8245e6d7
commit
e8b8d72e61
2 files changed
+8
-22
No files matched your search
@@ -83,8 +83,7 @@ export class Jobs {
|
|||||||
};
|
};
|
||||||
// First estimate: the uncached phrases in batches of 50, plus about one sense or search for every other node.
|
// First estimate: the uncached phrases in batches of 50, plus about one sense or search for every other node.
|
||||||
const snap = this.o.snap();
|
const snap = this.o.snap();
|
||||||
const phrases = new Set(nodes.flatMap((id) => (snap.nodes[id] ? extract(snap.nodes[id].body).flatMap((c) => c.variants) : [])));
|
const uncached = wiki ? wiki.uncached(phrasesOf(snap, nodes)) : 0;
|
||||||
const uncached = wiki ? wiki.uncached([...phrases]) : 0;
|
|
||||||
state.etaSec = Math.round(((Math.ceil(uncached / 50) + nodes.length * 0.5) * spacing) / 1000);
|
state.etaSec = Math.round(((Math.ceil(uncached / 50) + nodes.length * 0.5) * spacing) / 1000);
|
||||||
this.current = state;
|
this.current = state;
|
||||||
const ac = (this.stop = new AbortController());
|
const ac = (this.stop = new AbortController());
|
||||||
@@ -140,8 +139,7 @@ export class Jobs {
|
|||||||
const chunk = nodes.slice(i, i + CHUNK);
|
const chunk = nodes.slice(i, i + CHUNK);
|
||||||
const snap = this.o.snap();
|
const snap = this.o.snap();
|
||||||
if (wiki) {
|
if (wiki) {
|
||||||
const phrases = [...new Set(chunk.flatMap((id) => (snap.nodes[id] ? extract(snap.nodes[id].body).flatMap((c) => c.variants) : [])))];
|
await wiki.lookup(phrasesOf(snap, chunk), { priority: "bulk", signal });
|
||||||
await wiki.lookup(phrases, { priority: "bulk", signal });
|
|
||||||
}
|
}
|
||||||
for (const id of chunk) {
|
for (const id of chunk) {
|
||||||
if (signal.aborted) return;
|
if (signal.aborted) return;
|
||||||
@@ -159,10 +157,8 @@ export class Jobs {
|
|||||||
state.requests = (wiki?.requests ?? 0) - r0;
|
state.requests = (wiki?.requests ?? 0) - r0;
|
||||||
// What is left: the uncached phrases of the nodes not yet scanned, at the client's pace.
|
// What is left: the uncached phrases of the nodes not yet scanned, at the client's pace.
|
||||||
const left = nodes.slice(state.done);
|
const left = nodes.slice(state.done);
|
||||||
const snapNow = this.o.snap();
|
|
||||||
const phrases = new Set(left.slice(0, 200).flatMap((x) => (snapNow.nodes[x] ? extract(snapNow.nodes[x].body).flatMap((c) => c.variants) : [])));
|
|
||||||
const scale = left.length > 200 ? left.length / 200 : 1;
|
const scale = left.length > 200 ? left.length / 200 : 1;
|
||||||
state.etaSec = Math.round((((wiki ? Math.ceil(wiki.uncached([...phrases]) / 50) * scale : 0) + left.length * 0.5) * spacing) / 1000);
|
state.etaSec = Math.round((((wiki ? Math.ceil(wiki.uncached(phrasesOf(this.o.snap(), left.slice(0, 200))) / 50) * scale : 0) + left.length * 0.5) * spacing) / 1000);
|
||||||
if (Date.now() - lastAnnounce > 500 || state.done === state.total) {
|
if (Date.now() - lastAnnounce > 500 || state.done === state.total) {
|
||||||
lastAnnounce = Date.now();
|
lastAnnounce = Date.now();
|
||||||
this.o.announce(state);
|
this.o.announce(state);
|
||||||
@@ -186,3 +182,6 @@ export class Jobs {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The phrases a scan of these nodes would look up, each once. */
|
||||||
|
const phrasesOf = (snap: Snap, ids: NodeId[]) => [...new Set(ids.flatMap((id) => (snap.nodes[id] ? extract(snap.nodes[id].body).flatMap((c) => c.variants) : [])))];
|
||||||
+2
-15
@@ -12,7 +12,7 @@
|
|||||||
* model, as it does when the model writes.
|
* model, as it does when the model writes.
|
||||||
*/
|
*/
|
||||||
import { ownerSection } from "../../src/core/links";
|
import { ownerSection } from "../../src/core/links";
|
||||||
import { ancestors, label, notesOf, sections, topOf, tops, type NodeId, type Snap } from "../../src/core/model";
|
import { ancestors, descendants, label, notesOf, sections, topOf, tops, type NodeId, type Snap } from "../../src/core/model";
|
||||||
import type { Ref } from "../../src/core/ref";
|
import type { Ref } from "../../src/core/ref";
|
||||||
import { clip, plain, sentences } from "../../src/core/text";
|
import { clip, plain, sentences } from "../../src/core/text";
|
||||||
import type { LinkVerdicts, LLM } from "../../src/llm/types";
|
import type { LinkVerdicts, LLM } from "../../src/llm/types";
|
||||||
@@ -159,7 +159,7 @@ export class Reviewer {
|
|||||||
const snap = this.o.snap();
|
const snap = this.o.snap();
|
||||||
const order = new Map<NodeId, number>();
|
const order = new Map<NodeId, number>();
|
||||||
let i = 0;
|
let i = 0;
|
||||||
for (const d of tops(snap)) for (const id of [d, ...descendantsInOrder(snap, d)]) order.set(id, i++);
|
for (const d of tops(snap)) for (const id of [d, ...descendants(snap, d)]) order.set(id, i++);
|
||||||
const sorted = [...list].sort((a, b) => (order.get(a.node) ?? 1e9) - (order.get(b.node) ?? 1e9) || a.range[0] - b.range[0]);
|
const sorted = [...list].sort((a, b) => (order.get(a.node) ?? 1e9) - (order.get(b.node) ?? 1e9) || a.range[0] - b.range[0]);
|
||||||
for (let at = 0; at < sorted.length; at += BATCH) {
|
for (let at = 0; at < sorted.length; at += BATCH) {
|
||||||
if (budget.calls >= budget.max) return { ...report, fallback: `the reviewer's limit of ${budget.max} model call${budget.max === 1 ? "" : "s"} was reached` };
|
if (budget.calls >= budget.max) return { ...report, fallback: `the reviewer's limit of ${budget.max} model call${budget.max === 1 ? "" : "s"} was reached` };
|
||||||
@@ -233,16 +233,3 @@ export class Reviewer {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A node's sections and notes, depth first, in reading order. */
|
|
||||||
function descendantsInOrder(snap: Snap, id: NodeId): NodeId[] {
|
|
||||||
const out: NodeId[] = [];
|
|
||||||
const visit = (x: NodeId) => {
|
|
||||||
for (const c of snap.nodes[x].children) {
|
|
||||||
out.push(c);
|
|
||||||
visit(c);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
visit(id);
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user