Collisions step 1: whether a file exists, without laying it out (abso Capacity, issue 664). Version 245 of shared· capacity· Oct 15 (2026-10-15 16:02 UTC) · Not checked
A 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.
On 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.
test/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.
Version 244 · Files at version 245
4 files, 151 lines added, 4 removed.
--- a/src/engine/view.ts
+++ b/src/engine/view.ts
@@ -49,7 +49,14 @@
49 49 /** Structural read boundary shared by historical and transaction-bound projections. */ 50 50 export type ReadView = Omit< 51 51 Pick<View, keyof View>, 52 − "sameText" | "visibleCount" | "shareMoves" | "shareFiles" | "fileOfNumber" | "lineNumberOf" | "visibleWriters"
54 61 sameText(path: string, other: ReadView): boolean; @@ -427,6 +434,17 @@
427 434 this.#filesFrom = { from, except }; 429 436 #filesFrom: { from: View; except: () => ReadonlySet<string> | undefined } | null | undefined; 439 + * The files this view's set has, from what the project keeps for a published version (abso Capacity): hasFile 440 + * answers from it, not a layout of the file. Collisions resolving an import tried up to seven names, and each one 441 + * laid its file out. `paths` is asked once, when first needed; undefined lays files out as before. 443 + knowPaths(paths: () => ReadonlySet<string> | undefined): void { 444 + if (this.#pathsFrom === undefined) this.#pathsFrom = paths; 446 + #pathsFrom: (() => ReadonlySet<string> | undefined) | undefined; 447 + #knownPaths: ReadonlySet<string> | null | undefined; 430 448 #filesShared: { from: View; except: ReadonlySet<string> } | null | undefined; 431 449 #sharedFiles(): { from: View; except: ReadonlySet<string> } | null { 432 450 if (this.#filesShared === undefined) { @@ -899,6 +917,15 @@
900 918 /** Whether the file exists in this projection (has a visible line). */ 901 919 hasFile(path: string): boolean { 920 + if (!this.#files.has(path)) { 921 + // A file the draft doesn't touch exists as it does in the base; a published version's files are kept. 922 + const shared = this.#filesFrom === undefined ? null : this.#sharedFiles(); 923 + if (shared && !shared.except.has(path)) return shared.from.hasFile(path); 924 + if (this.#pathsFrom !== undefined) { 925 + if (this.#knownPaths === undefined) this.#knownPaths = this.#pathsFrom() ?? null; 926 + if (this.#knownPaths) return this.#knownPaths.has(path); 902 929 const attrs = this.attrs(path); 903 930 return attrs.exists || attrs.link !== null || attrs.blob !== null || this.#file(path).vis.length > 0; --- a/worker/project/pathindex.ts
+++ b/worker/project/pathindex.ts
@@ -50,17 +50,26 @@
50 50 * then the caller lays the version out. 52 52 keptPaths(space: Space, version: number): string[] | undefined { 53 + const files = this.keptPathSet(space, version); 54 + return files && [...files].sort(); 57 + /** keptPaths as a set, kept for the newest version asked: never changed once made, so a view can hold it. */ 58 + keptPathSet(space: Space, version: number): ReadonlySet<string> | undefined { 53 59 let fold = this.#keptPaths.get(space); 60 + if (fold?.version === version) return fold.files; 54 61 if (!fold || fold.version > version) fold = { version: -1, files: new Set() }; 55 62 const files = new Set(fold.files); 56 63 for (let v = fold.version + 1; v <= version; v++) { 57 64 if (!this.#keptFiles(space, v)) return undefined; 58 − const shape = this.#shapeCache.get(space)!.get(v)!;
65 + // Not yet when the version is still being kept (keep asks its views which files exist). 66 + const shape = this.#shapeCache.get(space)?.get(v); 67 + if (!shape) return undefined; 59 68 for (const f of shape.gone) files.delete(f); 60 69 for (const f of shape.made) files.add(f); 62 71 this.#keptPaths.set(space, { version, files }); 63 − return [...files].sort();
66 75 /** Each space's path index (#41): built the first time it's asked for, then kept up as versions land. */ --- a/worker/project/project.ts
+++ b/worker/project/project.ts
@@ -2777,7 +2777,11 @@
2778 2778 /** A space at a version: published versions never change, so the key is just their names (#46). */ 2779 2779 #viewAt(space: Space, version: number): ReadView { 2780 − return this.#viewKeyed(`v ${space.name}@${version}`, () => this.#at(space, version));
2780 + const view = this.#viewKeyed(`v ${space.name}@${version}`, () => this.#at(space, version)); 2781 + // Which files it has from the kept path list (abso Capacity, View.knowPaths), as pathsAt answers. 2782 + if (view instanceof View && this.#writerStorage && space.name === SHARED) 2783 + view.knowPaths(() => this.#paths.keptPathSet(space, version)); 2783 2787 #sharedView(): ReadView { --- /dev/null
+++ b/worker/project/test/known-paths.test.ts
@@ -0,0 +1,107 @@
1 + // Whether a file exists, answered without laying it out (abso Capacity, View.knowPaths): a published version's view 2 + // on a writer answers from the kept path list, and a draft's view asks its base for every file the draft doesn't 3 + // touch. Each must say what the in-memory project says, at every version and in every draft: files deleted or 4 + // renamed by a published version, and by a draft, by record and by moving lines. 6 + import assert from "node:assert/strict"; 7 + import { test } from "node:test"; 8 + import { storedArray } from "../../../src/engine/state-source.ts"; 9 + import { SqlState } from "../../../src/engine/test/storage-helper.ts"; 10 + import { MemoryStore, Project } from "../project.ts"; 11 + import type { Entry, ProjectStore } from "../project-types.ts"; 14 + const storage = new SqlState(); 15 + const entries = storedArray<Entry>(storage, "canonical-log"); 16 + const store: ProjectStore = { 18 + for (const entry of batch) entries.push(entry); 21 + return new Project(store, { writerStorage: storage }); 24 + const AREA = "export function area(r: number) {\n return 3.14 * r * r;\n}\n"; 26 + "src/shapes.ts": `// shapes\n${AREA}`, 27 + "src/old-name.ts": "export const x = 1;\n", 28 + "src/gone.ts": "export const y = 2;\n", 29 + "src/keep.ts": 'import { x } from "./old-name";\n', 30 + "notes.md": "notes\n", 33 + /** Every name to ask about: each path any version or draft has had, and names that never existed. */ 35 + ...Object.keys(FILES), 39 + "src/draft-renamed.ts", 45 + function history(project: Project) { 47 + project.init(FILES, t); 49 + // Version 1: ann deletes a file and renames another with record. 52 + { "src/gone.ts": null, "src/old-name.ts": null, "src/new-name.ts": FILES["src/old-name.ts"] }, 55 + assert.equal(project.publish("ann", "Delete gone, rename old-name", ++t).ok, true); 57 + // Version 2: ann moves area() into a new file by moving its lines. 58 + project.edit("ann", { file: "src/shapes.ts", old: AREA, new: "" }, ++t); 59 + project.edit("ann", { file: "src/geometry.ts", content: AREA }, ++t); 60 + assert.equal(project.publish("ann", "Move area", ++t).ok, true); 61 + for (const agent of ["v2", "bob", "cy", "dee", "eve"]) project.sync(agent); 62 + // Drafts over version 2: bob deletes a file, cy renames one with record, dee moves lines into a new file, eve adds one. 63 + project.record("bob", { "src/keep.ts": null }, ++t); 64 + project.record("cy", { "src/new-name.ts": null, "src/draft-renamed.ts": FILES["src/old-name.ts"] }, ++t); 65 + project.edit("dee", { file: "src/geometry.ts", old: AREA, new: "" }, ++t); 66 + project.edit("dee", { file: "src/draft-new.ts", content: AREA }, ++t); 67 + project.record("eve", { "src/draft-new.ts": "new\n" }, ++t); 70 + const exists = (project: Project, agent: string) => { 71 + const view = project.draftOf(agent)!.view; 72 + return Object.fromEntries(NAMES.map((name) => [name, view.hasFile(name)])); 75 + test("whether each file exists, at every version and in every draft, as the in-memory project says", () => { 76 + const oracle = new Project(new MemoryStore()); 77 + const project = writer(); 80 + for (const agent of ["v0", "v1", "v2", "bob", "cy", "dee", "eve"]) { 81 + // Before any layout, and again after every file has been read. 82 + assert.deepEqual(exists(project, agent), exists(oracle, agent), agent); 83 + const view = project.draftOf(agent)!.view; 84 + for (const path of view.paths()) view.lines(path); 85 + assert.deepEqual(exists(project, agent), exists(oracle, agent), `${agent} after reading`); 86 + assert.deepEqual(view.paths(), oracle.draftOf(agent)!.view.paths(), `${agent} paths`); 88 + // The cases the test is for, so a history change can't empty it. 89 + const at = (agent: string) => exists(oracle, agent); 90 + assert.equal(at("v0")["src/gone.ts"], true); 91 + assert.equal(at("v1")["src/gone.ts"], false); 92 + assert.equal(at("v1")["src/old-name.ts"], false); 93 + assert.equal(at("v1")["src/new-name.ts"], true); 94 + assert.equal(at("v2")["src/geometry.ts"], true); 95 + assert.equal(at("bob")["src/keep.ts"], false); 96 + assert.equal(at("cy")["src/new-name.ts"], false); 97 + assert.equal(at("cy")["src/draft-renamed.ts"], true); 98 + assert.equal(at("dee")["src/draft-new.ts"], true); 99 + assert.equal(at("dee")["src/geometry.ts"], false); 100 + assert.equal(at("eve")["src/draft-new.ts"], true); 101 + for (const [version, agent] of [ 106 + assert.deepEqual(project.pathsAt(version).files, oracle.draftOf(agent)!.view.paths(), `paths at ${version}`);