Skip to content

perf(tests): stop re-importing the whole worker per test file; parallel pre-push gate - #99

Merged
leorfer23 merged 1 commit into
mainfrom
perf/fast-gate
Oct 14, 2026
Merged

leorfer23 merged 1 commit into
mainfrom
perf/fast-gate

Conversation

@leorfer23

Copy link
Copy Markdown
Contributor

Gate was taking 2.5–7.5 min per PR. Measured where it went and cut it.

Root cause: 94% of unit-test wall time was module import, not tests. Every test file that did import { env } from 'cloudflare:test' loads the whole worker (src/index.ts, 5–10s per file, re-done for each file in a fresh isolate). Most of them only wanted bindings.

Changes

  • 58 test files + 2 helpers: env now comes from cloudflare:workers (same bindings, no worker load). Files that touch Durable Objects (MiniDB, KnowledgeStore, runInDurableObject) keep cloudflare:test: with cloudflare:workers they load the worker lazily inside the test and can hit the 10s hook timeout under load.
  • ci-check-fast.sh (pre-push): static checks, typecheck, app tests, the 3 workspaces and the secret scan run in parallel. Output is printed only on failure. check:bundles runs last and alone because it rewrites public/_bundles/ (the stage-skill-bundle test does too).
  • Pre-push secret scan covers merge-base..HEAD commits (0.1s) instead of the whole tree (16s). ci-check.sh still does the full-tree scan.
  • typecheck is incremental (3.2s → 1.1s warm; cache in node_modules/.cache).

Measured (same machine, other agents running, load 6–24)

before after
full suite import time (summed) 2344s ~900s
full suite wall 375–452s ~186s
full gate incl. full suite (SHAREOUT_FULL_TESTS=1 ci-check-fast.sh) ~7–9 min sequential 168s
test:critical 11.8s 9.9s
otp.test.ts alone 10.4s 0.5s

Full suite: 550 files / 5207 tests green.

🤖 Generated with Claude Code

…el pre-push gate

- 58 unit tests (+ 2 helpers) only used `env` from `cloudflare:test`, which makes
  every such file import src/index.ts (~5-10s each). `cloudflare:workers` gives
  the same bindings without loading the worker. Files that touch Durable
  Objects (MiniDB, knowledge store, runInDurableObject) keep `cloudflare:test`.
  Full suite: import 2344s -> ~885s, wall 375s -> ~186s on a loaded machine.
- ci-check-fast.sh runs static checks, typecheck, tests, workspaces and the
  secret scan in parallel; check:bundles stays last (it rewrites _bundles/).
- Secret scan in pre-push covers base..HEAD commits (0.1s) instead of the
  whole tree (16s). Full-tree scan unchanged in ci-check.sh.
- typecheck is incremental (3.2s -> 1.1s warm).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@leorfer23
leorfer23 merged commit 1160648 into main Oct 14, 2026
2 checks passed
@leorfer23
leorfer23 deleted the perf/fast-gate branch October 14, 2026 19:35
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