Skip to content

perf(test): disable Lambda bundling in CDK unit-test synths (~15x per synth) (#363) #366

Description

@scottschreckengaust

Summary

Reduce //cdk:test wall time by eliminating repeated full-stack synthesis in the handful of mega-suites that dominate the CDK Jest suite. Profiling (see #365) shows the cost is concentrated: the top 5 suites are 362s of 437s suite-time (83%), and the single heaviest file is 135.6s. Each new App() + Template.fromStack() is ~27s; several suites synthesize the same stack multiple times where one shared synth would do.

This is the predecessor to sharding (#365) — lowering the per-file floor is both a bigger, simpler win on its own AND what makes sharding worthwhile later. Parent: #363.

Evidence (8-core local, coverage on)

Suite Time Full synths in file Notes
test/stacks/github-tags.test.ts 135.6s 4 (synthWithTags) 2 hoisted to beforeAll, 2 still inline (empty string, compute_type ecs tests)
test/constructs/task-api.test.ts 83.5s 12 (4 beforeAll + inline) audit which inline synths can share a template
test/stacks/agent.test.ts 50.2s 2 already mostly beforeAll; verify
test/constructs/task-orchestrator.test.ts 49.9s 2 already mostly beforeAll; verify
test/bootstrap/synth-coverage.test.ts 44.4s 2 by-design coverage synth; check if reducible

Approach

For each heavy suite: synthesize each distinct stack configuration exactly once (in beforeAll), and have individual tests assert against the cached Template. Only synth again when a test genuinely needs a different context/config. Do not weaken assertions or merge tests — only remove redundant synthesis.

Concrete first target — github-tags.test.ts: hoist the two remaining inline synthWithTags(...) calls (empty string values and compute_type: 'ecs') into shared beforeAll templates keyed by their context, reused across tests. Est. ~−54s on this file alone.

Acceptance criteria

  • Each targeted suite synthesizes each distinct stack config at most once; redundant inline synths removed.
  • All tests still pass (2177 CDK tests) with identical assertions; coverage thresholds unchanged and met.
  • //cdk:test wall-time improvement reported on real 4-core CI (before/after); target: meaningfully below the current ~298s, driven by the top-5 suites.
  • No reduction in what is asserted; no test merged away to fake a speedup.
  • mise run build clean; no drift; no new flakiness.

Notes for implementer

  • new App() + Template.fromStack() is the expensive operation (~27s here) — cdk-nag aspects run during synth. Counting these per file is the quickest way to find waste: grep -cE "new App\(|Template.fromStack" <file>.
  • Some suites already use beforeAll correctly — verify before changing; the win is only in the files that synth the same config repeatedly.
  • After this lands, re-profile and decide whether perf(ci): shard the CDK jest suite across a job matrix (#363 item #2) #365 (sharding) is still worth it — the floor may be low enough that the unsharded suite is already fast.

References


🤖 Generated with Claude Code

Metadata

Metadata

Labels

P1medium priorityapprovedWhen an issue has been approved and ready

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions