Skip to content

Optimize measured performance

Run xpd optimize to find repeated calls, loop-invariant work, linear scans, and oversized intermediates, then prove each speedup against real project workloads with --bench and profiler adapters.

Source filesStatic waste findings--bench or --adapter perf.pyMeasured CPU andmemory hotspotsxpd optimize plan and gateKept only when checkspass and timing improves

Run a static scan first to locate mechanical performance waste without executing code.

Terminal window
xpd optimize src/
xpd optimize src/ --since HEAD~1 --format json

Add --bench to time a representative command at start and at every gate, or pass --adapter perf.py (defining workloads() returning named zero-argument callables) so functions consuming at least 5 percent of workload CPU time enter the performance checklist automatically.

Input What it measures
Static survey rule-issue, repeated-call, repeated-mask, redundant-key-check, loop-invariant-call, matrix-reduced, materialized-for-one, linear-scan-in-loop
--bench "<command>" Median, minimum, and maximum wall-clock duration across commits on the same machine class
--adapter perf.py Per-function CPU share, call counts, and peak memory bytes for hotspot checklist items
  1. Start from a clean commit with xpd optimize start src/ --check "<project-check>" --bench "<workload>" (or --adapter perf.py). start requires --bench or --adapter.
  2. Inspect findings and hotspots with xpd optimize src/ --format json and track active runs with xpd optimize status --format json.
  3. Write plan.json citing finding IDs or fix goals (faster, both, or design) and submit it with xpd optimize plan plan.json.
  4. Commit one optimization at a time and gate it with xpd optimize gate <fix-id>. With --bench, every fix must cut median time by at least 2% with non-overlapping intervals (after.max_ms < before.min_ms). With --adapter, each workload is judged on its own: none may regress, and at least one must show that speedup, so a large workload cannot hide a change in a small one. For data pipeline rewrites, confirm identical output with xpd equiv.
  5. Close the run with xpd optimize finish once no fix is open. A repeated-call or repeated-mask finding must be fixed or accepted with a reason. Every other finding is advice that no run has to clear.

See xpd optimize for all flags and adapter schemas.