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
blame on this site's /mcp
CLI
abso blame worker/project/definition-code.ts --json
JSON
/christopher/abso-core/blame/worker/project/definition-code.ts?format=json
90 linescodex-capacity-chair 77% · capacity 23%Last change capacity in version 275,

90 lines from 3 changes in 3 versions.

codex-capacity-chair175Reduce disk-backed record and publish allocations; reviewed in core ask 52 with parsed-code budget and exact aligned-line follow-ups. Keep disk-first activation off.Compare1import type { ReadView, VisibleLine } from "../../src/engine/index.ts";
2import { StoredText } from "../../src/engine/stored-text.ts";
3import { eachCodeLine } from "./names.ts";
4
capacity274Cold 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. - 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.Compare5/**
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 */
10export const DEFINITION_CODE_IN_MEMORY = 4_000_000;
capacity275Definition code: setDefinitionCodeInMemory for tests (abso's kept-reader test puts a 100 KB file through scratch, as before the 4 MB limit), and 274's test formatted as Biome wants (274's check failed on it).Compare12let inMemoryLimit = DEFINITION_CODE_IN_MEMORY;
14/**
15 * Tests only: the in-memory limit for every later call, so a small file takes the scratch path (abso's kept-reader
16 * test checks scratch is let go). Answers the limit it replaces, to put back.
17 */
18export function setDefinitionCodeInMemory(limit: number): number {
19 const before = inMemoryLimit;
20 inMemoryLimit = limit;
21 return before;
codex-capacity-chair175Reduce disk-backed record and publish allocations; reviewed in core ask 52 with parsed-code budget and exact aligned-line follow-ups. Keep disk-first activation off.Compare24/** Parsed code is temporary derived data, discarded with the scratch transaction. */
25export function withDefinitionCode<T>(
26 view: ReadView,
27 visible: readonly VisibleLine[],
28 operation: (code: readonly string[]) => T,
capacity275Definition code: setDefinitionCodeInMemory for tests (abso's kept-reader test puts a 100 KB file through scratch, as before the 4 MB limit), and 274's test formatted as Biome wants (274's check failed on it).Compare29 inMemory = inMemoryLimit,
codex-capacity-chair175Reduce disk-backed record and publish allocations; reviewed in core ask 52 with parsed-code budget and exact aligned-line follow-ups. Keep disk-first activation off.Compare30): T {
31 function* source() {
32 for (const line of visible) yield line.text;
33 }
34 if (!view.graph.hasOrderedChildren) return operation([...eachCodeLine(source())]);
35 const iterator = eachCodeLine(source());
36 let prefix: string[] = [];
37 let size = 0;
38 let pending = iterator.next();
capacity274Cold 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. - 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.Compare39 while (!pending.done && size + pending.value.length + 1 <= inMemory) {
codex-capacity-chair175Reduce disk-backed record and publish allocations; reviewed in core ask 52 with parsed-code budget and exact aligned-line follow-ups. Keep disk-first activation off.Compare40 prefix.push(pending.value);
41 size += pending.value.length + 1;
42 pending = iterator.next();
43 }
44 if (pending.done) return operation(prefix);
45 return view.graph.withProjectionScratch((storage) => {
46 const text = new StoredText(storage, "definition-code");
47 let count = 0;
48 for (const line of prefix) text.write(String(count++), line);
49 prefix = [];
50 text.write(String(count++), pending.value!);
51 for (const line of iterator) text.write(String(count++), line);
52 const cache = new Map<number, string>();
53 let characters = 0;
54 const read = (index: number) => {
55 if (index < 0 || index >= count) return undefined;
56 const cached = cache.get(index);
57 if (cached !== undefined) return cached;
58 const value = text.read(String(index));
59 if (value.length <= 65536) {
60 while (cache.size >= 64 || characters + value.length > 65536) {
61 const first = cache.keys().next().value!;
62 characters -= cache.get(first)!.length;
63 cache.delete(first);
64 }
65 cache.set(index, value);
66 characters += value.length;
67 }
68 return value;
69 };
70 let active = true;
71 const code = new Proxy([] as string[], {
72 has(target, key) {
73 if (!active) throw Error("definition code scope has ended");
74 if (typeof key === "string" && /^(0|[1-9][0-9]*)$/.test(key)) return Number(key) < count;
75 return Reflect.has(target, key);
76 },
77 get(target, key, receiver) {
78 if (!active) throw Error("definition code scope has ended");
79 if (key === "length") return count;
80 if (typeof key === "string" && /^(0|[1-9][0-9]*)$/.test(key)) return read(Number(key));
81 return Reflect.get(target, key, receiver);
82 },
83 });
84 try {
85 return operation(code);
86 } finally {
87 active = false;
88 }
89 });