- MCP
- blame on this site's /mcp
- CLI
- abso blame worker/project/views.ts --version 104 --json
- JSON
- /christopher/abso-core/blame/worker/project/views.ts?version=104&format=json
61 linesFirst import 93% · codex-capacity-policy 7%Last change codex-capacity-policy in version 104,
61 lines from 2 changes in 2 versions.
init0Start the project1// The views a project lays out from sets of atoms, cached under a byte budget (#46, disk-first 1). Published
2// versions never change, so their views are kept by name; any other set is kept by its exact contents.
4import { type AtomId, type Graph, View } from "../../src/engine/index.ts";
6/**
7 * About how many bytes the cached views may hold together (#46). A laid-out
8 * line costs about 10 bytes (view.ts), so this holds over 2 million of them;
9 * the records a view keeps for the file it was last asked about count too.
10 */
11const VIEW_BUDGET = 24_000_000;
13/** Views by key, most recently used last, held under VIEW_BUDGET bytes and 32 views. */
14export class ViewCache {
15 readonly #graph: Graph;
16 readonly #cache = new Map<string, View>();
18 constructor(graph: Graph) {
19 this.#graph = graph;
20 }
22 /**
23 * Keep the cached views under VIEW_BUDGET bytes (the website project, #43,
24 * #46): each view holds every line its files ever had, so a few views of a
25 * large generated file add up. At most 32.
26 */
27 #trim(): void {
28 let total = 0;
29 for (const v of this.#cache.values()) total += v.weight();
30 for (const [key, v] of this.#cache) {
codex-capacity-policy104Enforce retained view cache budget on accessCompare31 if (total <= VIEW_BUDGET && this.#cache.size <= 32) break;
33 this.#cache.delete(key);
34 }
35 }
37 /** A view of a set, cached by the set's exact contents. */
38 view(set: ReadonlySet<AtomId>): View {
39 const key = [...set]
40 .map((id) => this.#graph.atom(id).seq)
41 .sort((a, b) => a - b)
42 .join(",");
43 return this.keyed(key, () => set);
44 }
46 /** A view cached under `key`, made from `set()` when it isn't there. */
47 keyed(key: string, set: () => ReadonlySet<AtomId>): View {
48 let view = this.#cache.get(key);
49 if (view) {
50 // Most recently used last, so eviction takes the oldest.
51 this.#cache.delete(key);
52 } else {
53 view = new View(this.#graph, set());
54 }
codex-capacity-policy104Enforce retained view cache budget on accessCompare55 // Account the selected view, including growth since its last access,
56 // before evicting older entries. An oversized view may evict itself.
60 }
61}