How I built a startup profiler for my desktop AI companion: 256 records, 1 decimal, and the slowest entry it can delete
Ankita AI is a desktop AI assistant by Krish Verma, and it boots with a small crowd: a handful of built-in skills, whatever MCP servers you connected, and a few custom skill folders. When startup felt slow, I had no data — just a hunch and a list of suspects. So I built a profiler that times every plugin and skill as it loads, and prints the answer where I can act on it. It lives in Ankita, the open-source companion at ankita-sable.vercel.app.
The decision: time the load, at the load site
The profiler is one 20-line class, StartupProfile in src/core/startup-profile.mjs. It holds a Map of records, keyed kind:name, capped at 256 entries per process. Each record is a name, a duration in milliseconds shown to 1 decimal place, and a status — ready or error. Nothing else. No arguments, no error text, no connection strings: the report is names, durations, and statuses, because a timing report that leaks your MCP server's command line is a bug, not a feature.
There are exactly two call sites, and both follow the same shape: take the timestamp, do the work, record in finally.
In src/integrations/mcp-manager.mjs, connect() stamps startupProfile.now() before client.connect(), and the finally block calls finish('plugin', serverId, started, startupStatus). The status defaults to 'error' and only becomes 'ready' after the handshake and the host setup both succeed. A server that fails to launch still gets a row — with its failure time, not silence.
In src/core/skills.mjs, loadSkillCatalog() does the same per skill file: stamp, parse the SKILL.md, finish('skill', name, started, status) in finally. A malformed skill — bad frontmatter, a description outside 10–300 characters, a body over 12,000 characters — is recorded as error and stays visible in settings instead of disappearing. The parse is timed even when it fails, so a skill that is slow and broken shows up twice: once in the error list, once in the timings.
Where the numbers show up
The terminal prints the whole report at boot, dimmed, right under the config summary (src/core/cli.mjs): Startup timings (ms): plugin composio 412.3 ms (ready; /mcp disable composio) · skill bug-repro 3.1 ms (ready; Plugins → Skills → Disable). Slowest first — snapshot() sorts by duration descending — so the culprit is the first thing you read.
The desktop shows the same report in Plugins → Skills, under a "Startup timings" disclosure with a Refresh timings button (SkillsSection.tsx). Refreshing calls getStartupProfile over IPC, which re-runs loadSkills() and re-formats the live map (desktop/electron/engine.mjs). And every entry points at its own off switch: a plugin row names /mcp disable <name>, a skill row points to Plugins → Skills → Disable. A timing you cannot act on is trivia; the report is built so the fix is one command away.
Two deliberate behaviours worth naming. First, repeated cache hits keep the original measurements — loadSkillCatalog() returns the cached parse when the file stamps match, so a skill's first-load number stays until a reload replaces it. Second, a cold remote package download is timed as-is: the profiler records the network, it does not promise a fixed startup duration. A slow number on an npx server might be your network, not the server.
The flaw I already found in it
Here is the part I would rather a reviewer found than shipped quietly: the 256-record cap evicts the oldest entry, not the fastest. finish() deletes the first key in the map while the size is over the limit. In a long session with many skill reloads, the slowest component — the one this profiler exists to catch — can be evicted while fast, recent entries survive. The report silently stops showing the thing you built it to find. The cache-hit rule makes it worse in the other direction: a skill that got faster after an edit still shows its first-load number until reload, so the report can also overstate a problem that no longer exists.
Load time has a third blind spot: it is not first-use latency. A plugin can connect in 40 ms and take 10 seconds on its first real tool call, and this profiler will call it fast. Timing the handshake is not timing the work.
The verification I have: the focused profiler, skill, and plugin checks passed 18/18; a live HTTP handshake and a failed process launch both returned measured statuses; npm run desktop:build passed; and the real Vite renderer in Chromium, with a fixture IPC transport calling the real engine, returned STARTUP_PROFILE_UI_LIVE report=true refresh=true existingDisable=true rendererErrors=0. One honest gap in that list: the packaged Electron binary itself was not exercised by the renderer check.
The question
I built a profiler to find the slowest thing at startup, and its own eviction rule can delete the slowest thing. Is the fix to evict the fastest entry instead of the oldest — keeping the report honest about what is slow — or is that just trading one lie for another, since a stale slow number from an hour ago is no more true than a missing one? And should the profiler time first use as well as load, or does that turn a boot report into a session report? Tell me I'm wrong: where would you draw the line?
— Krish Verma, creator of Ankita AI

