Files
vac-optimizer/docs/benchmark/pr-278-date-keys.md

2.7 KiB

PR #278: build placement date keys directly

Measured on 2026-10-16, starting from PR #278 at cbde23f.

The unchanged benchmark finished in 299.372 seconds before this change, leaving only 0.628 seconds before its 300-second timeout. A separate loaded-year CPU profile attributed 8.27 of 66.57 seconds to placementTieKey, including its callees. That function runs when looking up cached calendar observations and when comparing final placement dates.

The one-line optimization sorts the placement map's date keys directly, using native string sorting. It removes the intermediate placement-to-date array and the comparison callback. Every placement map entry is keyed by its placement's date, and native string sorting preserves the existing lexical date order, so the resulting keys are identical. Search choices and scoring are unchanged.

Before and after

Both runs used Node 24.18.0, Bun 1.3.14, Vitest 5.0.3, the same local machine, and the exact command below. No other test, build or profiling workload ran alongside either measurement.

NODE_OPTIONS=--max-old-space-size=2048 timeout 300s bunx vitest run src/app/benchmark/leave-planner-benchmark.spec.ts --maxWorkers=1

All seven warm-ups, fourteen measured calculations, the typed-obligation precheck, fixtures and assertions remain unchanged. Coverage is disabled for this command.

Measurement Before After
Entire command, external wall time 299.372 s 268.573 s
Benchmark test 293.620 s 263.265 s
Loaded year, mean of two measured calculations 76.649 s 67.747 s
Headroom before timeout 0.628 s 31.427 s

The entire command was 10.3% faster in this before-and-after pair. Both runs completed successfully, and every repeated scenario remained deterministic. These are local measurements; Gitea runner performance still needs confirmation.

Correctness checks

Complete outcomes, stable explanations and final-state snapshots match the baseline for all seven scenarios. These separate comparisons ran alongside functional checks; their diagnostic timings are not used in the table above.

The functional coverage suite passes all 635 tests across 33 files. Application and spec type checks, lint, source formatting and git diff --check also pass. No browser timing run or live CI rerun was performed for this change.

The profiling runner and full protocol logs are retained in /tmp/vac-opt278-measure. The original diagnostic reproduction is documented in issue-78.md.