Skip to content

feat(perf-kit): Cloudflare Worker startup mode - #11188

Merged
IWANABETHATGUY merged 4 commits into
mainfrom
feat/metrics-lab-worker
Nov 4, 2026
Merged

IWANABETHATGUY merged 4 commits into
mainfrom
feat/metrics-lab-worker

Conversation

@IWANABETHATGUY

@IWANABETHATGUY IWANABETHATGUY commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Measure a Vite-built Cloudflare Worker's startup under the app's own workerd and attribute it to modules, with the loop the browser and node modes have: worker-config writes a Vite config that puts the rolldown metrics report on every environment; worker-scan times the main module's import on fresh workerd instances minus an empty-import floor, hits the pinned requests on the real entry, profiles the import, and takes precise coverage from inside the isolate (wrangler >= 4.108.0, or --tools <dir> for that run); worker-attrib charges startup CPU to the evaluating module from a preserveModules build; why <module> lists the importers and the chain; cut --root a,b keeps Durable Object class modules eager so the cut lands below them.

cloudflare/agents-starter after one scan:

[consolidated] 5 cold runs (fresh workerd each)
startup 23ms (p75 24ms) | floor 4ms | app 19ms | instance boot 87ms (not counted)
guard: PASS
first requests on the real entry (startup already done; a deferred module loads on its first hit):
  /                            200      6ms  785 bytes
  /agents/chat-agent/default   404      9ms  15 bytes
startup CPU (profile): active 24ms = app modules 10ms (57.1%) + runtime 3ms + engine 4ms + parse/compile "(program)" 4ms; GC 4ms; 168 samples
  top self-time at startup:
          5ms  ../../node_modules/zod/v4/core/core.js
          4ms  (engine: gc)
          3ms  ../../node_modules/zod/v4/classic/schemas.js
          3ms  (unmapped)
          1ms  ../../node_modules/zod/v4/core/util.js
          1ms  ../../node_modules/zod/v4/core/schemas.js
  3ms sits in chunk top-level code V8 gave no line ticks for - `node harness.mjs worker-attrib` on an attribution build charges it to the evaluating module
evaluated at startup: 547.3KB of 1940.2KB in the static closure (183 modules, 28% executed); 4 runtime module(s) loaded (node-internal:internal_inspector, cloudflare:workers, node:async_hooks, node:diagnostics_channel)
cold at startup - in the closure, never executed to start (2):
      24.5KB  ../../node_modules/@cfworker/json-schema/dist/esm/validate.js
       4.3KB  ../../node_modules/zod/v3/locales/en.js
parsed but mostly not executed at startup (libraries run a slice of themselves at import; the rest is load cost):
     202.3KB idle of   269.3KB   25% executed  ../../node_modules/agents/dist/index.js
     172.5KB idle of   184.0KB    6% executed  ../../node_modules/ai/dist/index.mjs
     102.0KB idle of   152.7KB   33% executed  ../../node_modules/@cloudflare/ai-chat/dist/index.js
      75.5KB idle of    84.7KB   11% executed  ../../node_modules/zod/v3/types.js
      64.9KB idle of    77.0KB   16% executed  ../../node_modules/workers-ai-provider/dist/index.mjs
      62.9KB idle of   120.8KB   48% executed  ../../node_modules/agents/dist/chat/index.js
      52.3KB idle of    58.0KB   10% executed  ../../node_modules/@ai-sdk/provider-utils/dist/index.mjs

Shared changes, used by every mode: profile attribution splits a frame's self-time by its line ticks and maps every chunk that has a sourcemap (checklist A4); the ownership split counts multi-chunk source rows as app code; cut --root.

Shaped on cloudflare/agents-starter and cloudflare/vibesdk; the vibesdk pass is cloudflare/vibesdk#466 (wrangler check startup: 102.5 ms -> 63.3 ms). Design notes: "Worker startup mode (Cloudflare Workers)" in packages/perf-kit/README.md; the agent contract in AGENTS.md.

The first commit, the serve.mjs socket fix, is a parity matter and can move down into #11140.

requires #11140

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview URL: https://feat-metrics-lab-worker-rolldown-rs.voidzero-docs.workers.dev (commit 12bc024)

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://22519856-rolldown-rs.voidzero-docs.workers.dev 12bc024 2026-11-04T02:18:34.657Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://622b18ab-rolldown-rs.voidzero-docs.workers.dev ad57d3d 2026-11-03T17:12:46.465Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://7dd000d4-rolldown-rs.voidzero-docs.workers.dev 62407ee 2026-10-29T12:31:26.499Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://b83f5ce0-rolldown-rs.voidzero-docs.workers.dev c0a2170 2026-10-29T01:58:17.872Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://969f8afa-rolldown-rs.voidzero-docs.workers.dev d40cb93 2026-10-28T16:00:03.700Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://5cc0d492-rolldown-rs.voidzero-docs.workers.dev f62d239 2026-10-28T15:43:36.051Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://d3064953-rolldown-rs.voidzero-docs.workers.dev 5f941c1 2026-10-28T13:19:42.702Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://8203d676-rolldown-rs.voidzero-docs.workers.dev ce98f23 2026-10-28T03:58:17.001Z Visit the dashboard ↗
  • Build: In progress 🔵

View logs ↗
bc83ba4 2026-10-28T03:50:05.477Z View logs ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://f6715831-rolldown-rs.voidzero-docs.workers.dev ae6c8fa 2026-10-15T01:46:03.805Z Visit the dashboard ↗

View all previews: View all previews ↗

@netlify

netlify Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for rolldown-rs canceled.

Name Link
🔨 Latest commit 12bc024
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/6aea9557acdf88f90e6f90cd

@IWANABETHATGUY
IWANABETHATGUY force-pushed the feat/metrics-lab-worker branch from 2e7e50c to ae6c8fa Compare October 15, 2026 01:43
@IWANABETHATGUY
IWANABETHATGUY force-pushed the feat/metrics-lab-worker branch from ae6c8fa to bc83ba4 Compare October 28, 2026 03:50
@IWANABETHATGUY
IWANABETHATGUY force-pushed the feat/metrics-lab-worker branch from ce98f23 to 5f941c1 Compare October 28, 2026 13:17
@IWANABETHATGUY IWANABETHATGUY changed the title feat(metrics-lab): Cloudflare Worker startup mode feat(perf-kit): Cloudflare Worker startup mode Oct 28, 2026
@IWANABETHATGUY
IWANABETHATGUY force-pushed the feat/metrics-lab-worker branch from 5f941c1 to f62d239 Compare October 28, 2026 15:34
@IWANABETHATGUY
IWANABETHATGUY force-pushed the feat/metrics-lab-worker branch from f62d239 to d40cb93 Compare October 28, 2026 15:50
Base automatically changed from feat/metrics-lab-parity to main October 29, 2026 12:26
@IWANABETHATGUY
IWANABETHATGUY force-pushed the feat/metrics-lab-worker branch 2 times, most recently from 62407ee to ad57d3d Compare November 3, 2026 17:10
@IWANABETHATGUY
IWANABETHATGUY marked this pull request as ready for review November 3, 2026 17:13
Chrome keeps a socket open with no finished request, and `server.close()`
alone waits for it until Node's requestTimeout (300 s). Each parity run on a
React app took 5 to 10 minutes; `closeAllConnections()` after `close()` ends
the wait at once (3.6 s for the same run).
Measure a Vite-built Worker's startup under the app's own workerd and
attribute it to modules, with the loop the browser and node modes have.
`worker-config` writes a Vite config that puts the rolldown metrics report
on every environment (one directory each; an environment built without it
in the same process writes a full log under `unknown-session`).
`worker-scan` times the main module's import on fresh workerd instances
minus an empty-import floor, hits the pinned requests on the real entry,
profiles the import over the external inspector, and takes precise
coverage from inside the isolate through a `node:inspector` session
(wrangler >= 4.108.0, or `--tools <dir>` for that run). `worker-attrib`
charges startup CPU to the evaluating module from a preserveModules build,
because chunk top-level frames carry no line ticks and ESM evaluation is
not a call stack. `why <module>` lists the importers and the chain.

Shared changes the mode needed, used by every mode: profile attribution
splits a frame's self-time by its line ticks and maps every chunk that has
a sourcemap (checklist A4); the ownership split counts multi-chunk source
rows as app code; `cut --root a,b` keeps class modules eager so the cut
lands below a Durable Object class instead of at the entry.

Shaped on cloudflare/agents-starter and cloudflare/vibesdk; the vibesdk
pass is cloudflare/vibesdk#466 (startup 102.5 ms -> 63.3 ms on
`wrangler check startup`).
Report mode writes one report per output folder, so the config shim no
longer sets `reportDir` per environment. The Worker lookup reads
`node_modules/.rolldown/report/dist/<worker>`, and the attribution build
reads `node_modules/.rolldown/report/dist-attrib/<worker>`.
One prompt each for a browser page load, a node or deno server startup and
a Cloudflare Worker startup: the target, the number that counts, the Tools
paragraph, the rules and the report. The Tools paragraph is the only part
that names perf-kit, so the same prompt without it is the control prompt of
an A/B run. The README points at the page and the package ships it.
@IWANABETHATGUY
IWANABETHATGUY force-pushed the feat/metrics-lab-worker branch from ad57d3d to 12bc024 Compare November 4, 2026 02:15
@IWANABETHATGUY
IWANABETHATGUY merged commit 5ddaaa1 into main Nov 4, 2026
35 checks passed
@IWANABETHATGUY
IWANABETHATGUY deleted the feat/metrics-lab-worker branch November 4, 2026 02:40
shulaoda pushed a commit to raminjafary/rolldown that referenced this pull request Nov 4, 2026
…1214)

`scan` now reports static chunks that started downloading more than one
RTT after their static parent finished, separately before FCP and before
LCP, so that an agent can find a late-discovered chunk before it moves a
preload or a chunk boundary. The chunk graph comes from a new
`chunk-graph.json` that devtools report mode writes from the output
after `generateBundle` (a Vite manifest also works), and a keep/revert
decision now checks both FCP and LCP against the pinned baseline.

Design notes: "Chunk discovery" in `packages/perf-kit/README.md`.

requires rolldown#11188
shulaoda pushed a commit to raminjafary/rolldown that referenced this pull request Nov 4, 2026
…lds (rolldown#11215)

The lab measures a local copy with a fixed throttle, so a lab gain can
vanish in production and a production stall can stay invisible in the
lab. This PR adds `field`, which measures deployed variants in the
user's own logged-in Chrome, and `record` / `replay`, which give
field-like numbers for a build that is not deployed yet.

```mermaid
sequenceDiagram
    participant A as Agent
    participant L as Lab (harness.mjs / replay.mjs)
    participant C as User's Chrome (logged in)
    participant S as Deployed site
    participant R as Replay server (local HTTP/2)
    participant H as Headless Chrome (new context per load)

    Note over A,S: 1. record: once per network
    A->>L: record --config field.json --variant base
    L->>C: attach over CDP, load the page (6 timing runs + 1 body run)
    C->>S: real requests: real data, network and server
    S-->>C: responses
    L->>L: archive in $TMPDIR: responses, server time per call,<br/>network model, field medians, HANDOFF.txt
    L-->>A: archive path, complete, gaps

    Note over A,H: 2. calibrate: the recorded build must reproduce the field
    A->>L: replay --dist recorded=stable/dist --calibrate
    L->>R: serve the archive for every host
    L->>H: load the page (--host-resolver-rules: real origin, nothing leaves the machine)
    H->>R: every request
    R-->>H: static files from the dist (drawn TTFB, shared bandwidth)<br/>API responses from the archive (recorded server time)
    L-->>A: verdict: pass / record-again / model-error

    Note over A,H: 3. A/B: only after pass
    loop each candidate change
        A->>A: edit the app or the bundler, build ./dist
        A->>L: replay --dist base=stable/dist --dist candidate=./dist
        L->>H: alternating pairs, base and candidate
        H->>R: same recorded network and server for both
        L-->>A: paired deltas (90% interval), late chunks, unrecorded requests
        A->>A: keep or revert
    end

    Note over A,S: 4. confirm on the real site after a preview deploy
    A->>L: field --config field.json (base vs candidate)
    L->>C: alternating pairs on the deployed variants
    C->>S: real requests
    L-->>A: paired deltas on the real network
```

A replay is trusted only after `--calibrate` reproduces the field
medians with the recorded build. After that, local builds are compared
in alternating pairs on the same recorded network and server, and a kept
change is confirmed with `field` after a preview deploy. `replay.mjs` is
a standalone entry with `--json` results and exit codes, so one agent
can record and another can replay.

Also in this PR: timed runs record Chrome's request priorities for chunk
discovery, and CPU profiles map every chunk through its own sourcemap,
with top-level code split by sampled lines. The worker mode from rolldown#11188
now uses that shared attribution.

Design notes: "Field mode" and "Replay" in
`packages/perf-kit/README.md`; the agent contract in `AGENTS.md`.

requires rolldown#11214
shulaoda added a commit that referenced this pull request Nov 5, 2026
## [0.1.0] - 2026-11-05

### 🚀 Features

- perf-kit: add the Worker leads and keep rules from the startup A/B
runs (#11479) by @IWANABETHATGUY
- perf-kit: show module-scope calls and compare with the pinned build in
the same Worker scan (#11415) by @IWANABETHATGUY
- perf-kit: measure the deployed site and replay it for local builds
(#11215) by @IWANABETHATGUY
- perf-kit: diagnose chunk loading before FCP and LCP (#11214) by
@IWANABETHATGUY
- perf-kit: Cloudflare Worker startup mode (#11188) by @IWANABETHATGUY

### 🐛 Bug Fixes

- perf-kit: Worker mode with nested rolldown, external bindings,
redirects (#11498) by @IWANABETHATGUY
- perf-kit: make Worker mode work on more app setups (#11414) by
@IWANABETHATGUY

### 📚 Documentation

- add build report and perf-kit in-depth pages (#11480) by
@IWANABETHATGUY

### ⚙️ Miscellaneous Tasks

- perf-kit: keep run details out of code comments (#11481) by
@IWANABETHATGUY

Co-authored-by: shulaoda <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants