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 247 --json
JSON
/christopher/abso-core/versions/247?format=json

A kept reader settles after each read; line texts weigh what V8 holds (abso Capacity, issue 664).

of shared·capacity··Not checked

What a kept reader held on abso, measured per question without the answer itself (heap snapshot after tree with authors, 56.9 MB held): the view cache 38.3 MB against its 24 MB budget, the agents read 6.5 to 7.7 MB, the move skeleton 2.4 MB, the state cache 2.3 MB; the rest is the engine's indexes.

  • Project.afterRead: the view cache trimmed to its budget (ViewCache.trim) and the agents the read decoded let go (WriterAgents.release). Views grow while a call lays files out and the cache weighed them only when asked for again; a read-only reader never flushed its agents, so it held every agent's news told.
  • View weight: a laid-out line's text counts a 16-byte header and a byte a character (two outside Latin-1), rounded to 8, as V8 holds it. It counted 8 and two a character, so abso's whole shared layout (22.7 MB held) weighed about 28 MB, over the budget alone: once trimmed, it was laid out again for every question (blame folder 2.5 s became 14.4 s).

Full warm run on the abso export: held heap at most 41.7 MB (was 56.9), 24 to 29 MB between the big reads (was 32 to 37); every answer the same. Status and drafts take about 30 ms more (agents read again); blame folder 1.7 s instead of 2.5 s.

Tests: view-cache (trim reweighs growth with no further hit), after-read (new: reads before and after it, and a write after it, against the in-memory project), and the collision, path and compare tests: 21 of 21.

Version 246 · Files at version 247

6 files, 105 lines added, 1 removed.

--- a/src/engine/view.ts
+++ b/src/engine/view.ts
@@ -74,7 +74,7 @@
7474 // FileState and FileAttrs are per laid-out file; typed-array headers are separate from their payload byte lengths.
7575 n = OBJECT_BYTES + OBJECT_BYTES + 2 * ARRAY_HEADER_BYTES;
7676 n += f.seq.byteLength + f.vis.byteLength;
77− if (f.visText) for (const text of f.visText) n += REFERENCE_BYTES + 2 * (text?.length ?? 0);
77+ if (f.visText) for (const text of f.visText) n += REFERENCE_BYTES + (text === null ? 0 : stringBytes(text));
7878 if (f.visWriter) n += 4 * f.visWriter.length;
7979 if (f.visK) n += 4 * f.visK.length;
8080 if (f.seqWriter) n += 4 * f.seqWriter.length;
@@ -131,7 +131,16 @@
131131const MAP_ENTRY_BYTES = 40;
132132const SET_ENTRY_BYTES = 32;
133133const REFERENCE_BYTES = 8;
134+const STRING_HEADER_BYTES = 16;
134135/**
136+ * What V8 holds for a string of its own (abso Capacity, measured on abso's layouts): a header, then one byte a
137+ * character when every character fits in Latin-1 and two otherwise, rounded up to 8.
138+ */
139+function stringBytes(text: string): number {
140+ const chars = /[^\u0000-\u00ff]/.test(text) ? 2 * text.length : text.length;
141+ return (STRING_HEADER_BYTES + chars + 7) & ~7;
142+}
143+/**
135144 * Moved lines a view resolves once and keeps (abso Capacity): a stored graph otherwise resolved every move again on
136145 * disk for each file it laid out. Game's whole history has 290; past this many, the view goes back to that.
137146 */
--- a/worker/project/project.ts
+++ b/worker/project/project.ts
@@ -2811,6 +2811,17 @@
28112811 return this.#viewAt(this.#shared, last(this.#shared));
28122812 }
28132813
2814+ /**
2815+ * After each read of a reader kept between calls, one that changed nothing (abso Capacity): the cached views back
2816+ * under their budget, since views grow while a call lays files out and the cache weighs them only when they are
2817+ * asked for again (on abso, a tree with authors left 38 MB of views held against the 24 MB budget), and the agents
2818+ * the read decoded let go, read again from storage by the next call (7 MB on abso, every agent's news told).
2819+ */
2820+ afterRead(): void {
2821+ this.#views.trim();
2822+ if (this.#agents instanceof WriterAgents) this.#agents.release();
2823+ }
28142825 /** A view of a set, cached by the set's exact contents (views.ts). */
28152826 #view(set: ReadonlySet<AtomId>): ReadView {
28162827 this.#views.assertUnkeyedAllowed();
--- /dev/null
+++ b/worker/project/test/after-read.test.ts
@@ -0,0 +1,57 @@
1+// A reader kept between calls settles after each read (abso Capacity, Project.afterRead): the cached views trimmed
2+// to their budget and the agents it decoded let go. The next reads must answer as before, from storage, and a
3+// write after it must still see every agent as stored.
4+
5+import assert from "node:assert/strict";
6+import { test } from "node:test";
7+import { storedArray } from "../../../src/engine/state-source.ts";
8+import { SqlState } from "../../../src/engine/test/storage-helper.ts";
9+import { MemoryStore, Project } from "../project.ts";
10+import type { Entry, ProjectStore } from "../project-types.ts";
12+function writer() {
13+ const storage = new SqlState();
14+ const entries = storedArray<Entry>(storage, "canonical-log");
15+ const store: ProjectStore = {
16+ append(batch) {
17+ for (const entry of batch) entries.push(entry);
18+ },
19+ };
20+ return new Project(store, { writerStorage: storage });
21+}
23+const SHAPES = "export function area(r: number) {\n return 3.14 * r * r;\n}\n";
24+const IMPORT = 'import { area } from "./shapes";\n';
26+function history(project: Project) {
27+ project.init({ "src/shapes.ts": SHAPES, "src/main.ts": IMPORT, "notes.md": "notes\n" }, 0);
28+ project.edit("ann", { file: "src/shapes.ts", old: "area(r: number)", new: "area(r: number, scale = 1)" }, 1);
29+ project.record("bob", { "src/main.ts": `${IMPORT}export const a = area(2);\n` }, 2);
30+ project.record("cy", { "notes.md": "notes\nmore\n" }, 3);
31+}
33+const reads = (project: Project) => ({
34+ status: project.status(),
35+ collisions: project.collisions(),
36+ tree: project.tree("", { authors: true }),
37+ bob: project.draftOf("bob")!.view.text("src/main.ts"),
38+});
40+test("reads after afterRead answer as before it, and a write after it sees every agent", () => {
41+ const oracle = new Project(new MemoryStore());
42+ const project = writer();
43+ history(oracle);
44+ history(project);
45+ const expected = reads(oracle);
46+ assert.deepEqual(reads(project), expected);
47+ project.afterRead();
48+ assert.deepEqual(reads(project), expected, "after afterRead");
49+ project.afterRead();
50+ oracle.afterRead();
51+ for (const p of [oracle, project]) {
52+ p.record("cy", { "notes.md": "notes\nmore\nand more\n" }, 4);
53+ assert.equal(p.publish("ann", "Add a scale", 5).ok, true);
54+ }
55+ assert.deepEqual(reads(project), reads(oracle), "a write after afterRead");
56+ assert.ok(expected.collisions.collisions.some((c) => c.kind === "definition"));
57+});
--- a/worker/project/test/view-cache.test.ts
+++ b/worker/project/test/view-cache.test.ts
@@ -103,6 +103,20 @@
103103 });
104104});
105105
106+test("trim reweighs growth with no further hit and evicts until the views fit (abso Capacity)", () => {
107+ withControlledWeights((control) => {
108+ const cache = new ViewCache(new Graph());
109+ control.setIncomingWeights([10_000_000, 10_000_000]);
110+ const growing = get(cache, "growing");
111+ const newer = get(cache, "newer");
112+ // A call lays files out in the older view after the cache last weighed it, and nothing asks for it again.
113+ control.setWeight(growing, 16_000_000);
114+ cache.trim();
115+ assert.equal(get(cache, "newer"), newer);
116+ assert.notEqual(get(cache, "growing"), growing);
117+ });
118+});
106120test("an oversized view is returned but not retained", () => {
107121 withControlledWeights((control) => {
108122 const cache = new ViewCache(new Graph());
--- a/worker/project/views.ts
+++ b/worker/project/views.ts
@@ -39,6 +39,14 @@
3939 }
4040
4141 /**
42+ * Weigh every cached view again and evict until they fit (abso Capacity): views grow while a call lays files out,
43+ * and #get weighs a view only when it is asked for again. A kept reader trims after each call.
44+ */
45+ trim(): void {
46+ this.#trim();
47+ }
49+ /**
4250 * Keep the cached views under VIEW_BUDGET bytes (the website project, #43,
4351 * #46): each view holds every line its files ever had, so a few views of a
4452 * large generated file add up. At most VIEW_COUNT.
--- a/worker/project/writer-agents.ts
+++ b/worker/project/writer-agents.ts
@@ -47,6 +47,11 @@
4747 yield [key, value];
4848 }
4949 }
50+ /** Let go of the agents read, when nothing changed them: a reader kept between calls (abso Capacity). */
51+ release(): void {
52+ this.#touched.clear();
53+ }
5055 flush(): void {
5156 for (const [key, value] of this.#touched) super.set(key, value);
5257 this.#touched.clear();