Skip to content

perf: cut api build cost where nimbus owns it - #293

Merged
MohamedH1998 merged 14 commits into
mainfrom
feat/api-build-cost
Oct 25, 2026
Merged

MohamedH1998 merged 14 commits into
mainfrom
feat/api-build-cost

Conversation

@MohamedH1998

@MohamedH1998 MohamedH1998 commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Four small performance changes to the API engine, measured on the Cloudflare API site (2,974 operations). None adds config or a cache. The build's wall time does not move; the gains are structural: one fewer parse, one fewer render pass, a lighter Worker, and a log line that says why a rebuild happened.

Decision: adopt all four. First PR of a stack of four.

Changes

  • Parse the spec text once for the walk and the ref-preserving copy instead of three times. After dereferencing, a probe checks that the shared document still holds its $refs; if a parser version ever resolves in place, the text is parsed again, so links cannot disappear silently.
  • For an API with bundle: false, say on a version-cache miss what changed: Nimbus, an installed package, the spec, or the routes, or that nothing was cached yet. Per-component digests live in a small sidecar per version, pruned with the version.
  • Stage agent files by clone instead of copy, and read the staged Markdown twins for the search inventory instead of rendering every page a second time.
  • In a server build, read the agent-endpoint manifest from the staged assets once per isolate instead of bundling a 2.5 MB literal into the Worker. Staging fails with a clear error and a remedy if that file would exceed Cloudflare's 25 MiB static file limit. The Worker purity check allows this published path and still rejects the build directory.

Validation

Metric Before After
Spec parses per miss 3 2
Agent-file staging 5.7 s 4.2 s
Render passes over API pages 2 1
Worker bundle 18 MB 16 MB
Manifest literal in Worker 2,495,016 B 162 B
Twin request through workerd, first / warm bundled 16 ms / 4–5 ms
Preview release on the site, miss / warm 39–44 s / 37–44 s 38.6 s / 31.4 s
  • Passed: pnpm typecheck; full nimbus-docs suite; Workers feasibility matrix on workerd.
  • Passed: stranger test on a fresh scaffold from the preview release: manifest staged and not inlined, every agent endpoint serves through wrangler dev, rebuild reasons name the spec, the cache, or a first build; static output unchanged. Its wording findings are applied in the last commit.
  • Passed: probe unit tests against a document resolved in place; staging rejects an oversized manifest before copying anything.

The text was parsed three times: validate, dereference and the ref-preserving
copy each parsed it again. One parse now feeds dereference and the raw document;
validate keeps its own because Scalar's validator rewrites a non-string
info.version on the object it is handed. Empty or unparseable text now fails
with "could not be parsed" instead of "produced no document to render".
The version cache keyed on one composite hash and logged nothing on a miss, so
a slow build could not be told apart from a cache that never hit. Each version
now keeps a small record of the input digests its last preparation hashed, and
the "Prepared API pages" line names the inputs that differ, or the first build.
Staging asserted every path segment, made the directory and checked the target for each of thousands of files; now the roots and each directory are checked once and a file costs one lstat and one clone. The request-route inventory rendered every API page a second time for its searchable text although the bake had just written the same Markdown; it now reads the twin like every other page.
The virtual module inlined every Markdown and llms asset row into the server bundle, a 2.5 MB chunk on a large API. Staging now writes manifest.json beside the assets and a server build reads it once per isolate through the staged-asset reader; dev and prerendered routes keep the inlined copy.
@cloudflare-workers-and-pages

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

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview URL: https://feat-api-build-cost.nimbus-docs.com (commit 0f5602d)

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://e916c498.nimbus-docs.com 0f5602d 2026-10-25T09:59:50.163Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://2650d6f6.nimbus-docs.com 55d4ad5 2026-10-24T22:37:42.857Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://9bf0982c.nimbus-docs.com 85366b6 2026-10-24T21:26:42.069Z Visit the dashboard ↗
  • Build: Failed ❌

View logs ↗
16c0b99 2026-10-24T20:57:52.748Z View logs ↗

@MohamedH1998 MohamedH1998 changed the title Cut API build cost where Nimbus owns it perf: cut api build cost where nimbus owns it Oct 24, 2026
…e changes

The shared parse now probes one $ref after dereferencing and parses the text again if a parser version resolved in place, so schema links cannot disappear silently. Staging fails with a clear error when the agent-endpoint manifest would exceed Cloudflare's 25 MiB static file limit instead of failing the deploy later. The Worker purity check allows the published manifest path it now reads by design while still rejecting the build directory.
@MohamedH1998
MohamedH1998 added this pull request to stack #297 October 24, 2026 21:51
The staging error names a remedy, the rebuild reason no longer says "this version" for an API without versions, and the changeset and guides say which builds print the rebuild line and what the staged manifest is.
@MohamedH1998
MohamedH1998 marked this pull request as ready for review October 25, 2026 09:56
@MohamedH1998
MohamedH1998 merged commit c3aa96f into main Oct 25, 2026
57 of 59 checks passed
@MohamedH1998
MohamedH1998 deleted the feat/api-build-cost branch October 25, 2026 10:50

This branch was successfully deployed

1 active deployment
cloudflare — 0f5602dc Deployed Oct 25, 2026 by MohamedH1998 via Delete closed PR Preview #37
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.

1 participant