A big publish spends less on the changed-definition rule (abso issue 158, under 157). Version 6 of shared· engine· Oct 9 (2026-10-09 01:46 UTC) · Not checked
Measured on gig-replay-2's a3 PR 309 publish, five versions behind shared, through the Worker's project layer with text read back from the log, as live runs it. Cloud measured 9 s of CPU on staging. Two costs in the definition rule:
For every line a draft wrote, it walked the atom's runs to find the run holding the line, and each run's length meant reading its text back from the log. Each atom's run ends are now worked out once per check (definition-rule.ts). It scanned data files for definitions. A 23,000-line JSON fixture was read line by line for names it can't define, and its keys could pass for uses of code names. JSON, CSV, lock and SVG files now count as holding no code, like prose (names.ts holdsNoCode). The publish through EngineProject takes about 0.84-1.1 s locally (was 1.9 s); what's left is mostly expressing moves within the layout budget.
Tests: a new definitions test (data files hold no definitions); the changed-definition tests pass. Check passes (695), and the project tests also pass with AVCS_TEXT_FROM_LOG=1 (217). The replay gate passed on 33 live projects (ef9edb7) with these same three files in abso's folder.
Version 5 · Files at version 6
4 files, 42 lines added, 14 removed.
--- a/worker/project/definition-rule.ts
+++ b/worker/project/definition-rule.ts
@@ -7,7 +7,7 @@
7 7 import { type AtomId, type Graph, joinLines, type LineId, type View } from "../../src/engine/index.ts"; 8 8 import { type Origin, touchedFiles } from "./collisions.ts"; 9 9 import { type Definition, definitionsIn, importsOf, usedNames } from "./definitions.ts"; 10 − import { codeOfLines, declaredIn, isProse } from "./names.ts";
10 + import { codeOfLines, declaredIn, holdsNoCode } from "./names.ts"; 11 11 import { definitionText } from "./news.ts"; 12 12 import type { Collision } from "./project.ts"; @@ -30,6 +30,12 @@
31 31 const EMPTY_NAMES: ReadonlySet<string> = new Set(); 33 + /** Where one of an atom's inserted runs ends (its lines' k), and the node it hangs off. */ 35 + readonly end: number; 36 + readonly parent: string; 33 39 export class DefinitionRule { 34 40 readonly #graph: Graph; 35 41 readonly #origin: (atom: AtomId, spaceName: string) => Origin; @@ -46,20 +52,20 @@
46 52 * replaced the block of lines the atom deleted just before it in `base`. 47 53 * A pure insertion replaced nothing. 49 − #replacedNames(line: LineId, base: View): ReadonlySet<string> {
55 + #replacedNames(line: LineId, base: View, runsOf: Map<AtomId, readonly RunEnd[]>): ReadonlySet<string> { 50 56 const g = this.#graph; 51 57 const info = g.line(line); 52 58 if (!info) return EMPTY_NAMES; 53 59 const atom = g.atom(info.atom); 54 − let k = 0;
55 − let parent: string | undefined;
56 − for (const run of atom.inserts) {
57 − if (info.k < k + run.lines.length) {
58 − parent = run.parent;
59 − break;
60 − }
61 − k += run.lines.length;
60 + // Where each of the atom's runs ends, worked out once per check (abso issue 158): reading a run's 61 + // lines can mean reading its text back from the log, so not once per line of a big change. 62 + let runs = runsOf.get(atom.id); 65 + runs = atom.inserts.map((run) => ({ end: (k += run.lines.length), parent: run.parent })); 66 + runsOf.set(atom.id, runs); 68 + const parent = runs.find((r) => info.k < r.end)?.parent; 63 69 if (parent === undefined || parent.startsWith("^") || !g.deletersOf(parent).includes(atom.id)) return EMPTY_NAMES; 64 70 const key = `${atom.id} ${parent}`; 65 71 let names = this.#replacedCache.get(key); @@ -100,10 +106,11 @@
100 106 if (draft.size === 0 || newer.size === 0) return []; 101 107 const uses = new Map<string, { file: string; index: number }[]>(); 102 108 const declared = new Set<string>(); 109 + const runsOf = new Map<AtomId, readonly RunEnd[]>(); 103 110 // Only files the draft wrote lines in can hold its lines. 104 111 const draftFiles = touchedFiles(this.#graph, draft, [view]); 105 112 for (const file of [...draftFiles].sort()) { 106 − if (isProse(file) || !view.hasFile(file)) continue;
113 + if (holdsNoCode(file) || !view.hasFile(file)) continue; 107 114 const visible = view.lines(file); 108 115 if (!visible.some((l) => draft.has(l.atom))) continue; 109 116 const code = codeOfLines(visible.map((l) => l.text)); @@ -111,7 +118,7 @@
111 118 if (!draft.has(line.atom)) return; 112 119 for (const name of declaredIn(code[i]!)) declared.add(name); 113 120 // Only names the change added: a use already on the lines it replaced is not the draft's to answer for. 114 − const before = this.#replacedNames(line.id, baseView);
121 + const before = this.#replacedNames(line.id, baseView, runsOf); 115 122 for (const name of usedNames(code[i]!)) { 116 123 if (before.has(name)) continue; 117 124 const list = uses.get(name); --- a/worker/project/definitions.ts
+++ b/worker/project/definitions.ts
@@ -20,7 +20,7 @@
20 20 // that defines it (project.ts, #definitionCore). 22 22 import type { LineId, View } from "../../src/engine/index.ts"; 23 − import { codeOfLines, isCommonName, isProse } from "./names.ts";
23 + import { codeOfLines, holdsNoCode, isCommonName } from "./names.ts"; 25 25 export interface Definition { 26 26 readonly name: string; @@ -119,7 +119,7 @@
121 121 function definitionsInFile(view: View, file: string, keepCommon = false): Definition[] { 122 − if (isProse(file) || !view.hasFile(file)) return [];
122 + if (holdsNoCode(file) || !view.hasFile(file)) return []; 123 123 const out: Definition[] = []; 124 124 const visible = view.lines(file); 125 125 const code = codeOfLines(visible.map((l) => l.text)); --- a/worker/project/names.ts
+++ b/worker/project/names.ts
@@ -64,6 +64,21 @@
66 66 /** Files of prose, whose words are not code: Markdown, plain text, READMEs and the like. */ 67 + /** Data files: no code defines or uses a name in them, however big they are (abso issue 158). */ 68 + const DATA_EXTENSIONS = new Set(["json", "jsonc", "json5", "jsonl", "ndjson", "geojson", "csv", "tsv", "lock", "svg"]); 71 + * Whether the definition rule passes over a file: prose, or data. Scanning a 72 + * 23,000-line JSON fixture for definitions it can't hold cost a big publish 73 + * hundreds of milliseconds, and its keys could pass for uses of code names. 75 + export function holdsNoCode(path: string): boolean { 76 + if (isProse(path)) return true; 77 + const base = path.slice(path.lastIndexOf("/") + 1).toLowerCase(); 78 + const dot = base.lastIndexOf("."); 79 + return dot > 0 && DATA_EXTENSIONS.has(base.slice(dot + 1)); 67 82 export function isProse(path: string): boolean { 68 83 const base = path.slice(path.lastIndexOf("/") + 1).toLowerCase(); 69 84 const dot = base.lastIndexOf("."); --- a/worker/project/test/definitions.test.ts
+++ b/worker/project/test/definitions.test.ts
@@ -62,3 +62,9 @@
62 62 Span: ["pub struct Span {\n start: usize,\n}"], 66 + test("data files hold no definitions: JSON, CSV and lock files are passed over, however code-like a line looks (abso issue 158)", () => { 67 + const codeLike = "export function parsePattern(text: string): Node {\n return compileNode(text);\n}\n"; 68 + assert.deepEqual(defs({ "fixtures/a.json": codeLike, "data/b.csv": codeLike, "c.lock": codeLike }), {}); 69 + assert.deepEqual(Object.keys(defs({ "src/a.ts": codeLike })), ["parsePattern"]);