Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed

Versions 307 to 318

Compare

+72 −62 in 8 places
Lines 1524–1562 at 318 (were 1524–1566 at 307)
15241524 * the search never descends below the target's lamport.
15251525 */
15261526 #reaches(from: Iterable<AtomId>, target: AtomId): boolean {
1527− const floor = this.#lamportAt(this.#seq(target));
1528− if (this.#storage) {
1529− return this.withProjectionScratch((scratch) => {
1530− let length = 0;
1531− const push = (id: AtomId): void => {
1532− if (scratch.read("seen", id)) return;
1533− scratch.write("seen", id, true);
1534− scratch.write("stack", String(length++), id);
1535− };
1536− for (const id of from) {
1537− if (id === target) return true;
1538− if (this.#lamportAt(this.#seq(id)) > floor) push(id);
1539− }
1540− while (length > 0) {
1541− const key = String(--length);
1542− const current = scratch.read("stack", key) as AtomId;
1543− scratch.remove("stack", key);
1544− if (this.#lamportAt(this.#seq(current)) <= floor) continue;
1545− for (const dependency of this.atom(current).deps) {
1546− if (dependency === target) return true;
1547− push(dependency);
1548− }
1549− }
1550− return false;
1551− });
1527+ return this.#reachable(from, new Set([target])).has(target);
1528+ }
1530+ /**
1531+ * Which of `targets` are reachable along deps from any of `from` (themselves included), in one walk: it never
1532+ * descends below the lowest target's lamport, and stops once every target is found (abso 714, piece 4: record
1533+ * walked once per line writer).
1534+ * The walk's seen marks and stack are in memory, by atom number: one byte and four bytes an atom at most, so about
1535+ * 62 KB on abso's 12,454 atoms and 50 MB at 10 million, under a Worker's 128 MB. They were scratch rows in storage
1536+ * (abso-core 139, bounding memory with the graph), which cost a read and a write per atom visited: on abso's Oct 14
1537+ * tables, 41,000 of a 1470-shaped record's 77,767 statements.
1538+ */
1539+ #reachable(from: Iterable<AtomId>, targets: ReadonlySet<AtomId>): Set<AtomId> {
1540+ const found = new Set<AtomId>();
1541+ let floor = Number.POSITIVE_INFINITY;
1542+ for (const target of targets) floor = Math.min(floor, this.#lamportAt(this.#seq(target)));
1543+ const seen = new Uint8Array(this.#atoms.length);
1544+ const stack = new Int32Array(this.#atoms.length);
1545+ let length = 0;
1546+ const visit = (id: AtomId): void => {
1547+ if (targets.has(id)) found.add(id);
1548+ const seq = this.#seq(id);
1549+ if (seen[seq]) return;
1550+ seen[seq] = 1;
1551+ stack[length++] = seq;
1552+ };
1553+ for (const id of from) visit(id);
1554+ while (length > 0 && found.size < targets.size) {
1555+ const seq = stack[--length]!;
1556+ if (this.#lamportAt(seq) <= floor) continue;
1557+ for (const dependency of this.atom(atomId(seq)).deps) visit(dependency);
15521558 }
1553− const seen = new Set<AtomId>();
1554− const stack = [...from];
1555− while (stack.length > 0) {
1556− const cur = stack.pop()!;
1557− if (cur === target) return true;
1558− if (seen.has(cur)) continue;
1559− seen.add(cur);
1560− if (this.#lamportAt(this.#seq(cur)) <= floor) continue;
1561− for (const d of this.atom(cur).deps) if (!seen.has(d)) stack.push(d);
1562− }
1563− return false;
1559+ return found;
15641560 }
15651561
15661562 /**
Lines 1606–1633 at 318 (were 1610–1632 at 307)
16101606 for (const r of atom.reasons) if (!this.has(r.to)) bad(`reason points at unknown atom ${r.to}`);
16111607
16121608 // Everything it touches must come from its closure. Derived deps name the
1613− // writers directly, so this is usually one lookup per writer.
1614− const memoryBelow = scratch ? undefined : new Map<AtomId, boolean>();
1615− const below = {
1616− get: (key: AtomId) => (scratch ? (scratch.read("below", key) as boolean | undefined) : memoryBelow!.get(key)),
1617− set: (key: AtomId, value: boolean) => {
1618− if (scratch) scratch.write("below", key, value);
1619− else memoryBelow!.set(key, value);
1620− },
1621− };
1622− const inClosure = (writer: AtomId): boolean => {
1623− let hit = below.get(writer);
1624− if (hit === undefined) {
1625− hit = deps.has(writer) || this.#reaches(atom.deps, writer);
1626− below.set(writer, hit);
1609+ // writers directly, so this is usually one lookup per writer. The writers
1610+ // that aren't deps are walked for together, once (abso 714, piece 4).
1611+ const touched: LineId[] = [];
1612+ for (const run of atom.inserts) if (!isStartNode(run.parent)) touched.push(run.parent);
1613+ for (const m of atom.moves ?? []) {
1614+ touched.push(m.line);
1615+ if (!isStartNode(m.parent)) touched.push(m.parent);
1616+ }
1617+ touched.push(...atom.deletes);
1618+ for (const list of [atom.writes, atom.reads, atom.holds])
1619+ for (const key of list) {
1620+ const parsed = parseKey(key);
1621+ if (parsed.kind === "line" || ((parsed.kind === "gap" || parsed.kind === "pos") && !isStartNode(parsed.node)))
1622+ touched.push(parsed.node);
16271623 }
1628− return hit;
1629− };
1624+ const beyond = new Set<AtomId>();
1625+ for (const line of touched) {
1626+ const writer = this.lineAtom(line);
1627+ if (writer !== undefined && !deps.has(writer)) beyond.add(writer);
1628+ }
1629+ const reached = beyond.size > 0 ? this.#reachable(atom.deps, beyond) : beyond;
1630+ const inClosure = (writer: AtomId): boolean => deps.has(writer) || reached.has(writer);
16301631 const checkLine = (line: LineId, what: string): void => {
16311632 const writer = this.lineAtom(line);
16321633 if (writer === undefined) return bad(`${what} names unknown line ${line}`);
Lines 10–16 at 318 (were 10–16 at 307)
1010// made when a caller asks for them, and the latest asked for is kept.
1111
1212import type { Graph, RelocationInfo } from "./graph.ts";
13−import { isStartNode, lineId, seqOf } from "./keys.ts";
13+import { atomId, isStartNode, lineId, seqOf } from "./keys.ts";
1414import { resolveScratchMoves, scratchLayoutNodes } from "./relocation-scratch.ts";
1515import { isClosedSet, StableSet } from "./state-source.ts";
1616import { joinLines } from "./text.ts";
Lines 1095–1108 at 318 (were 1095–1101 at 307)
10951095 }
10961096
10971097 *lineChunks(path: string): IterableIterator<() => Iterable<string>> {
1098− for (const n of this.#file(path).vis) yield () => this.graph.textChunks(n);
1098+ // The texts the packed layout already holds, read a page at a time (abso Capacity, 714): a record's diff read each
1099+ // line's own row, 11,873 statements for abso's index.ts. Only a line too long to pack is read in chunks.
1100+ const { vis, visText } = this.#file(path);
1101+ for (let i = 0; i < vis.length; i++) {
1102+ const packed = visText?.[i];
1103+ if (packed != null) yield () => [packed];
1104+ else yield () => this.graph.textChunks(vis[i]!);
1105+ }
10991106 }
11001107
11011108 /** Visible lines without retaining their text in the view cache. */
Lines 1112–1118 at 318 (were 1105–1111 at 307)
11051112 yield {
11061113 id: graph.lineIdOf(n),
11071114 text: graph.textOf(n),
1108− atom: graph.idOfSeq(graph.writerSeqOf(n)),
1115+ atom: atomId(graph.writerSeqOf(n)),
11091116 };
11101117 }
11111118
Lines 1126–1137 at 318 (were 1119–1130 at 307)
11191126 const n = vis[i]!;
11201127 const packed = visText?.[i];
11211128 lines[i] = {
1122− id: visWriter && visK ? lineId(graph.idOfSeq(visWriter[i]!), visK[i]!) : graph.lineIdOf(n),
1129+ id: visWriter && visK ? lineId(atomId(visWriter[i]!), visK[i]!) : graph.lineIdOf(n),
11231130 textChunks: () => graph.textChunks(n),
11241131 get text() {
11251132 return packed ?? graph.textOf(n);
11261133 },
1127− atom: graph.idOfSeq(visWriter ? visWriter[i]! : graph.writerSeqOf(n)),
1134+ atom: atomId(visWriter ? visWriter[i]! : graph.writerSeqOf(n)),
11281135 };
11291136 }
11301137 return lines;
Lines 1143–1156 at 318 (were 1136–1147 at 307)
11361143 const graph = this.graph;
11371144 const { vis, visText, visWriter, visK } = this.#file(path);
11381145 const lines: VisibleLine[] = new Array(vis.length);
1146+ // Writer seqs come from the graph's own layout, so they're named with atomId, not checked by idOfSeq (abso 738):
1147+ // on a stored graph its check read the atom count once a line, about 0.9 s of a warm draft-state on abso.
11391148 for (let i = 0; i < vis.length; i++) {
11401149 const n = vis[i]!;
11411150 lines[i] = {
1142− id: visWriter && visK ? lineId(graph.idOfSeq(visWriter[i]!), visK[i]!) : graph.lineIdOf(n),
1151+ id: visWriter && visK ? lineId(atomId(visWriter[i]!), visK[i]!) : graph.lineIdOf(n),
11431152 text: visText?.[i] ?? graph.textOf(n),
1144− atom: graph.idOfSeq(visWriter ? visWriter[i]! : graph.writerSeqOf(n)),
1153+ atom: atomId(visWriter ? visWriter[i]! : graph.writerSeqOf(n)),
11451154 };
11461155 }
11471156 this.#linesCache = { path, lines };
Lines 1172–1184 at 318 (were 1163–1175 at 307)
11631172 const writer = seqWriter ? seqWriter[i]! : graph.writerSeqOf(n);
11641173 let text: string | undefined;
11651174 out[i] = {
1166− id: seqWriter && seqK ? lineId(graph.idOfSeq(writer), seqK[i]!) : graph.lineIdOf(n),
1175+ id: seqWriter && seqK ? lineId(atomId(writer), seqK[i]!) : graph.lineIdOf(n),
11671176 get text() {
11681177 text ??= graph.textOf(n);
11691178 return text;
11701179 },
1171− atom: graph.idOfSeq(writer),
1172− deletedBy: by ? by.map((s) => graph.idOfSeq(s)) : NONE,
1180+ atom: atomId(writer),
1181+ deletedBy: by ? by.map((s) => atomId(s)) : NONE,
11731182 visible: by === undefined,
11741183 };
11751184 }
MCP
compare on this site's /mcp
CLI
abso diff 307 318 src --json
JSON
/christopher/abso-core/compare/307..318?file=src&format=json