Vitest caches modules and may load capture.js before environment
variables like CODEFLASH_PERF_LOOP_COUNT are set. When these were
read as constants at module load time, they would always return
default values.
This change converts the performance configuration from constants
to getter functions that read environment variables at runtime,
ensuring correct values are used even when the module is cached.
Fixes:
- PERF_LOOP_COUNT always being 1 in Vitest
- PERF_BATCH_SIZE, PERF_MIN_LOOPS, etc. using defaults instead of env values
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Previously, MAX_BATCHES was set to PERF_LOOP_COUNT directly (e.g., 250),
which caused the loop-runner to run 250 batches even though only 25
batches were needed to produce timing data (with BATCH_SIZE=10).
The bug was that timing markers only appeared for the first N batches
(where N = LOOP_COUNT / BATCH_SIZE), and the remaining batches were
wasted overhead.
Fix: Calculate MAX_BATCHES as ceil(LOOP_COUNT / BATCH_SIZE) + 1, capped
at LOOP_COUNT. This ensures only the necessary batches run:
- With LOOP_COUNT=250, BATCH_SIZE=10: MAX_BATCHES = 26 (not 250)
This significantly improves benchmark efficiency by eliminating wasted
Jest passes that don't contribute timing data.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>