perf: query workers skip the extraction and resolution stacks

Merged
BO
1mo ago
+2331-2273

Item 1E. §5.45 found each query worker holding ~96 MB of anonymous memory. Most of it was code the worker never runs.

Cause. Loading the library through src/index.ts pulled 187 modules (4.5 MB of JavaScript: the tree-sitter extractors, the callback synthesizer, the name matcher, the resolver). Every open also built an extraction orchestrator and a resolver. A query worker only reads the graph.

Change:

  • The CodeGraph class moved to src/codegraph.ts. src/index.ts stays the public entry with every export unchanged, and hands the extraction, resolution and watcher modules to the class through provideStacks.
  • A caller that loads codegraph.ts directly loads those modules on first use. That means the query worker, the MCP engine and the ToolHandler's cross-project open, which now require ../codegraph instead of ../index.
  • The orchestrator and resolver are built on first use and reset when the layers are rewired after a reopen.

Measured (the bloc corpus, daemon mode, the same 8-way explore burst as §5.45):

beforeafter
modules a worker loads18760
RSS added by that load+44 MB+25 MB
idle daemon, anonymous148 MB109 MB
after the burst, anonymous531 MB (5 workers)303 MB (6 workers)
per extra worker~96 MB~32 MB

AGENTS.md is updated for the new file layout, and the ledger has §5.46 and a CHANGELOG Fixes entry. One test sampled a call line from the engine's own src/index.ts; it now reads src/codegraph.ts, as its comment asked for when the file moved.

Gate: full suite, 305 files and 5,190 tests.