{"version":83,"agent":"speed","message":"where lays out an agent's view only when it reads it\n\ndraftOf's view is now built on first use. where asks every agent for its draft, most agents have no changes, and a big project has more agents than the view cache holds (32), so each call built every view again. On a 17,000-entry log with 52 agents, where went from about 730 ms a call to about 10 ms. Test: worker/project/test/where-many-agents.test.ts.","time":1791615253261,"timeIso":"2026-10-10T06:54:13.261Z","changes":2,"change":880,"files":["worker/project/project.ts","worker/project/test/where-many-agents.test.ts"],"draft":null,"diff":[{"path":"worker/project/project.ts","added":14,"removed":3,"diff":"--- a/worker/project/project.ts\n+++ b/worker/project/project.ts\n@@ -391,10 +391,21 @@\n \t\treturn [...this.#agents.keys()].sort();\n \t}\n \n-\t/** An agent's unpublished changes, oldest first, and its view (its space at its base plus its changes). Read only. */\n-\tdraftOf(agentName: string): { atoms: AtomId[]; view: View } | undefined {\n+\t/**\n+\t * An agent's unpublished changes, oldest first, and its view (its space at its base plus its changes). Read only.\n+\t * The view is laid out on first use: where asks every agent, most have no changes, and a big project has more\n+\t * agents than the view cache holds, so building every view cost each call about 0.7 s.\n+\t */\n+\tdraftOf(agentName: string): { atoms: AtomId[]; readonly view: View } | undefined {\n \t\tconst agent = this.#agents.get(agentName);\n-\t\treturn agent && { atoms: this.#draft(agent), view: this.#agentView(agent) };\n+\t\tif (!agent) return undefined;\n+\t\tconst view = () => this.#agentView(agent);\n+\t\treturn {\n+\t\t\tatoms: this.#draft(agent),\n+\t\t\tget view() {\n+\t\t\t\treturn view();\n+\t\t\t},\n+\t\t};\n \t}\n \n \t/** The shared version an atom was published in, or undefined while it's only in a draft. */"},{"path":"worker/project/test/where-many-agents.test.ts","added":29,"removed":0,"diff":"--- /dev/null\n+++ b/worker/project/test/where-many-agents.test.ts\n@@ -0,0 +1,29 @@\n+// Where asks every agent for its draft, and a big project has more agents than\n+// the view cache holds (32). An agent's view is laid out only when it's read,\n+// so agents with no changes cost nothing, and the answer stays what it was.\n+\n+import assert from \"node:assert/strict\";\n+import { test } from \"node:test\";\n+import { MemoryStore, Project } from \"../project.ts\";\n+import { where } from \"../where.ts\";\n+\n+test(\"where answers right with more agents than the view cache holds, and lays out no view for an empty draft\", () => {\n+\tconst store = new MemoryStore();\n+\tconst project = new Project(store);\n+\tproject.init({ \"a.ts\": \"one\\ntwo\\nthree\\n\" }, 0);\n+\tfor (let i = 0; i < 40; i++) project.sync(`idle-${i}`);\n+\tproject.edit(\"busy\", { file: \"a.ts\", old: \"two\\n\", new: \"two!\\n\" }, 1);\n+\n+\tconst answer = where(project);\n+\tassert.deepEqual(Object.keys(answer.files), [\"a.ts\"]);\n+\tassert.deepEqual(\n+\t\tanswer.files[\"a.ts\"]!.map((s) => [s.agent, s.lines, s.changes]),\n+\t\t[[\"busy\", [[2, 2]], 1]],\n+\t);\n+\tassert.deepEqual(where(Project.load(store.entries, new MemoryStore())), answer);\n+\n+\tconst idle = project.draftOf(\"idle-0\")!;\n+\tassert.deepEqual(idle.atoms, []);\n+\tassert.equal(typeof Object.getOwnPropertyDescriptor(idle, \"view\")?.get, \"function\");\n+\tassert.equal(idle.view.text(\"a.ts\"), \"one\\ntwo\\nthree\\n\");\n+});"}],"ci":null}