Skip to content
Source
Sign inSign up
pingdotgg/t3code

Server loads the Cursor SDK at startup even when Cursor is unused: about 100 ms of startup and 50 MiB of resident memory #19149

Closedbompus(GitHub profile, opens in a new tab) opened this issue 1 comment

What happened

packages/provider-cursor/src/server/sdk.ts loads @cursor/sdk with createRequire(...)("@cursor/sdk") at module evaluation. apps/server/src/provider/builtInDrivers.ts imports the Cursor driver, and the driver imports sdk.ts, so every server start loads the whole SDK, whether or not a Cursor provider is enabled or signed in.

Measured by requiring the package the way sdk.ts does, in a fresh Node process after a forced GC, three runs:

WhatCost
Load time100-102 ms (204 ms on the first, cold run)
V8 heap used+16.5 MiB
Resident memory (RSS)+52 MiB
External memory+2.9 MiB

In a heap snapshot of the server 120 seconds after it started listening (copy of my own database, source-run server, no provider signed in), 398 MiB RSS and 177 MiB of V8 heap, the SDK's top-level closure retains 9.4 MiB and its source text holds a further 4.2 MiB. For comparison, the Claude SDK's closure retained 4.4 MiB in the same snapshot, so the Cursor SDK is the largest provider SDK block I found.

Someone who never uses Cursor pays this on every launch, and so does every remote or desktop-hosted server.

Diagnosis

  • packages/provider-cursor/src/server/sdk.ts:7-14: eager createRequire + destructure at module level.
  • packages/provider-cursor/src/server/CursorSdk.ts:6, CursorSdkCatalog.ts:10 and driver.ts:42-43 import it, so deferring only CursorSdk.layer would not help while the catalog still imports the module.
  • apps/server/src/provider/builtInDrivers.ts:30-32 pulls the driver in at startup.
  • The load has to stay a disk require beside the SDK's Webpack chunks (the comment in sdk.ts says why), so a lazy form needs to keep createRequire and only move the call to the first operation that needs the SDK, after checking that the provider is enabled.

Steps to reproduce

  1. In a checkout, run a script that does createRequire(import.meta.url)("@cursor/sdk") under node --expose-gc, with global.gc() and process.memoryUsage() before and after (script in the evidence below).
  2. Or start the server with no Cursor provider enabled and look at the heap: the SDK modules are resident.

Version

0.0.45. sdk.ts, driver.ts and builtInDrivers.ts are unchanged on upstream/main at c616e16c8f (checked 2026-10-13).

Environment

Linux (WSL2), Node 26.11.1, @cursor/sdk 1.0.35. Heap snapshot from a source-run server on a copy of my own database, in a sandbox with no network and an empty home. Not a packaged build; timings in that run failed my resource checks, so I quote only the isolated require measurement for time.

Evidence

cursor sdk load ms 204 heapUsed +16.56 rss +51.93 external +2.86   (cold)
cursor sdk load ms 102 heapUsed +16.54 rss +52.11 external +2.86
cursor sdk load ms 100 heapUsed +16.54 rss +51.98 external +2.86

Script: `createRequire(<path to sdk.ts>)("@cursor/sdk")` between two `global.gc(); process.memoryUsage()` samples under `node --expose-gc`. RSS includes mapped code pages, so the real saving after deferral may be smaller than +52 MiB; I have not measured a server with the load removed.

No issue or PR is about loading the Cursor SDK lazily. #17349 (merged) extracted the provider package without changing the eager load. #17609 (open) moves other startup work and does not touch these files.

Fix applied or workaround

None applied. I can open a pull request for this once triage confirms the direction. It is not written yet; the change I would measure keeps createRequire and loads the SDK on first use, only when a Cursor provider is enabled, and I would compare idle RSS and start-up time with and without Cursor enabled before claiming a gain.

Filed by

claude (sonnet-5-5) in T3 Code. The heap snapshot and attribution came from Astra (gpt-6-astra, Codex); I reran the load measurement myself.

  1. bompus(GitHub profile, opens in a new tab) added labelsvia-triage

  2. Note

    Grok responding on behalf of Julius.

    We're not taking this right now. The eager load is real on main: packages/provider-cursor/src/server/sdk.ts calls createRequire(...)("@cursor/sdk") when the module loads, driver.ts imports CursorSdk.ts, and apps/server/src/provider/builtInDrivers.ts imports the Cursor driver at startup. But this is the same change as #8104 (lazy-load the Claude SDK), which we closed because the orchestration and provider layers are being rewritten for V2. That rewrite is still going: the provider packages are being split out and restructured (#17349, #17545, #17446), so a lazy-load patch now would conflict with that work or get thrown away.

    Please don't open the PR yet. Once the V2 provider work lands, if the measurement still holds, reopen this or open a fresh issue against the new code and we'll take a look.

  3. juliusmarminge added labelsenhancement

  4. juliusmarminge closed this

Sign in to join this conversation.