Skip to content

workerd schema preload adds about 10 MiB cold heap in client + server bundle #2865

Description

@zackbart

Observation

The workerd shims in both @modelcontextprotocol/client@2.0.0 and @modelcontextprotocol/server@2.0.0 call preloadSchemas() at module scope. In a Connecta Worker-example bundle, removing only those two calls for measurement reduced cold used V8 heap by about 10.03 MiB on average across three fresh local workerd isolates per variant.

Pair Original used heap Without the two preload calls
1 23,184,168 B 12,485,064 B
2 22,998,196 B 12,478,996 B
3 22,846,584 B 12,503,924 B

Environment: Node 26.9.0, Miniflare 4.20260722.0, workerd 1.20260722.1, compatibility date 2025-01-01, nodejs_compat, both SDK packages 2.0.0.

Reproduction and limits

Measurement script, raw observations, and method and interpretation.

The script bundles the Worker example, retains its imported export to prevent tree shaking, answers one synthetic request, then reads Runtime.getHeapUsage from the exact core:user: inspector target. The comparison plugin removes the two shim calls without modifying installed dependencies. Each sample uses a fresh Miniflare instance, disposed afterward. No provider is called or Worker deployed.

This measures cold allocation without forced GC, not retained heap after GC or production isolate churn. HeapProfiler.collectGarbage did not respond within ten seconds in this runtime. We have not verified that removing preload preserves all SDK schema paths on Workers and are not shipping a patch or recommending that workaround.

Could the workerd entry avoid eagerly materializing unused schemas while preserving its no-runtime-code-generation requirements? An upstream supported approach would let consumers benefit without modifying their dependencies.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    v2Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixes

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions