Repository navigation
perf(mcp): keep the watcher and an idle query worker out of startup - #419
Merged
Merged
Conversation
Every `serve --mcp` process loaded the file watcher, and through it all of extraction and resolution, because project-lifecycle imported two small names from the sync barrel. Import them from their own modules instead; LockUnavailableError moves to sync/lock-unavailable.ts so the watcher and the lifecycle share one class. A query pool with no default project no longer starts a worker at once. Its first read call that names a project starts one and runs in-process meanwhile, as calls already do before a worker is ready.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes
serve --mcpno longer loads the file watcher, extraction or resolution at startup.project-lifecycle.tsimportedLockUnavailableErrorandwatchDisabledReasonfrom thesyncbarrel, and the barrel pulls in the watcher and everything it uses: about 125 modules. Both names now come from small modules.LockUnavailableErrormoved tosrc/sync/lock-unavailable.ts, and the watcher re-exports it, so there is still one class.Measured
Resident memory of a fresh
serve --mcpprocess 8 seconds after the handshake, under Bun 1.4.2 on Linux. Each value is the range of three runs. The base is54188d0cbuilt the same way.The proxy session loads 66 fewer modules. The direct session drops from 217 modules to 93 and runs one less thread. Sessions with a project open still load these modules when they start watching, so their memory is unchanged.
Not included
A proxy session still loads the engine and tool handlers, which it uses only when the daemon is unreachable. Splitting them out would save about 5 MiB more per proxy session (prototype measurement). It needs an asynchronous engine factory, because the source-level tests cannot follow a lazy
require()of a TypeScript sibling. I left it for a separate change.Checks
npm run build, thennpx vitest run: 672 files, 8,591 tests passed, 39 skipped.npm run test:bun: 37 failures across 10 files. The same tests fail on the unchanged base in this environment, by name. They includeruntime-control,ui-highlight,writer-lockandgrammar-load-failure. One base run failed 36, so one of them is flaky.__tests__/mcp-startup-modules.test.tsfails if the server entry loads the watcher, extraction, resolution or the CodeGraph core again. Aquery-poolunit test coverswarm(). The real-project pool test now expects no worker before the first call in a session with no default project.README rows checked
Summary by CodeRabbit