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
MCP
show on this site's /mcp
CLI
abso show 274 --json
JSON
/christopher/abso-core/versions/274?format=json

Cold reads (abso Capacity, issue 664): a packed layout reads only the text pages holding a line it shows; definition code stays in memory up to 4 MB; a stored array's element read skips its length read.

of shared·capacity··Not checked

  • Layout: each line's file and place are kept and texts are read after the walk, a page at a time, only for shown lines. Every text a file and the files its moved-in lines came from ever had was read for every layout; abso's worker files, split out of index.ts, each read all of index.ts's history. Cold compare 612 to 1224 on abso read text pages 17,080 times, now 2,856.
  • Definition code: at 64 KB every large file's parsed code went row by row into scratch and back (25,000 rows each for index.ts). The visible lines are already in memory, so 4 MB at most doubles a file's text for the call. withDefinitionCode takes the limit; its scratch test passes 64 KB.
  • storedArray: set writes the row and the length together and nothing shrinks, so no row lies past the length; half of a cold layout's reads were the length.

Side by side on abso's export, same machine, three rounds: cold collisions 10.5 s to 6.2 s, cold compare 12.6 s to 8.6 s. tsc clean; view, state-cache, state-source, graph, graph-long-text, graph-line-chunks, graph-move-write-membership, definition-code, definitions, changed-definition, collisions-kept-views and draft-reads-stored tests: 73 pass.

Version 273 · Files at version 274

5 files, 63 lines added, 13 removed.

--- a/src/engine/graph.ts
+++ b/src/engine/graph.ts
@@ -691,6 +691,13 @@
691691 *packedTexts(file: number): IterableIterator<string | null> {
692692 yield* this.#fileTexts!.values(String(file));
693693 }
694+ /**
695+ * The texts at positions [page * 256, (page + 1) * 256) of packedTexts(file) (abso Capacity): a layout reads only the
696+ * pages holding a line it shows.
697+ */
698+ packedTextPage(file: number, page: number): readonly (string | null)[] {
699+ return this.#fileTexts!.pageAt(String(file), page);
700+ }
694701 *packedDeletes(file: number): IterableIterator<PackedDelete> {
695702 yield* this.#fileDeletes!.values(String(file));
696703 }
--- a/src/engine/state-source.ts
+++ b/src/engine/state-source.ts
@@ -348,7 +348,9 @@
348348 return new Proxy([] as T[], {
349349 get(target, key, receiver) {
350350 if (key === "length") return length();
351− if (indexKey(key)) return Number(key) < length() ? read(key) : undefined;
351+ // No length read first (abso Capacity): set writes the row and the length together and nothing shrinks, so no
352+ // row lies past the length. Half of a cold layout's reads were this length.
353+ if (indexKey(key)) return read(key);
352354 return Reflect.get(target, key, receiver);
353355 },
354356 set(_target, key, value) {
@@ -419,6 +421,14 @@
419421 }
420422 for (const [key] of storage.entries(`${name}:lengths`)) yield key;
421423 },
424+ /** Values [index * PAGE, (index + 1) * PAGE) of `key`'s list: one page, not the whole list (abso Capacity). */
425+ pageAt(key: string, index: number): readonly V[] {
426+ const count = length(key);
427+ const values = page(key, index);
428+ if (values.length !== Math.min(pageSize, count - index * pageSize))
429+ throw new Error(`incomplete writer list page in ${name}`);
430+ return values;
431+ },
422432 *values(key: string): IterableIterator<V> {
423433 const count = length(key);
424434 for (let start = 0; start < count; start += pageSize) {
--- a/src/engine/view.ts
+++ b/src/engine/view.ts
@@ -755,7 +755,11 @@
755755 const relocs = this.#hasMoves ? this.#relocationsN() : undefined;
756756 const files = new Set<number>([-1 - start, ...(this.#movedInFrom().get(path) ?? [])]);
757757 const children = new Map<number, Child[]>();
758− const texts = new Map<number, string | null>();
758+ // Where each line's text is: its file and its place in that file's packed history. Texts are read after the walk,
759+ // only for the lines it shows (abso Capacity): every text a file and its moved-in sources ever had was read for
760+ // every layout, and abso's worker files, split out of index.ts, read all of index.ts's history each.
761+ const textFile = new Map<number, number>();
762+ const textPlace = new Map<number, number>();
759763 const writers = new Map<number, number>();
760764 const places = new Map<number, number>();
761765 const deleters = new Map<number, number[]>();
@@ -770,9 +774,9 @@
770774 return lamport;
771775 };
772776 for (const file of files) {
773− const lineTexts = graph.packedTexts(file);
777+ let place = -1;
774778 for (const [n, parent, seq, k, replaces] of graph.packedLines(file)) {
775− const text = lineTexts.next().value as string | null;
779+ place++;
776780 if (!this.#has(seq)) continue;
777781 const moved = relocs?.get(n);
778782 let at = parent;
@@ -785,7 +789,8 @@
785789 const list = children.get(at);
786790 if (list) list.push(child);
787791 else children.set(at, [child]);
788− texts.set(n, text);
792+ textFile.set(n, file);
793+ textPlace.set(n, place);
789794 writers.set(n, seq);
790795 places.set(n, k);
791796 }
@@ -796,7 +801,7 @@
796801 else deleters.set(n, [deleter]);
797802 }
798803 // Runs written elsewhere under this file's lines follow them; the loop reads their files too.
799− for (const [parent, into] of graph.packedCrossings(file)) if (texts.has(parent)) files.add(into);
804+ for (const [parent, into] of graph.packedCrossings(file)) if (writers.has(parent)) files.add(into);
800805 }
801806 const order = (a: Child, b: Child) =>
802807 b.replaces - a.replaces || b.lamport - a.lamport || b.seq - a.seq || a.k - b.k;
@@ -809,6 +814,18 @@
809814 const seqWriter: number[] = [];
810815 const seqK: number[] = [];
811816 const deletedBy = new Map<number, readonly number[]>();
817+ // The text pages read for this layout, by file and page: each at most once.
818+ const pages = new Map<number, Map<number, readonly (string | null)[]>>();
819+ const textOf = (n: number): string | null => {
820+ const file = textFile.get(n)!;
821+ const place = textPlace.get(n)!;
822+ const page = Math.floor(place / 256);
823+ let byPage = pages.get(file);
824+ if (!byPage) pages.set(file, (byPage = new Map()));
825+ let texts = byPage.get(page);
826+ if (!texts) byPage.set(page, (texts = graph.packedTextPage(file, page)));
827+ return texts[place % 256] ?? null;
828+ };
812829 const stack: number[] = [];
813830 const push = (code: number) => {
814831 const list = children.get(code);
@@ -824,7 +841,7 @@
824841 if (complete) deletedBy.set(seq.length, by.length > 1 ? by.sort(priority) : by);
825842 } else {
826843 vis.push(n);
827− visText.push(texts.get(n) ?? null);
844+ visText.push(textOf(n));
828845 visWriter.push(writers.get(n)!);
829846 visK.push(places.get(n)!);
830847 }
--- a/worker/project/definition-code.ts
+++ b/worker/project/definition-code.ts
@@ -2,11 +2,19 @@
22import { StoredText } from "../../src/engine/stored-text.ts";
33import { eachCodeLine } from "./names.ts";
44
5+/**
6+ * Characters of parsed code kept in memory before the rest goes to scratch (abso Capacity). The visible lines it is
7+ * parsed from are already in memory, so this at most doubles a file's text for the call; at 64 KB, every large file's
8+ * code went row by row into scratch and back, 25,000 rows each for abso's index.ts, a third of a cold collisions call.
9+ */
10+export const DEFINITION_CODE_IN_MEMORY = 4_000_000;
512/** Parsed code is temporary derived data, discarded with the scratch transaction. */
613export function withDefinitionCode<T>(
714 view: ReadView,
815 visible: readonly VisibleLine[],
916 operation: (code: readonly string[]) => T,
17+ inMemory = DEFINITION_CODE_IN_MEMORY,
1018): T {
1119 function* source() {
1220 for (const line of visible) yield line.text;
@@ -16,7 +24,7 @@
1624 let prefix: string[] = [];
1725 let size = 0;
1826 let pending = iterator.next();
19− while (!pending.done && size + pending.value.length + 1 <= 65536) {
27+ while (!pending.done && size + pending.value.length + 1 <= inMemory) {
2028 prefix.push(pending.value);
2129 size += pending.value.length + 1;
2230 pending = iterator.next();
--- a/worker/project/test/definition-code.test.ts
+++ b/worker/project/test/definition-code.test.ts
@@ -39,18 +39,26 @@
3939 const rows = () => storage.db.prepare("SELECT * FROM state ORDER BY collection,key").all();
4040 const before = rows();
4141 let escaped: readonly string[] = [];
42− withDefinitionCode(view, view.buildLines("f.ts"), (code) => {
43− escaped = code;
42+ withDefinitionCode(
43+ view,
44+ view.buildLines("f.ts"),
45+ (code) => {
46+ escaped = code;
4447 assert.deepEqual(code.slice(0, 4), expected.slice(0, 4));
4548 for (let i = code.length - 1; i >= 0; i--) assert.equal(code[i], expected[i]);
46− for (let i = 0; i < code.length; i++) assert.equal(code[i], expected[i]);
47− });
49+ for (let i = 0; i < code.length; i++) assert.equal(code[i], expected[i]);
50+ },
51+ 65536,
52+ );
4853 assert.throws(() => escaped[0], /scope has ended/);
4954 assert.deepEqual(rows(), before);
5055 assert.deepEqual(definitionsIn(view), definitionsIn(new View(memory, ["a0"])));
5156 assert.deepEqual(definedTwice(view, "f.ts"), definedTwice(new View(memory, ["a0"]), "f.ts"));
5257 assert.deepEqual(rows(), before);
5358 storage.failWrite = storage.writes + 2;
54− assert.throws(() => withDefinitionCode(view, view.buildLines("f.ts"), () => []), /injected storage failure/);
59+ assert.throws(
60+ () => withDefinitionCode(view, view.buildLines("f.ts"), () => [], 65536),
61+ /injected storage failure/,
62+ );
5563 assert.deepEqual(rows(), before);
5664});