Drop eager MCP schema preload in workerd isolates - #1742
Merged
Conversation
Contributor
Cloudflare previewTorn down — the PR is closed. |
RhysSullivan
marked this pull request as ready for review
August 25, 2026 21:14
This was referenced Aug 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since #1733, p95 on authenticated API routes roughly doubled (2-2.5s -> 4.5-5.5s) and isolate reuse halved (~5-7 -> ~3 requests per isolate), version-correlated in traces: in the same 15-minute window the old version served p95 2.4s while #1733's deploy served 5.3s.
Mechanism:
@modelcontextprotocol/client's workerd shim runspreloadSchemas()at module eval, building both protocol eras' zod schemas in every isolate. Measured under the workerd export condition: importing the barrel costs ~30MB heap upstream vs ~11MB with this patch. That ~19MB per-isolate baseline is what pressures Cloudflare into evicting isolates, collapsing reuse; every extra cold isolate then eats the first-await startup penalty on whatever authenticated request lands on it.Fix:
bun patchthe package to drop the eager preload. Schema construction stays lazy and memoized (upstream's documented default on other runtimes); the first MCP use in an isolate pays ~15ms CPU once. A sentinel inscripts/check-patched-deps.tsguards against the patch silently not applying, since a revert would reproduce the incident with no functional signal.Worth an upstream issue: the warm-up default is actively harmful for large-bundle workers; it should be opt-in.
Verify after deploy: requests/isolate back to ~5-7 and
http.serverp95 back under ~2.5s in the executor-cloud dataset.