Skip to content

perf(cloudflare): reduce Worker startup module closure - #3199

Open
ascorbic wants to merge 6 commits into
mainfrom
codex/reduce-worker-startup
Open

ascorbic wants to merge 6 commits into
mainfrom
codex/reduce-worker-startup

Conversation

@ascorbic

Copy link
Copy Markdown
Collaborator

What does this PR do?

Reduces the module graph evaluated when an EmDash Cloudflare Worker starts. The Worker entry exports PluginBridge directly, loads scheduled maintenance only when a Cron Trigger runs, and loads the bridge's repository runtime on the first sandbox RPC through a narrow emdash/plugins/host entry. Existing emdash and @emdash-cms/cloudflare/worker exports remain compatible.

Adds a production-build guard that walks static imports from the generated Worker entry. CI now rejects more than 30 eager modules, more than 2 MB of eager JavaScript, or eager WXR, Tiptap/ProseMirror, plugin-registry, and media-maintenance sources.

The query-count harness now disables Astro 7.3's separate dev and preview background modes so local agent runs capture the same query events as CI.

Discussion: #3143

Measured on the production-built Cloudflare starter with Wrangler 4.125.0, using one discarded warm-up and nine startup samples:

Metric Before After Change
Eager modules 144 18 -87.5%
Eager bytes 5,721,716 1,734,286 -69.7%
Startup active CPU median 44.0 ms 19.0 ms -56.8%
Startup CPU range 41.0–45.3 ms 18.7–20.1 ms

The narrow bridge runtime adds 928 KB on the first sandbox RPC, keeping startup plus first plugin use at approximately 2.66 MB instead of loading the 5.72 MB root barrel. Testing Cloudflare's new_module_registry flag increased the optimized median to 35.4 ms, so this PR does not enable it.

Type of change

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

The localization, new-feature, and screenshot items are not applicable: this changes Worker startup timing without adding admin UI or a new product capability.

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: OpenAI Codex (GPT-5)

Screenshots / test output

Not applicable — no UI changes.

Validated on the exact merged origin/main head with:

  • pnpm install --frozen-lockfile
  • pnpm build
  • pnpm typecheck
  • pnpm lint
  • pnpm format:check
  • pnpm --dir packages/cloudflare test — 436 passed
  • focused core content-access tests — 102 passed
  • production workerd bridge tests — 31 passed
  • pnpm query-counts --target d1 — count and SQL snapshots match
  • pnpm --dir templates/starter-cloudflare build
  • pnpm startup:check — 18 modules, 1,734,286 bytes
  • wrangler check startup — 19.0 ms median across nine measured runs

The package API linter (publint) passes for both changed packages. The secondary attw --pack process crashes after packing with Cannot read properties of undefined (reading 'filename') for both packages and does not report a package diagnostic.

@changeset-bot

changeset-bot Bot commented Sep 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1772c0a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 12 packages
Name Type
@emdash-cms/cloudflare Patch
emdash Patch
@emdash-cms/plugin-test Patch
@emdash-cms/sandbox-workerd Patch
@emdash-cms/admin Patch
@emdash-cms/auth Patch
@emdash-cms/blocks Patch
create-emdash Patch
@emdash-cms/gutenberg-to-portable-text Patch
@emdash-cms/x402 Patch
@emdash-cms/auth-atproto Patch
@emdash-cms/plugin-embeds Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Sep 18, 2026

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/admin@3199

@emdash-cms/auth

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/auth@3199

@emdash-cms/auth-atproto

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/auth-atproto@3199

@emdash-cms/blocks

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/blocks@3199

@emdash-cms/cloudflare

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/cloudflare@3199

@emdash-cms/contentful-to-portable-text

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/contentful-to-portable-text@3199

emdash

npm i https://pkg.pr.new/emdash-cms/emdash@3199

create-emdash

npm i https://pkg.pr.new/emdash-cms/emdash/create-emdash@3199

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/gutenberg-to-portable-text@3199

@emdash-cms/plugin-cli

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-cli@3199

@emdash-cms/plugin-test

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-test@3199

@emdash-cms/plugin-types

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-types@3199

@emdash-cms/registry-client

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/registry-client@3199

@emdash-cms/registry-lexicons

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/registry-lexicons@3199

@emdash-cms/registry-loader

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/registry-loader@3199

@emdash-cms/registry-moderation

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/registry-moderation@3199

@emdash-cms/registry-verification

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/registry-verification@3199

@emdash-cms/sandbox-workerd

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/sandbox-workerd@3199

@emdash-cms/x402

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/x402@3199

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-ai-moderation@3199

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-atproto@3199

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-audit-log@3199

@emdash-cms/plugin-color

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-color@3199

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-embeds@3199

@emdash-cms/plugin-field-kit

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-field-kit@3199

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-forms@3199

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-webhook-notifier@3199

commit: 1772c0a

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 18, 2026

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview URL: https://codex-reduce-worker-startup.try.emdashcms.com, https://codex-reduce-worker-startup-emdash-playground.emdash-cms.workers.dev (commit 1772c0a)

This URL reflects your latest Preview deployment

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://1cb19c7a.try.emdashcms.com, https://1cb19c7a-emdash-playground.emdash-cms.workers.dev 1772c0a 2026-09-18T12:40:27.087Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://ac01ec9f.try.emdashcms.com, https://ac01ec9f-emdash-playground.emdash-cms.workers.dev 45b69b0 2026-09-18T12:20:34.909Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://1774d1f3.try.emdashcms.com, https://1774d1f3-emdash-playground.emdash-cms.workers.dev 23b229f 2026-09-18T11:40:00.721Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://2d8501a0.try.emdashcms.com, https://2d8501a0-emdash-playground.emdash-cms.workers.dev 8c6f07e 2026-09-18T10:52:32.272Z Visit the dashboard ↗

@github-actions

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot added size/L and removed size/XL labels Sep 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant