- MCP
- blame on this site's /mcp
- CLI
- abso blame worker/project/test/definition-code.test.ts --json
- JSON
- /christopher/abso-core/blame/worker/project/test/definition-code.test.ts?format=json
61 linescodex-capacity-chair 80% · capacity 20%Last change capacity in version 275,
61 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 assert from "node:assert/strict";
2import { test } from "node:test";
3import { buildBase, Graph, View } from "../../../src/engine/index.ts";
4import { SqlState } from "../../../src/engine/test/storage-helper.ts";
5import { withDefinitionCode } from "../definition-code.ts";
6import { definedTwice, definitionsIn } from "../definitions.ts";
7import { codeOfLines } from "../names.ts";
9test("small parsed code stays in memory without scratch writes", (t) => {
10 const storage = new SqlState();
11 t.after(() => storage.db.close());
12 const graph = new Graph({ storage });
13 graph.add(buildBase({ "f.ts": "export const answer = 42;\n" }, { author: "writer", message: "init" }));
14 const view = new View(graph, ["a0"]);
15 const writes = storage.writes;
16 withDefinitionCode(view, view.buildLines("f.ts"), (code) => {
17 assert.deepEqual(code, codeOfLines(["export const answer = 42;"]));
18 });
19 assert.equal(storage.writes, writes);
20});
22test("disk definition code preserves random reads and always rolls scratch back", (t) => {
23 const storage = new SqlState();
24 t.after(() => storage.db.close());
25 const lines = [
26 "/* comment",
27 "end */ export function parseOne(",
28 "arg: string",
29 ") { return 1; }",
30 ...Array.from({ length: 4000 }, (_, i) => `const value${i} = ${i}; // trailing`),
31 ];
32 const atom = buildBase({ "f.ts": `${lines.join("\n")}\n` }, { author: "writer", message: "init" });
33 const memory = new Graph();
34 memory.add(atom);
35 const graph = new Graph({ storage });
36 graph.add(atom);
37 const view = new View(graph, ["a0"]);
38 const expected = codeOfLines(lines);
39 const rows = () => storage.db.prepare("SELECT * FROM state ORDER BY collection,key").all();
40 const before = rows();
41 let escaped: readonly string[] = [];
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.Compare42 withDefinitionCode(
43 view,
44 view.buildLines("f.ts"),
45 (code) => {
46 escaped = code;
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).Compare47 assert.deepEqual(code.slice(0, 4), expected.slice(0, 4));
48 for (let i = code.length - 1; i >= 0; i--) assert.equal(code[i], expected[i]);
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.Compare49 for (let i = 0; i < code.length; i++) assert.equal(code[i], expected[i]);
50 },
51 65536,
52 );
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.Compare53 assert.throws(() => escaped[0], /scope has ended/);
54 assert.deepEqual(rows(), before);
55 assert.deepEqual(definitionsIn(view), definitionsIn(new View(memory, ["a0"])));
56 assert.deepEqual(definedTwice(view, "f.ts"), definedTwice(new View(memory, ["a0"]), "f.ts"));
57 assert.deepEqual(rows(), before);
58 storage.failWrite = storage.writes + 2;
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).Compare59 assert.throws(() => withDefinitionCode(view, view.buildLines("f.ts"), () => [], 65536), /injected storage failure/);
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.Compare60 assert.deepEqual(rows(), before);
61});