Skip to content

perf(electron): load the MCP SDK, fastify and the updater when first used - #13633

Closed
yuxi-liu-wired wants to merge 1 commit into
logseq:masterfrom
yuxi-liu-wired:perf/open-mcp
Closed

yuxi-liu-wired wants to merge 1 commit into
logseq:masterfrom
yuxi-liu-wired:perf/open-mcp

Conversation

@yuxi-liu-wired

Copy link
Copy Markdown
Contributor

The Electron main process loads the MCP SDK and zod, fastify and electron-updater before it creates the main window, through the top-level requires of electron.mcp-server, electron.server, electron.updater and electron.handler. In a CPU profile of a desktop app open, those requires took about 210 ms (MCP SDK and zod/v3), 115 ms (electron-updater) and 65 ms (fastify, @fastify/cors) of the main process's time before the window. None is needed for the window: the API server and MCP are off by default, and the updater is first used after the page loads.

  • electron.mcp-server requires the SDK modules and zod on first use (the first /mcp initialize, or the first MCP server it creates); the tool definitions are built per server from the loaded zod.
  • electron.server/start! requires fastify and @fastify/cors when the API server starts.
  • electron.updater requires electron-updater when it is used, and setup-updater! sets the updater up when the main window's page has finished loading (its teardown is returned as before); electron.handler's :quitAndInstall requires it there too.

Checked in a desktop build: with the API server and MCP turned on, an MCP initialize over HTTP gets a session and tools/list returns listPages, getPage, upsertNodes, searchBlocks, listTags and listProperties; in a CPU profile of the main process before the window, none of the MCP SDK, electron-updater or fastify is loaded.

yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 6, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 8, 2026
@yuxi-liu-wired

Copy link
Copy Markdown
Contributor Author

Measured this optimization with ablations against upstream, using the same shared warm profile, Xvfb, hyperfine, 20 measured runs per build and CPU settings fixed at 100% with turbo enabled.

Whole-command mean ± standard deviation:

  • Upstream baseline: 2.819 ± 0.025 seconds.
  • Lazy translation compilation alone: 2.538 ± 0.026 seconds.
  • Lazy code editor alone: 2.664 ± 0.035 seconds.
  • Lazy MCP/updater dependencies alone: 2.717 ± 0.034 seconds.
  • Translation + code editor: 2.391 ± 0.032 seconds.
  • All three: 2.277 ± 0.017 seconds.
  • Our complete nightly: 2.285 ± 0.031 seconds.

The three changes together reproduce the full fork's startup performance. Launch-to-real-home for the three-change build: 2.077 ± 0.017 seconds versus upstream 2.621 ± 0.025 seconds. Code-block first use was checked using real keyboard events: three backticks mount CodeMirror; typing and selection work.

Ablation base: 22a29b3. Combined patch: d462a777b0. Raw benchmark JSON and per-run stages are retained locally at results/startup/20261008-190710, with individual-change comparisons at 20261008-185448, 20261008-185654, and 20261008-185902.

All three optimizations are already included in published fork-nightly commit 1771ba4. The lazy editor includes the module-registration completion fix.

yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 11, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 13, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 16, 2026
@yuxi-liu-wired
yuxi-liu-wired force-pushed the perf/open-mcp branch 5 times, most recently from 7e3552b to d891597 Compare October 22, 2026 11:01
@yuxi-liu-wired
yuxi-liu-wired force-pushed the perf/open-mcp branch 2 times, most recently from 28f3ac9 to 008ae5d Compare October 25, 2026 11:01
…used

The Electron main process loads the MCP SDK and zod, fastify and electron-updater before it creates the main window, through the top-level requires of `electron.mcp-server`, `electron.server`, `electron.updater` and `electron.handler`. In a CPU profile of a desktop app open, those requires took about 210 ms (MCP SDK and `zod/v3`), 115 ms (`electron-updater`) and 65 ms (`fastify`, `@fastify/cors`) of the main process's time before the window. None is needed for the window: the API server and MCP are off by default, and the updater is first used after the page loads.

- `electron.mcp-server` requires the SDK modules and zod on first use (the first `/mcp` initialize, or the first MCP server it creates); the tool definitions are built per server from the loaded zod.
- `electron.server/start!` requires fastify and `@fastify/cors` when the API server starts.
- `electron.updater` requires electron-updater when it is used, and `setup-updater!` sets the updater up when the main window's page has finished loading (its teardown is returned as before); `electron.handler`'s `:quitAndInstall` requires it there too.

Checked in a desktop build: with the API server and MCP turned on, an MCP `initialize` over HTTP gets a session and `tools/list` returns listPages, getPage, upsertNodes, searchBlocks, listTags and listProperties; in a CPU profile of the main process before the window, none of the MCP SDK, electron-updater or fastify is loaded.
@yuxi-liu-wired

Copy link
Copy Markdown
Contributor Author

Combined into #13872 with the other PRs of this theme, to keep the number of open PRs down; the commits are unchanged there.

@yuxi-liu-wired
yuxi-liu-wired deleted the perf/open-mcp branch November 17, 2026 02:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant