Skip to content

test(flags-core): profile initialization across auth and source modes - #502

Closed
luismeyer wants to merge 2 commits into
flags-version-headerfrom
perf/flags-core-init
Closed

luismeyer wants to merge 2 commits into
flags-version-headerfrom
perf/flags-core-init

Conversation

@luismeyer

@luismeyer luismeyer commented Sep 16, 2026

Copy link
Copy Markdown
Member

Summary

Adds a repeatable, network-free initialization performance test/benchmark. This is a separate PR stacked on #498 (flags-version-header) for the version-header client mode. It now includes the opt-in generated JSON-parse probe plus the benchmark, tests, and docs: the base branch no longer contains the earlier parse-probe commit. No further changes were pushed to #498 by this benchmark task. Retarget after that dependency lands.

  • Eight scenarios: SDK key and request-scoped OIDC, each with embedded-only/offline, fresh version header, mocked primed stream, and mocked full-datafile stream without a matching embedded entry.
  • Each cold sample runs in its own Node process; a second new client measures warmed module/data/hash/OIDC caches. Same-client re-initialization is also reported.
  • Phase timings for creation, initialization, embedded import, auth lookup, SDK-key hash/cache lookup, embedded JSON parsing, header detection, stream initialization/auth, and remaining work.
  • Initialization probes are added only to a temporary worker build, with no flags-core client API changes. The generated definitions module also has an opt-in VERCEL_FLAGS_DEBUG_EMBEDDED_PARSE=1 timer, disabled by default, which logs only parse duration and input length.
  • Functional assertions cover auth headers, revisions, correct modes, header-driven stream bypass, memoization, and stream cancellation. No flaky latency thresholds.
  • Optional local definitions file and JSON output. Private input is not committed; temporary copies are cleaned up.

Usage

pnpm --filter @vercel/flags-core bench:init
pnpm --filter @vercel/flags-core bench:init --definitions /path/to/datafile.json --samples 20

Add --json for unrounded phase median/p95 values and validation counters.

Local measurements

Node 22.22.3 on Apple M5 Pro, supplied 31-flag fixture (8,394 bytes after synthetic metadata normalization), 20 fresh-process samples per scenario / 160 processes total. Times below are median initialize() durations, excluding client creation.

Scenario SDK key cold / warm (ms) OIDC cold / warm (ms)
Embedded only 1.468 / 0.024 1.905 / 0.053
Fresh version header 1.452 / 0.025 1.780 / 0.051
Mocked primed stream 2.041 / 0.113 2.343 / 0.237
Mocked full-datafile stream 1.636 / 0.189 2.319 / 0.277

For the fresh-header case, SDK-key hash lookup accounts for about 0.897 ms, or OIDC auth lookup about 1.207 ms. Embedded import is around 0.27 ms and JSON parsing around 0.039 ms. Same-client reinitialization is around 0.001 ms.

These are instrumented local diagnostic measurements, not deployed latency predictions: stream transport is mocked; fixture/mock construction and initial SDK module loading are outside the interval; Next.js use cache and live network latency are not measured. Some phase measurements are inclusive parents/children, documented in the README. Independently computed phase medians need not sum to the total median.

Verification

All completed with exit code 0:

  • pnpm --filter @vercel/flags-core exec vitest run bench/init.test.ts src/vercel-mode.black-box.test.ts src/controller/header-source.test.ts src/utils/read-bundled-definitions.test.ts — 72 tests passed.
  • pnpm --filter @vercel/flags-core type-check — passed.
  • pnpm --filter @vercel/prepare-flags-definitions exec vitest run src/index.test.ts — 30 tests passed (102 focused tests total).
  • pnpm --filter @vercel/prepare-flags-definitions type-check — passed.
  • pnpm exec biome check packages/prepare-flags-definitions/src/index.ts packages/prepare-flags-definitions/src/index.test.ts packages/vercel-flags-core/bench packages/vercel-flags-core/package.json packages/vercel-flags-core/tsconfig.json — passed.
  • git diff --check — passed.
  • pnpm --filter @vercel/flags-core bench:init --definitions /path/to/datafile.json --samples 20 — all eight scenarios, cold/warm paths, and per-sample assertions passed against the supplied local file.

@vercel

vercel Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
flags-playground Ready Ready Preview, v0 Sep 16, 2026 11:21am UTC
flags-sdk-dev Ready Ready Preview, v0 Sep 16, 2026 11:21am UTC
shirt-shop Ready Ready Preview, v0 Sep 16, 2026 11:21am UTC
shirt-shop-api Ready Ready Preview, v0 Sep 16, 2026 11:21am UTC

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