{"version":245,"agent":"capacity","message":"Collisions step 1: whether a file exists, without laying it out (abso Capacity, issue 664).\n\nA published version's view on a writer answers hasFile from the kept path list (PathIndex.keptPathSet, the set pathsAt already answers from), and a draft's view asks its base for every file the draft doesn't touch. Resolving an import tried up to seven file names in collisions, and each check laid the whole file out.\n\nOn the abso export (collisions, my machine): the first call lays out 130 files instead of 407, 13.4 s instead of 15.2 s; a warm call 7.7 s instead of 8.3 s (step 2 is most of what's left). Same answer as replay. Heap after a full warm run: 76.9 MB against 76.5 MB on 244.\n\ntest/known-paths.test.ts: every name at versions 0 to 2 and in four drafts, against the in-memory project, before and after every file is read: a version that deletes a file and renames one with record, one that moves lines into a new file, and drafts that delete, rename, move lines and add.","time":1792080130564,"timeIso":"2026-10-15T16:02:10.564Z","changes":5,"change":3776,"files":["src/engine/view.ts","worker/project/pathindex.ts","worker/project/project.ts","worker/project/test/known-paths.test.ts"],"draft":null,"diff":[{"path":"src/engine/view.ts","added":28,"removed":1,"diff":"--- a/src/engine/view.ts\n+++ b/src/engine/view.ts\n@@ -49,7 +49,14 @@\n /** Structural read boundary shared by historical and transaction-bound projections. */\n export type ReadView = Omit<\n \tPick<View, keyof View>,\n-\t\"sameText\" | \"visibleCount\" | \"shareMoves\" | \"shareFiles\" | \"fileOfNumber\" | \"lineNumberOf\" | \"visibleWriters\"\n+\t| \"sameText\"\n+\t| \"visibleCount\"\n+\t| \"shareMoves\"\n+\t| \"shareFiles\"\n+\t| \"knowPaths\"\n+\t| \"fileOfNumber\"\n+\t| \"lineNumberOf\"\n+\t| \"visibleWriters\"\n > & {\n \tsameText(path: string, other: ReadView): boolean;\n };\n@@ -427,6 +434,17 @@\n \t\tthis.#filesFrom = { from, except };\n \t}\n \t#filesFrom: { from: View; except: () => ReadonlySet<string> | undefined } | null | undefined;\n+\n+\t/**\n+\t * The files this view's set has, from what the project keeps for a published version (abso Capacity): hasFile\n+\t * answers from it, not a layout of the file. Collisions resolving an import tried up to seven names, and each one\n+\t * laid its file out. `paths` is asked once, when first needed; undefined lays files out as before.\n+\t */\n+\tknowPaths(paths: () => ReadonlySet<string> | undefined): void {\n+\t\tif (this.#pathsFrom === undefined) this.#pathsFrom = paths;\n+\t}\n+\t#pathsFrom: (() => ReadonlySet<string> | undefined) | undefined;\n+\t#knownPaths: ReadonlySet<string> | null | undefined;\n \t#filesShared: { from: View; except: ReadonlySet<string> } | null | undefined;\n \t#sharedFiles(): { from: View; except: ReadonlySet<string> } | null {\n \t\tif (this.#filesShared === undefined) {\n@@ -899,6 +917,15 @@\n \n \t/** Whether the file exists in this projection (has a visible line). */\n \thasFile(path: string): boolean {\n+\t\tif (!this.#files.has(path)) {\n+\t\t\t// A file the draft doesn't touch exists as it does in the base; a published version's files are kept.\n+\t\t\tconst shared = this.#filesFrom === undefined ? null : this.#sharedFiles();\n+\t\t\tif (shared && !shared.except.has(path)) return shared.from.hasFile(path);\n+\t\t\tif (this.#pathsFrom !== undefined) {\n+\t\t\t\tif (this.#knownPaths === undefined) this.#knownPaths = this.#pathsFrom() ?? null;\n+\t\t\t\tif (this.#knownPaths) return this.#knownPaths.has(path);\n+\t\t\t}\n+\t\t}\n \t\tconst attrs = this.attrs(path);\n \t\treturn attrs.exists || attrs.link !== null || attrs.blob !== null || this.#file(path).vis.length > 0;\n \t}"},{"path":"worker/project/pathindex.ts","added":11,"removed":2,"diff":"--- a/worker/project/pathindex.ts\n+++ b/worker/project/pathindex.ts\n@@ -50,17 +50,26 @@\n \t * then the caller lays the version out.\n \t */\n \tkeptPaths(space: Space, version: number): string[] | undefined {\n+\t\tconst files = this.keptPathSet(space, version);\n+\t\treturn files && [...files].sort();\n+\t}\n+\n+\t/** keptPaths as a set, kept for the newest version asked: never changed once made, so a view can hold it. */\n+\tkeptPathSet(space: Space, version: number): ReadonlySet<string> | undefined {\n \t\tlet fold = this.#keptPaths.get(space);\n+\t\tif (fold?.version === version) return fold.files;\n \t\tif (!fold || fold.version > version) fold = { version: -1, files: new Set() };\n \t\tconst files = new Set(fold.files);\n \t\tfor (let v = fold.version + 1; v <= version; v++) {\n \t\t\tif (!this.#keptFiles(space, v)) return undefined;\n-\t\t\tconst shape = this.#shapeCache.get(space)!.get(v)!;\n+\t\t\t// Not yet when the version is still being kept (keep asks its views which files exist).\n+\t\t\tconst shape = this.#shapeCache.get(space)?.get(v);\n+\t\t\tif (!shape) return undefined;\n \t\t\tfor (const f of shape.gone) files.delete(f);\n \t\t\tfor (const f of shape.made) files.add(f);\n \t\t}\n \t\tthis.#keptPaths.set(space, { version, files });\n-\t\treturn [...files].sort();\n+\t\treturn files;\n \t}\n \n \t/** Each space's path index (#41): built the first time it's asked for, then kept up as versions land. */"},{"path":"worker/project/project.ts","added":5,"removed":1,"diff":"--- a/worker/project/project.ts\n+++ b/worker/project/project.ts\n@@ -2777,7 +2777,11 @@\n \n \t/** A space at a version: published versions never change, so the key is just their names (#46). */\n \t#viewAt(space: Space, version: number): ReadView {\n-\t\treturn this.#viewKeyed(`v ${space.name}@${version}`, () => this.#at(space, version));\n+\t\tconst view = this.#viewKeyed(`v ${space.name}@${version}`, () => this.#at(space, version));\n+\t\t// Which files it has from the kept path list (abso Capacity, View.knowPaths), as pathsAt answers.\n+\t\tif (view instanceof View && this.#writerStorage && space.name === SHARED)\n+\t\t\tview.knowPaths(() => this.#paths.keptPathSet(space, version));\n+\t\treturn view;\n \t}\n \n \t#sharedView(): ReadView {"},{"path":"worker/project/test/known-paths.test.ts","added":107,"removed":0,"diff":"--- /dev/null\n+++ b/worker/project/test/known-paths.test.ts\n@@ -0,0 +1,107 @@\n+// Whether a file exists, answered without laying it out (abso Capacity, View.knowPaths): a published version's view\n+// on a writer answers from the kept path list, and a draft's view asks its base for every file the draft doesn't\n+// touch. Each must say what the in-memory project says, at every version and in every draft: files deleted or\n+// renamed by a published version, and by a draft, by record and by moving lines.\n+\n+import assert from \"node:assert/strict\";\n+import { test } from \"node:test\";\n+import { storedArray } from \"../../../src/engine/state-source.ts\";\n+import { SqlState } from \"../../../src/engine/test/storage-helper.ts\";\n+import { MemoryStore, Project } from \"../project.ts\";\n+import type { Entry, ProjectStore } from \"../project-types.ts\";\n+\n+function writer() {\n+\tconst storage = new SqlState();\n+\tconst entries = storedArray<Entry>(storage, \"canonical-log\");\n+\tconst store: ProjectStore = {\n+\t\tappend(batch) {\n+\t\t\tfor (const entry of batch) entries.push(entry);\n+\t\t},\n+\t};\n+\treturn new Project(store, { writerStorage: storage });\n+}\n+\n+const AREA = \"export function area(r: number) {\\n  return 3.14 * r * r;\\n}\\n\";\n+const FILES = {\n+\t\"src/shapes.ts\": `// shapes\\n${AREA}`,\n+\t\"src/old-name.ts\": \"export const x = 1;\\n\",\n+\t\"src/gone.ts\": \"export const y = 2;\\n\",\n+\t\"src/keep.ts\": 'import { x } from \"./old-name\";\\n',\n+\t\"notes.md\": \"notes\\n\",\n+};\n+\n+/** Every name to ask about: each path any version or draft has had, and names that never existed. */\n+const NAMES = [\n+\t...Object.keys(FILES),\n+\t\"src/new-name.ts\",\n+\t\"src/geometry.ts\",\n+\t\"src/draft-new.ts\",\n+\t\"src/draft-renamed.ts\",\n+\t\"src/never.ts\",\n+\t\"src/old-name\",\n+\t\"src/old-name.js\",\n+];\n+\n+function history(project: Project) {\n+\tlet t = 0;\n+\tproject.init(FILES, t);\n+\tproject.sync(\"v0\");\n+\t// Version 1: ann deletes a file and renames another with record.\n+\tproject.record(\n+\t\t\"ann\",\n+\t\t{ \"src/gone.ts\": null, \"src/old-name.ts\": null, \"src/new-name.ts\": FILES[\"src/old-name.ts\"] },\n+\t\t++t,\n+\t);\n+\tassert.equal(project.publish(\"ann\", \"Delete gone, rename old-name\", ++t).ok, true);\n+\tproject.sync(\"v1\");\n+\t// Version 2: ann moves area() into a new file by moving its lines.\n+\tproject.edit(\"ann\", { file: \"src/shapes.ts\", old: AREA, new: \"\" }, ++t);\n+\tproject.edit(\"ann\", { file: \"src/geometry.ts\", content: AREA }, ++t);\n+\tassert.equal(project.publish(\"ann\", \"Move area\", ++t).ok, true);\n+\tfor (const agent of [\"v2\", \"bob\", \"cy\", \"dee\", \"eve\"]) project.sync(agent);\n+\t// Drafts over version 2: bob deletes a file, cy renames one with record, dee moves lines into a new file, eve adds one.\n+\tproject.record(\"bob\", { \"src/keep.ts\": null }, ++t);\n+\tproject.record(\"cy\", { \"src/new-name.ts\": null, \"src/draft-renamed.ts\": FILES[\"src/old-name.ts\"] }, ++t);\n+\tproject.edit(\"dee\", { file: \"src/geometry.ts\", old: AREA, new: \"\" }, ++t);\n+\tproject.edit(\"dee\", { file: \"src/draft-new.ts\", content: AREA }, ++t);\n+\tproject.record(\"eve\", { \"src/draft-new.ts\": \"new\\n\" }, ++t);\n+}\n+\n+const exists = (project: Project, agent: string) => {\n+\tconst view = project.draftOf(agent)!.view;\n+\treturn Object.fromEntries(NAMES.map((name) => [name, view.hasFile(name)]));\n+};\n+\n+test(\"whether each file exists, at every version and in every draft, as the in-memory project says\", () => {\n+\tconst oracle = new Project(new MemoryStore());\n+\tconst project = writer();\n+\thistory(oracle);\n+\thistory(project);\n+\tfor (const agent of [\"v0\", \"v1\", \"v2\", \"bob\", \"cy\", \"dee\", \"eve\"]) {\n+\t\t// Before any layout, and again after every file has been read.\n+\t\tassert.deepEqual(exists(project, agent), exists(oracle, agent), agent);\n+\t\tconst view = project.draftOf(agent)!.view;\n+\t\tfor (const path of view.paths()) view.lines(path);\n+\t\tassert.deepEqual(exists(project, agent), exists(oracle, agent), `${agent} after reading`);\n+\t\tassert.deepEqual(view.paths(), oracle.draftOf(agent)!.view.paths(), `${agent} paths`);\n+\t}\n+\t// The cases the test is for, so a history change can't empty it.\n+\tconst at = (agent: string) => exists(oracle, agent);\n+\tassert.equal(at(\"v0\")[\"src/gone.ts\"], true);\n+\tassert.equal(at(\"v1\")[\"src/gone.ts\"], false);\n+\tassert.equal(at(\"v1\")[\"src/old-name.ts\"], false);\n+\tassert.equal(at(\"v1\")[\"src/new-name.ts\"], true);\n+\tassert.equal(at(\"v2\")[\"src/geometry.ts\"], true);\n+\tassert.equal(at(\"bob\")[\"src/keep.ts\"], false);\n+\tassert.equal(at(\"cy\")[\"src/new-name.ts\"], false);\n+\tassert.equal(at(\"cy\")[\"src/draft-renamed.ts\"], true);\n+\tassert.equal(at(\"dee\")[\"src/draft-new.ts\"], true);\n+\tassert.equal(at(\"dee\")[\"src/geometry.ts\"], false);\n+\tassert.equal(at(\"eve\")[\"src/draft-new.ts\"], true);\n+\tfor (const [version, agent] of [\n+\t\t[0, \"v0\"],\n+\t\t[1, \"v1\"],\n+\t\t[2, \"v2\"],\n+\t] as const)\n+\t\tassert.deepEqual(project.pathsAt(version).files, oracle.draftOf(agent)!.view.paths(), `paths at ${version}`);\n+});"}],"ci":null}