- MCP
- blame on this site's /mcp
- CLI
- abso blame worker/project/kept-parts.ts --version 314 --json
- JSON
- /christopher/abso-core/blame/worker/project/kept-parts.ts?version=314&format=json
109 linescapacity 100%Last change capacity in version 314,
109 lines from 3 changes in 2 versions.
capacity249Collisions step 3: each draft's definition work kept between calls, under a hard 4 MB budget (abso Capacity, issue 664).
KeptParts (kept-parts.ts) holds what draft collisions work out about each draft and each pair of drafts: the names a draft's new lines use, the definitions a draft's changes touch before and after (the changed-definition rule), and the names two drafts both define in a file. Each entry is weighed as the view cache weighs views (line ids, texts, names: view.ts's stringBytes) and the whole stays under 4 MB, oldest out first; an entry over the budget isn't kept. Keys name everything an entry depends on: shared's version, the draft's base and its atoms. Each collisions call drops every entry it didn't use, so a draft that changes, an agent that leaves or shared moving on drops theirs at once. On a stored writer only; the publish check (land.ts) and the in-memory project work as before.
On the abso export (my machine): a warm collisions call takes 322 ms instead of 3.4 s, with the same answer as replay. A full warm run's held heap is at most 42.9 MB (41.7 MB without it), and all 33 answers match.
Tests: kept-parts (new: the budget, oldest out first, an oversized entry never kept, a round dropping what it didn't use) and collisions-kept-views, which now runs through the kept parts on the writer (a draft changing, shared moving on, a draft dropped, each asked twice against the in-memory project). With the collision, definition, path and view tests: 47 of 47.Compare1// What draft collisions work out about each draft and each pair of drafts, kept between calls under a hard byte budget
capacity314Definition rule: lay out only the touched files the draft's uses reach (abso 738). The rule found changed definitions by laying out every file the newer work touched, in two views; for codex-prose-authorship-610 that was 494 files a view where its uses reach 7. It now works out which files the uses mean first and lays out only the touched ones among them. Same answers: the rule already ignored untouched files. Draft collisions keep each file's definitions, and the touched files, under the newer work's key.Compare2// (abso Capacity, issue 664): the names a draft's new lines use, the files a draft's changes touch and the definitions
3// in each before and after, and the names a pair of drafts both define in a file. Keys name everything an entry depends
4// on (shared's version, a draft's base and atoms), and a call drops every entry it didn't use, so a draft that changes,
5// an agent that leaves and shared moving on all drop theirs at once.
capacity249Collisions step 3: each draft's definition work kept between calls, under a hard 4 MB budget (abso Capacity, issue 664).
KeptParts (kept-parts.ts) holds what draft collisions work out about each draft and each pair of drafts: the names a draft's new lines use, the definitions a draft's changes touch before and after (the changed-definition rule), and the names two drafts both define in a file. Each entry is weighed as the view cache weighs views (line ids, texts, names: view.ts's stringBytes) and the whole stays under 4 MB, oldest out first; an entry over the budget isn't kept. Keys name everything an entry depends on: shared's version, the draft's base and its atoms. Each collisions call drops every entry it didn't use, so a draft that changes, an agent that leaves or shared moving on drops theirs at once. On a stored writer only; the publish check (land.ts) and the in-memory project work as before.
On the abso export (my machine): a warm collisions call takes 322 ms instead of 3.4 s, with the same answer as replay. A full warm run's held heap is at most 42.9 MB (41.7 MB without it), and all 33 answers match.
Tests: kept-parts (new: the budget, oldest out first, an oversized entry never kept, a round dropping what it didn't use) and collisions-kept-views, which now runs through the kept parts on the writer (a draft changing, shared moving on, a draft dropped, each asked twice against the in-memory project). With the collision, definition, path and view tests: 47 of 47.Compare6
7import { stringBytes } from "../../src/engine/view.ts";
8import type { Definition } from "./definitions.ts";
10/** At most this many bytes, weighed as the view cache weighs views (view.ts). */
11export const KEPT_PARTS_BUDGET = 4_000_000;
13const OBJECT_BYTES = 32;
14const ARRAY_HEADER_BYTES = 24;
15const MAP_HEADER_BYTES = 32;
16const MAP_ENTRY_BYTES = 40;
17const REFERENCE_BYTES = 8;
19/** Entries by key, most recently used last, held under KEPT_PARTS_BUDGET bytes. */
20export class KeptParts {
21 readonly #budget: number;
22 readonly #entries = new Map<string, { value: unknown; bytes: number }>();
23 #bytes = 0;
24 /** The keys used since the round began, when one has. */
25 #used: Set<string> | undefined;
27 constructor(budget = KEPT_PARTS_BUDGET) {
28 this.#budget = budget;
29 }
31 get bytes(): number {
32 return this.#bytes;
33 }
35 get size(): number {
36 return this.#entries.size;
37 }
39 /** The value kept under `key`, or `make()`'s, kept when it fits: `weigh` says what it holds. */
40 get<T>(key: string, make: () => T, weigh: (value: T) => number): T {
41 this.#used?.add(key);
42 const kept = this.#entries.get(key);
43 if (kept) {
44 this.#entries.delete(key);
45 this.#entries.set(key, kept);
46 return kept.value as T;
47 }
48 const value = make();
49 const bytes = MAP_ENTRY_BYTES + stringBytes(key) + weigh(value);
50 if (bytes > this.#budget) return value;
51 this.#entries.set(key, { value, bytes });
52 this.#bytes += bytes;
53 for (const [old, entry] of this.#entries) {
54 if (this.#bytes <= this.#budget) break;
55 this.#entries.delete(old);
56 this.#bytes -= entry.bytes;
57 }
58 return value;
59 }
61 /** Start counting which entries are used; endRound drops the rest. */
62 startRound(): void {
63 this.#used = new Set();
64 }
66 /** Drop every entry not used since startRound: what changed, left or moved on since. */
67 endRound(): void {
68 const used = this.#used;
69 this.#used = undefined;
70 if (!used) return;
71 for (const [key, entry] of this.#entries) {
72 if (used.has(key)) continue;
73 this.#entries.delete(key);
74 this.#bytes -= entry.bytes;
75 }
76 }
77}
79/** A definition's bytes: its record, name, text, and its lines' ids (its file's path is shared with the view's). */
80export function definitionBytes(d: Definition): number {
81 let n = OBJECT_BYTES + REFERENCE_BYTES + stringBytes(d.name) + stringBytes(d.text) + ARRAY_HEADER_BYTES;
82 for (const line of d.lines) n += REFERENCE_BYTES + stringBytes(line);
83 return n;
84}
86/** Definitions by name. */
87export function definitionsBytes(defs: ReadonlyMap<string, readonly Definition[]>): number {
88 let n = MAP_HEADER_BYTES;
89 for (const [name, list] of defs) {
90 n += MAP_ENTRY_BYTES + stringBytes(name) + ARRAY_HEADER_BYTES;
91 for (const d of list) n += REFERENCE_BYTES + definitionBytes(d);
92 }
93 return n;
94}
96/** Names with where they're used: a file and a line index for each. */
97export function usesBytes(uses: ReadonlyMap<string, readonly { file: string; index: number }[]>): number {
98 let n = MAP_HEADER_BYTES;
99 for (const [name, where] of uses)
100 n += MAP_ENTRY_BYTES + stringBytes(name) + ARRAY_HEADER_BYTES + where.length * (REFERENCE_BYTES + OBJECT_BYTES);
capacity314Definition rule: lay out only the touched files the draft's uses reach (abso 738). The rule found changed definitions by laying out every file the newer work touched, in two views; for codex-prose-authorship-610 that was 494 files a view where its uses reach 7. It now works out which files the uses mean first and lays out only the touched ones among them. Same answers: the rule already ignored untouched files. Draft collisions keep each file's definitions, and the touched files, under the newer work's key.Compare101 return n;
102}
104/** A set of paths (the files some work touched). */
105export function filesBytes(files: ReadonlySet<string>): number {
106 let n = MAP_HEADER_BYTES;
107 for (const file of files) n += MAP_ENTRY_BYTES + stringBytes(file);
capacity249Collisions step 3: each draft's definition work kept between calls, under a hard 4 MB budget (abso Capacity, issue 664).
KeptParts (kept-parts.ts) holds what draft collisions work out about each draft and each pair of drafts: the names a draft's new lines use, the definitions a draft's changes touch before and after (the changed-definition rule), and the names two drafts both define in a file. Each entry is weighed as the view cache weighs views (line ids, texts, names: view.ts's stringBytes) and the whole stays under 4 MB, oldest out first; an entry over the budget isn't kept. Keys name everything an entry depends on: shared's version, the draft's base and its atoms. Each collisions call drops every entry it didn't use, so a draft that changes, an agent that leaves or shared moving on drops theirs at once. On a stored writer only; the publish check (land.ts) and the in-memory project work as before.
On the abso export (my machine): a warm collisions call takes 322 ms instead of 3.4 s, with the same answer as replay. A full warm run's held heap is at most 42.9 MB (41.7 MB without it), and all 33 answers match.
Tests: kept-parts (new: the budget, oldest out first, an oversized entry never kept, a round dropping what it didn't use) and collisions-kept-views, which now runs through the kept parts on the writer (a draft changing, shared moving on, a draft dropped, each asked twice against the in-memory project). With the collision, definition, path and view tests: 47 of 47.Compare108 return n;
109}