xpd optimize
Run xpd optimize to find CPU, memory, and I/O work that the result does not need, and gate every change on real workload measurements.
| Group | Finding kinds |
|---|---|
| Performance rules | rule-issue |
| Repeated work | repeated-call, repeated-mask, redundant-key-check, loop-invariant-call |
| Oversized intermediates and scans | matrix-reduced, materialized-for-one, linear-scan-in-loop |
Go and Rust source can surface repeated scans in loops and collections built to read one item.
Two kinds block a recorded run and xpd audit --strict-clean: repeated-call and repeated-mask. An oracle that can prove a finding wrong labelled their findings in open-source repositories, and at least 90% of each kind were right. Every other finding of this track is advice: a fix may name one, and no run or audit has to clear one.
Run xpd optimize --questions to read the questions and the facts that inform them. The supported fix goals are faster and both.
Pass a representative workload with xpd optimize start --bench to time the whole command. Use --adapter perf.py on a list or start to measure individual workloads. The adapter defines workloads(), which returns a mapping from names to zero-argument callables. A shell adapter emits a JSON object with a workloads array where each workload holds name, median_ms, peak_bytes, and functions (file, name, line, cpu_ms, cumulative_cpu_ms, cpu_share, and calls, using project-relative paths and fractional shares). A gate judges each workload on its own: no workload may get slower, and a fix with the goal faster must make at least one workload at least 2% faster with timings that do not overlap. A run calls workloads() once at start and once at each gate.
xpd optimize [OPTIONS] [PATHS]... xpd optimize <COMMAND>Subcommands
Section titled “Subcommands”| Subcommand | What it does |
|---|---|
xpd optimize start |
Start a run: record the commit it starts from, the paths, line count, checks and optional benchmark of the project |
xpd optimize plan |
Record the plan of a round: the fixes in order, and the findings that are right as they are |
xpd optimize approve |
Record that the user said yes to a fix that changes what callers or users see, or that changes files outside the paths of the run |
xpd optimize gate |
Gate a fix: run the checks, time --bench when set, count lines and compare the findings with the commit before it. Exit 1 when the fix is not kept |
xpd optimize drop |
Record that a fix was given up, after its files were restored |
xpd optimize status |
Print the run and the stage that comes next |
xpd optimize finish |
End the run: compare findings, line count and benchmark timing with the start commit. Exit 1 while a fix is open or a new finding has no reason |
Arguments
Section titled “Arguments”| Argument | What it does |
|---|---|
<PATHS>... |
Files or directories (directories respect .gitignore) |
Options
Section titled “Options”| Option | Default | What it does |
|---|---|---|
--kind <KIND> |
List only the findings of these kinds, separated by commas. Repeatable. Values: rule-issue (A rule of xpd check or the project's own rule pack fires on this line), repeated-call (A function computes the same call more than once, with nothing changed in between), repeated-mask (A function computes the same boolean mask or masked slice more than once), redundant-key-check (A join validation or a uniqueness test scans a key that an earlier line already made unique), loop-invariant-call (A loop or comprehension computes a call on every pass and changes nothing it reads), matrix-reduced (A matrix of every element against every other is built and then reduced or contracted), materialized-for-one (A full diff, sort or cumulative sum is built only to read one element or a short head), linear-scan-in-loop (A loop scans a list for membership or filters a whole frame on every pass). |
|
--limit <LIMIT> |
20 |
The most findings to list of each kind, strongest first. 0 lists every finding. |
--since <COMMIT> |
Count the findings at this commit too, and print each count beside the count of today. | |
--group-by <GROUP_BY> |
none |
Group findings and checklist items by owning module or shared cause. Values: none (Keep the default flat per-kind listing), module (Group findings and checklist items by owning module path), cause (Group related findings by shared kind and anchor files). |
--packet <N> |
Emit one 1-indexed deterministic context-budgeted review packet for the Nth cluster. | |
--budget-lines <LINES> |
300 |
Maximum source lines included across excerpts inside a --packet view. |
--all-modules |
Include checklist review items for every surveyed module, not only modules with findings. | |
--format <FORMAT> |
Output format. Default: text on a terminal, json otherwise. Values: text, json. |
|
--questions |
||
--adapter <ADAPTER> |
Recorded run
Section titled “Recorded run”- Start: record the current commit, paths, project checks, and workload from a clean tracked tree with
xpd optimize start . --check "your-project-check" --bench "your-workload"or--adapter perf.py. One of the two is required. - List: read the stable ID of each finding and each hotspot with
xpd optimize . --format json. - Plan: record the ordered fixes, each naming the findings it removes, using
xpd optimize plan plan.json. - Approve: record approval for an interface change with
xpd optimize approve fix-id. - Gate: commit one fix and run
xpd optimize gate fix-id. When a benchmark is set onstart, every fix must cut median time by at least 2% with non-overlapping intervals (after.max_ms < before.min_ms). - Drop: return to the run's current commit and record a reason with
xpd optimize drop fix-id --reason "reason". - Status: show the current run, its recorded answers, and the next stage with
xpd optimize status. - Finish: compare against the starting commit with
xpd optimize finish. An open fix causes exit 1. Advice that is left needs no reason.
Example
Section titled “Example”$ xpd optimize --questions --format json | jq -c '{facts: (.facts | length), questions: (.questions | length)}'{"facts":9,"questions":10}Exit status
Section titled “Exit status”A successful list or recorded stage exits 0. A rejected gate or a finish with an open fix exits 1. Invalid input exits 2.