Lines 2–8 at 212 (were 2–8 at 211)
22// is the project in memory. 44import { type AtomId, type Graph, parseKey, type ReadView } from "../../src/engine/index.ts"; 5−import { describeSide, fileOfKey, type Pair } from "./collisions.ts";
5+import { claimantsAmong, describeSide, fileOfKey, pairsFrom } from "./collisions.ts"; 66import type { DefinitionRule } from "./definition-rule.ts"; 77import { type Definition, definedTwice } from "./definitions.ts"; 88import { pathKey } from "./pathkey.ts"; Lines 25–30 at 212 (were 25–31 at 211)
2525 draft(agent: Agent): AtomId[]; 2626 agentView(agent: Agent): ReadView; 2727 view(set: ReadonlySet<AtomId>): ReadView; 28− pairs(draft: readonly AtomId[], against: ReadonlySet<AtomId>, settled: ReadonlySet<AtomId>): Pair[];
2928 touchedFiles(ids: Iterable<AtomId>, views: readonly ReadView[]): Set<string>; Lines 53–90 at 212 (were 54–59 at 211)
5453 const sharedView = host.sharedView(); 5554 const out: DraftCollision[] = []; 5655 const side = (agent: string, file: string, s: CollisionSide) => ({ agent, file, lines: s.lines, text: s.text }); 56+ // Every draft change's claimants among all the drafts, found once (abso Capacity): a stored atom's keys are read 57+ // from disk, and a draft deleting a big file has thousands, read again for every other agent. 58+ let claimants: ReadonlyMap<AtomId, readonly AtomId[]> | undefined; 59+ const claimantsOf = (agent: Agent): ReadonlyMap<AtomId, readonly AtomId[]> => { 60+ claimants ??= claimantsAmong( 62+ working.flatMap((a) => host.draft(a)), 64+ const all = claimants; 65+ return new Map(host.draft(agent).map((id) => [id, all.get(id) ?? []])); 67+ // One set per draft, so the definition rule keeps what it worked out about it (abso Capacity). 68+ const draftSets = new Map<Agent, ReadonlySet<AtomId>>(); 69+ const draftSet = (agent: Agent) => { 70+ let set = draftSets.get(agent); 71+ if (!set) draftSets.set(agent, (set = new Set(host.draft(agent)))); 74+ // Shared now with each agent's draft on top, once per agent: the key of a view of a set lists every atom in it. 75+ const nowViews = new Map<Agent, ReadView>(); 76+ const nowViewOf = (agent: Agent) => { 77+ let view = nowViews.get(agent); 78+ if (!view) nowViews.set(agent, (view = host.view(new Set([...shared, ...host.draft(agent)])))); 81+ // Each agent's touched files once, not once per pair (abso Capacity). 82+ const touched = new Map<Agent, Set<string>>(); 83+ const touchedBy = (agent: Agent) => { 84+ let files = touched.get(agent); 85+ if (!files) touched.set(agent, (files = host.touchedFiles(host.draft(agent), [host.agentView(agent)]))); 5788 for (let i = 0; i < working.length; i++) { 5889 for (let j = 0; j < working.length; j++) { 5990 if (i === j) continue; Lines 92–105 at 212 (were 61–74 at 211)
6192 const b = working[j]!; 6293 const draftA = host.draft(a); 6394 const draftB = host.draft(b); 64− const newer = new Set(draftA);
95+ const newer = draftSet(a); 6596 const union = new Set([...shared, ...draftA, ...draftB]); 6697 const viewA = host.agentView(a); 6798 const viewB = host.agentView(b); 69100 // Lines and attributes: the same either way round, so once per pair. 70101 const paired = new Set<string>(); 71− for (const pair of host.pairs(draftB, newer, union)) {
102+ for (const pair of pairsFrom(host.graph, claimantsOf(b), newer, union)) { 72103 paired.add(`${pair.theirs} ${pair.yours}`); 73104 const file = fileOfKey(pair.keys[0]!.key, viewB); 74105 const fileKeys = pair.keys.filter((k) => fileOfKey(k.key, viewB) === file).map((k) => k.key); Lines 127–140 at 212 (were 96–106 at 211)
97128 // A name both define at the top level of one file: what the second meets once it syncs onto the 98129 // first's work, as the publish rule checks it then. Not when the two definitions are one lines collision. 99− const both = host.view(union);
130+ // The union's view only when the two share a file (abso Capacity): laying out shared plus both drafts 131+ // cost a few seconds a pair on a stored writer. 132+ let both: ReadView | undefined; 100133 const mineA = new Set(draftA); 101134 const mineB = new Set(draftB); 102− const filesA = host.touchedFiles(draftA, [viewA]);
103− for (const file of [...host.touchedFiles(draftB, [viewB])].filter((f) => filesA.has(f)).toSorted()) {
135+ const filesA = touchedBy(a); 136+ for (const file of [...touchedBy(b)].filter((f) => filesA.has(f)).toSorted()) { 137+ both ??= host.view(union); 104138 if (!both.hasFile(file)) continue; 105139 for (const [name, defs] of definedTwice(both, file)) { 106140 const by = (mine: Set<AtomId>) => defs.find((d) => d.lines.some((l) => mine.has(host.graph.line(l)!.atom))); Lines 155–162 at 212 (were 121–128 at 211)
123157 // Definitions: b's new lines use a name whose definition a's changes change. 124− const nowView = host.view(new Set([...shared, ...draftA]));
125− for (const d of host.definitionRule().collisions(new Set(draftB), viewB, sharedView, nowView, newer, SHARED)) {
158+ const nowView = () => nowViewOf(a); 159+ for (const d of host.definitionRule().collisions(draftSet(b), viewB, sharedView, nowView, newer, SHARED)) { 126160 const c = d.collision; 128162 kind: "definition",