- MCP
- blame on this site's /mcp
- CLI
- abso blame worker/project/views.ts --json
- JSON
- /christopher/abso-core/blame/worker/project/views.ts?format=json
142 linescapacity 47% · First import 32% · codex-capacity-chair 19% · codex-capacity-policy 2%Last change capacity in version 263,
142 lines from 11 changes in 8 versions.
init0Start the project1// The views a project lays out from sets of atoms, cached under a byte budget (#46, disk-first 1). Published
codex-capacity-chair117Avoid full membership enumeration for indexed view cache keysCompare2// versions never change, so their views are kept by name. Immutable indexed sets use their identity;
3// ordinary in-memory sets use their exact contents.
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare5import { type AtomId, type Graph, type ReadView, View } from "../../src/engine/index.ts";
codex-capacity-chair117Avoid full membership enumeration for indexed view cache keysCompare6import { StableSet } from "../../src/engine/state-source.ts";
8/**
9 * About how many bytes the cached views may hold together (#46). A laid-out
10 * line costs about 10 bytes (view.ts), so this holds over 2 million of them;
11 * the records a view keeps for the file it was last asked about count too.
12 */
13const VIEW_BUDGET = 24_000_000;
capacity234The view cache holds up to 128 views, still within its byte budget (disk-first 2; abso Capacity).
where visits every agent's draft view in turn. abso has more agents with drafts than the cache's 32 views, so each visit evicted the view the next call would need, and a kept writer laid every view out again on every call. Testing measured where at 5.5 s warm on abso with 232.
VIEW_COUNT is now 128. The byte budget (VIEW_BUDGET, 24 MB) still bounds what the views hold.
On abso adopted fresh, one kept writer: where's first call takes 3.7 to 4.5 s, then 0.31 to 0.37 s with about 1,700 reads (4.6 to 5.5 s each time at 32 views). 64 views was already enough on abso today; heap after the run is 32 MB either way.
Tests: view-cache's two count tests now use VIEW_COUNT. Named tests: view-cache, where-many-agents, draft-reads-stored, project, membership-cache, files-reads, collision-streaming, authors-stored (42 of 42); tsc and biome clean.Compare15/**
16 * At most this many views (abso Capacity). where visits every agent's draft view in turn: with more agents than views,
17 * each visit evicted the next one, and a warm where on abso laid every view out again (4.5 s against 0.33 s). The byte
18 * budget still bounds what they hold.
19 */
20export const VIEW_COUNT = 128;
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare22/** Internal opt-in. The owner validates identity and lifetime on every returned reader. */
23export interface ReadViewProvider {
24 keyed(key: string): ReadView;
25}
capacity234The view cache holds up to 128 views, still within its byte budget (disk-first 2; abso Capacity).
where visits every agent's draft view in turn. abso has more agents with drafts than the cache's 32 views, so each visit evicted the view the next call would need, and a kept writer laid every view out again on every call. Testing measured where at 5.5 s warm on abso with 232.
VIEW_COUNT is now 128. The byte budget (VIEW_BUDGET, 24 MB) still bounds what the views hold.
On abso adopted fresh, one kept writer: where's first call takes 3.7 to 4.5 s, then 0.31 to 0.37 s with about 1,700 reads (4.6 to 5.5 s each time at 32 views). 64 views was already enough on abso today; heap after the run is 32 MB either way.
Tests: view-cache's two count tests now use VIEW_COUNT. Named tests: view-cache, where-many-agents, draft-reads-stored, project, membership-cache, files-reads, collision-streaming, authors-stored (42 of 42); tsc and biome clean.Compare27/** Views by key, most recently used last, held under VIEW_BUDGET bytes and VIEW_COUNT views. */
29 readonly #graph: Graph;
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare30 readonly #provider?: ReadViewProvider;
codex-capacity-chair117Avoid full membership enumeration for indexed view cache keysCompare31 readonly #cache = new Map<string | StableSet<AtomId>, View>();
capacity263The view cache trims the least recently used file layouts across its views before whole views (abso Capacity, issue 664).
After each read, a kept reader's trim (ViewCache.trim, from afterRead) now lets go of file layouts in the order they were last used, across every cached view, until the views fit; a layout several views share (a draft's view borrows its base's) counts once and goes from all of them. Only then does it evict whole views. It evicted whole views before, so a call that laid out two big versions lost one of them entirely. Within a read, the cache trims whole views as before. A forgotten layout is laid out again, the same, when next asked.
On the abso export, collisions then compare 612 to 1224 asked again (Testing's order): 4.4 s and 17,349 queries, from 7.4 to 9.5 s. Compare alone needs about 25 MB of layouts, more than the 24 MB budget, so about half are laid out again; the rest needs a bigger budget or lighter layouts.
View records each file's last use (a count shared by all views) and can forget one (laidOut, forget); ViewCache takes an optional budget, for tests. Tests: view-cache (new: the least recently used layout goes first, both views stay cached, and the forgotten file reads the same); view's retained-state test still holds. All of src/engine/test (294) and worker/project/test (354) pass.Compare33 /** VIEW_BUDGET unless a test asks for less. */
34 readonly #budget: number;
35 constructor(graph: Graph, provider?: (graph: Graph) => ReadViewProvider, budget = VIEW_BUDGET) {
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare37 this.#provider = provider?.(graph);
capacity263The view cache trims the least recently used file layouts across its views before whole views (abso Capacity, issue 664).
After each read, a kept reader's trim (ViewCache.trim, from afterRead) now lets go of file layouts in the order they were last used, across every cached view, until the views fit; a layout several views share (a draft's view borrows its base's) counts once and goes from all of them. Only then does it evict whole views. It evicted whole views before, so a call that laid out two big versions lost one of them entirely. Within a read, the cache trims whole views as before. A forgotten layout is laid out again, the same, when next asked.
On the abso export, collisions then compare 612 to 1224 asked again (Testing's order): 4.4 s and 17,349 queries, from 7.4 to 9.5 s. Compare alone needs about 25 MB of layouts, more than the 24 MB budget, so about half are laid out again; the rest needs a bigger budget or lighter layouts.
View records each file's last use (a count shared by all views) and can forget one (laidOut, forget); ViewCache takes an optional budget, for tests. Tests: view-cache (new: the least recently used layout goes first, both views stay cached, and the forgotten file reads the same); view's retained-state test still holds. All of src/engine/test (294) and worker/project/test (354) pass.Compare38 this.#budget = budget;
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare39 }
40 assertUnkeyedAllowed(): void {
41 if (this.#provider) throw Error("unsupported unkeyed projection membership");
44 /**
capacity247A kept reader settles after each read; line texts weigh what V8 holds (abso Capacity, issue 664).
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.Compare45 * Weigh every cached view again and evict until they fit (abso Capacity): views grow while a call lays files out,
46 * and #get weighs a view only when it is asked for again. A kept reader trims after each call.
47 */
48 trim(): void {
capacity263The view cache trims the least recently used file layouts across its views before whole views (abso Capacity, issue 664).
After each read, a kept reader's trim (ViewCache.trim, from afterRead) now lets go of file layouts in the order they were last used, across every cached view, until the views fit; a layout several views share (a draft's view borrows its base's) counts once and goes from all of them. Only then does it evict whole views. It evicted whole views before, so a call that laid out two big versions lost one of them entirely. Within a read, the cache trims whole views as before. A forgotten layout is laid out again, the same, when next asked.
On the abso export, collisions then compare 612 to 1224 asked again (Testing's order): 4.4 s and 17,349 queries, from 7.4 to 9.5 s. Compare alone needs about 25 MB of layouts, more than the 24 MB budget, so about half are laid out again; the rest needs a bigger budget or lighter layouts.
View records each file's last use (a count shared by all views) and can forget one (laidOut, forget); ViewCache takes an optional budget, for tests. Tests: view-cache (new: the least recently used layout goes first, both views stay cached, and the forgotten file reads the same); view's retained-state test still holds. All of src/engine/test (294) and worker/project/test (354) pass.Compare49 const seen = new Set<object>();
50 let total = 0;
51 for (const v of this.#cache.values()) total += v.weight(seen);
52 if (total > this.#budget) this.#shed(total - this.#budget);
capacity247A kept reader settles after each read; line texts weigh what V8 holds (abso Capacity, issue 664).
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.Compare53 this.#trim();
capacity263The view cache trims the least recently used file layouts across its views before whole views (abso Capacity, issue 664).
After each read, a kept reader's trim (ViewCache.trim, from afterRead) now lets go of file layouts in the order they were last used, across every cached view, until the views fit; a layout several views share (a draft's view borrows its base's) counts once and goes from all of them. Only then does it evict whole views. It evicted whole views before, so a call that laid out two big versions lost one of them entirely. Within a read, the cache trims whole views as before. A forgotten layout is laid out again, the same, when next asked.
On the abso export, collisions then compare 612 to 1224 asked again (Testing's order): 4.4 s and 17,349 queries, from 7.4 to 9.5 s. Compare alone needs about 25 MB of layouts, more than the 24 MB budget, so about half are laid out again; the rest needs a bigger budget or lighter layouts.
View records each file's last use (a count shared by all views) and can forget one (laidOut, forget); ViewCache takes an optional budget, for tests. Tests: view-cache (new: the least recently used layout goes first, both views stay cached, and the forgotten file reads the same); view's retained-state test still holds. All of src/engine/test (294) and worker/project/test (354) pass.Compare54 }
56 /**
57 * Let go of the least recently used file layouts across every view, until about `over` bytes are freed (abso
58 * Capacity). Evicting whole views dropped layouts just made along with old ones: compare 612 to 1224 on abso needs
59 * both versions' layouts, about 25 MB, and evicting one whole after the call meant asking again laid it all out again.
60 * A layout several views share goes from all of them.
61 */
62 #shed(over: number): void {
63 // One entry per layout: a layout several views hold (a draft's view borrows its base's) is used as recently as
64 // any of them used it, and goes from all of them at once, since only that frees it.
65 const layouts = new Map<object, { used: number; bytes: number; holders: { view: View; path: string }[] }>();
66 for (const view of this.#cache.values())
67 for (const f of view.laidOut()) {
68 const entry = layouts.get(f.layout);
69 if (entry) {
70 entry.used = Math.max(entry.used, f.used);
71 entry.holders.push({ view, path: f.path });
72 } else layouts.set(f.layout, { used: f.used, bytes: f.bytes, holders: [{ view, path: f.path }] });
73 }
74 let freed = 0;
75 for (const entry of [...layouts.values()].sort((a, b) => a.used - b.used)) {
76 if (freed >= over) break;
77 for (const { view, path } of entry.holders) view.forget(path);
78 freed += entry.bytes;
79 }
capacity247A kept reader settles after each read; line texts weigh what V8 holds (abso Capacity, issue 664).
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.Compare80 }
82 /**
84 * #46): each view holds every line its files ever had, so a few views of a
capacity234The view cache holds up to 128 views, still within its byte budget (disk-first 2; abso Capacity).
where visits every agent's draft view in turn. abso has more agents with drafts than the cache's 32 views, so each visit evicted the view the next call would need, and a kept writer laid every view out again on every call. Testing measured where at 5.5 s warm on abso with 232.
VIEW_COUNT is now 128. The byte budget (VIEW_BUDGET, 24 MB) still bounds what the views hold.
On abso adopted fresh, one kept writer: where's first call takes 3.7 to 4.5 s, then 0.31 to 0.37 s with about 1,700 reads (4.6 to 5.5 s each time at 32 views). 64 views was already enough on abso today; heap after the run is 32 MB either way.
Tests: view-cache's two count tests now use VIEW_COUNT. Named tests: view-cache, where-many-agents, draft-reads-stored, project, membership-cache, files-reads, collision-streaming, authors-stored (42 of 42); tsc and biome clean.Compare85 * large generated file add up. At most VIEW_COUNT.
87 #trim(): void {
capacity241The view cache counts a file layout two views share once (disk-first 2; abso Capacity).
Testing found collisions on abso slower with 240 than with 234 (warm 7.3 to 12.3 s). Since 235 a draft's view takes its base view's layout of every file the draft doesn't touch, so many cached views hold the same layouts. The cache counted each view's layouts in full, so the 24 MB budget filled with copies. That evicted views the next call needed, and a kept writer laid abso's drafts out again on every collisions call.
- ViewCache keeps the newest views that fit the budget, as evicting oldest first does, counting a layout already counted for a newer view once (View.weight(seen)).
- A layout's own bytes are worked out once per layout (layoutBytes): the cache weighs every view on every lookup, which summed every line's text again.
On abso adopted fresh, one kept writer, against 240 on the same database: collisions 17.5 s to 11.9 s cold, 11.3 s to 6.1 s on the next call (49,000 and 19,000 reads, from 71,000 and 41,000). Both match replay. Heap after the run is the same with and without (about 125 to 130 MB with the kept writer); that's not from this change, and I'm reporting it separately.
Named tests: view-cache (the eviction tests as before), every engine test (290 of 290), every worker/project test (341 of 341); tsc and biome clean.Compare88 // The newest views that fit, as evicting oldest first leaves them. A file layout two views share (a draft's view
89 // takes its base's, View.shareFiles) counts once (abso Capacity): counted per view, they filled the budget twice
90 // over, and a kept writer laid abso's drafts out again on every collisions call.
91 const seen = new Set<object>();
capacity241The view cache counts a file layout two views share once (disk-first 2; abso Capacity).
Testing found collisions on abso slower with 240 than with 234 (warm 7.3 to 12.3 s). Since 235 a draft's view takes its base view's layout of every file the draft doesn't touch, so many cached views hold the same layouts. The cache counted each view's layouts in full, so the 24 MB budget filled with copies. That evicted views the next call needed, and a kept writer laid abso's drafts out again on every collisions call.
- ViewCache keeps the newest views that fit the budget, as evicting oldest first does, counting a layout already counted for a newer view once (View.weight(seen)).
- A layout's own bytes are worked out once per layout (layoutBytes): the cache weighs every view on every lookup, which summed every line's text again.
On abso adopted fresh, one kept writer, against 240 on the same database: collisions 17.5 s to 11.9 s cold, 11.3 s to 6.1 s on the next call (49,000 and 19,000 reads, from 71,000 and 41,000). Both match replay. Heap after the run is the same with and without (about 125 to 130 MB with the kept writer); that's not from this change, and I'm reporting it separately.
Named tests: view-cache (the eviction tests as before), every engine test (290 of 290), every worker/project test (341 of 341); tsc and biome clean.Compare93 let kept = 0;
94 let full = false;
95 for (const [key, v] of [...this.#cache].reverse()) {
96 if (!full) {
97 const w = v.weight(seen);
capacity263The view cache trims the least recently used file layouts across its views before whole views (abso Capacity, issue 664).
After each read, a kept reader's trim (ViewCache.trim, from afterRead) now lets go of file layouts in the order they were last used, across every cached view, until the views fit; a layout several views share (a draft's view borrows its base's) counts once and goes from all of them. Only then does it evict whole views. It evicted whole views before, so a call that laid out two big versions lost one of them entirely. Within a read, the cache trims whole views as before. A forgotten layout is laid out again, the same, when next asked.
On the abso export, collisions then compare 612 to 1224 asked again (Testing's order): 4.4 s and 17,349 queries, from 7.4 to 9.5 s. Compare alone needs about 25 MB of layouts, more than the 24 MB budget, so about half are laid out again; the rest needs a bigger budget or lighter layouts.
View records each file's last use (a count shared by all views) and can forget one (laidOut, forget); ViewCache takes an optional budget, for tests. Tests: view-cache (new: the least recently used layout goes first, both views stay cached, and the forgotten file reads the same); view's retained-state test still holds. All of src/engine/test (294) and worker/project/test (354) pass.Compare98 if (total + w <= this.#budget && kept < VIEW_COUNT) {
capacity241The view cache counts a file layout two views share once (disk-first 2; abso Capacity).
Testing found collisions on abso slower with 240 than with 234 (warm 7.3 to 12.3 s). Since 235 a draft's view takes its base view's layout of every file the draft doesn't touch, so many cached views hold the same layouts. The cache counted each view's layouts in full, so the 24 MB budget filled with copies. That evicted views the next call needed, and a kept writer laid abso's drafts out again on every collisions call.
- ViewCache keeps the newest views that fit the budget, as evicting oldest first does, counting a layout already counted for a newer view once (View.weight(seen)).
- A layout's own bytes are worked out once per layout (layoutBytes): the cache weighs every view on every lookup, which summed every line's text again.
On abso adopted fresh, one kept writer, against 240 on the same database: collisions 17.5 s to 11.9 s cold, 11.3 s to 6.1 s on the next call (49,000 and 19,000 reads, from 71,000 and 41,000). Both match replay. Heap after the run is the same with and without (about 125 to 130 MB with the kept writer); that's not from this change, and I'm reporting it separately.
Named tests: view-cache (the eviction tests as before), every engine test (290 of 290), every worker/project test (341 of 341); tsc and biome clean.Compare99 total += w;
100 kept++;
101 continue;
102 }
103 full = true;
104 }
106 }
107 }
codex-capacity-chair117Avoid full membership enumeration for indexed view cache keysCompare109 /** Indexed snapshots use identity; ordinary sets use their exact contents. */
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare110 view(set: ReadonlySet<AtomId>): ReadView {
111 this.assertUnkeyedAllowed();
codex-capacity-chair117Avoid full membership enumeration for indexed view cache keysCompare112 // Immutable indexed membership is already a stable identity. Building
113 // a sorted history-sized key defeats its external-storage contract.
114 if (set instanceof StableSet) return this.#get(set, () => set);
116 .map((id) => this.#graph.atom(id).seq)
117 .sort((a, b) => a - b)
118 .join(",");
119 return this.keyed(key, () => set);
120 }
122 /** A view cached under `key`, made from `set()` when it isn't there. */
codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare123 keyed(key: string, set: () => ReadonlySet<AtomId>): ReadView {
124 if (this.#provider) return this.#provider.keyed(key);
codex-capacity-chair117Avoid full membership enumeration for indexed view cache keysCompare125 return this.#get(key, set);
126 }
128 #get(key: string | StableSet<AtomId>, set: () => ReadonlySet<AtomId>): View {
130 if (view) {
131 // Most recently used last, so eviction takes the oldest.
132 this.#cache.delete(key);
133 } else {
134 view = new View(this.#graph, set());
135 }
codex-capacity-policy104Enforce retained view cache budget on accessCompare136 // Account the selected view, including growth since its last access,
137 // before evicting older entries. An oversized view may evict itself.
141 }
142}