Skip to content

perf(cli): warm up tool registry and MCP on bootstrap to eliminate ~2.5s cold start#8991

Open
Githubguy132010 wants to merge 13 commits intoKilo-Org:mainfrom
Githubguy132010:perf/tool-warmup-cold-start
Open

perf(cli): warm up tool registry and MCP on bootstrap to eliminate ~2.5s cold start#8991
Githubguy132010 wants to merge 13 commits intoKilo-Org:mainfrom
Githubguy132010:perf/tool-warmup-cold-start

Conversation

@Githubguy132010
Copy link
Copy Markdown
Contributor

Context

Fixes #7946.

On the first message in a session, resolveTools() lazily triggers two expensive initializations: ToolRegistry.state() (custom tool scanning + all Tool.init() calls) and MCP.state() (spawning server processes + handshakes). Profiling shows this adds ~2,549ms to the first request, dropping to 1–4ms on every subsequent one.

Implementation

Added ToolRegistry.warmup() to packages/opencode/src/tool/registry.ts:

export async function warmup(): Promise<void> {
  await Promise.allSettled([runPromise((svc) => svc.all()), MCP.tools()])
}
  • svc.all() triggers ToolRegistry.state() initialization — scans config dirs for custom tool files, loads plugins, and calls Tool.init() for every built-in tool (BashTool, SkillTool, TaskTool, etc.), warming their internal InstanceState caches
  • MCP.tools() triggers MCP.state() initialization — connects to all configured MCP servers, spawns processes, and performs handshakes
  • Promise.allSettled is used so a failure in either branch (e.g. an MCP server that refuses to connect) doesn't prevent the other from warming

In packages/opencode/src/project/bootstrap.ts, ToolRegistry.warmup() is called fire-and-forget at the end of InstanceBootstrap():

ToolRegistry.warmup() // fire-and-forget: warm tool registry and MCP connections in background

This runs concurrently with the server finishing startup. By the time the user sends their first message, the caches are already populated and resolveTools() returns in 1–4ms instead of ~2,500ms.

Screenshots

N/A — performance change, no UI impact.

How to Test

Start a fresh session and send a first message. With this change the tool initialization delay (~2.5s) should be gone. You can add a console.time/console.timeEnd around resolveTools() in prompt.ts to confirm the drop from ~2549ms to ~1–4ms on the first call.

Get in Touch

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Githubguy132010 and others added 2 commits April 19, 2026 15:04
….5s cold start

Closes Kilo-Org#7946

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Githubguy132010 Githubguy132010 force-pushed the perf/tool-warmup-cold-start branch from 651fbc0 to ab3c7ac Compare April 19, 2026 13:09
Comment thread packages/opencode/src/tool/registry.ts Outdated
@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot Bot commented Apr 19, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (2 files)
  • packages/opencode/src/project/bootstrap.ts
  • packages/opencode/src/tool/registry.ts

Reviewed by gpt-5.4-20260305 · 862,092 tokens

Hermes Agent and others added 2 commits April 19, 2026 15:37
…de effects during bootstrap

MCP.status() triggers full MCP initialization including starting MCP server
processes and potentially showing auth popups. Using MCP.tools() provides
a side-effect-free warmup that still preloads tool caches, eliminating the
~2.5s cold start without unwanted startup behavior.
MCP.status() was triggering MCP.state() initialization at bootstrap,
connecting all configured MCP servers before the first user prompt.
This caused auth toasts and process spawning at the wrong time.

The ToolRegistry warmup alone eliminates the ~2.5s cold start from
custom-tool scanning and Tool.init() caches. MCP connections now happen
on-demand as before, scoped to the first prompt.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Comment thread packages/opencode/src/project/bootstrap.ts
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.

perf(cli): tool initialization cold start adds ~2.5s to first request

1 participant