This repository contains:
- A Rust CLI that scans
.asmfiles and reports suboptimal instruction patterns. - The original
optimize.pyreference implementation. - A runtime-loaded YAML configuration in
configs/packs.yaml.
See yaml-config.md for the YAML schema and building blocks.
- Run on a directory (defaults to
--config configs/packs.yaml --pack rgbds):
cargo run --release -- .- Run with an explicit config + pack:
cargo run --release -- --config configs/packs.yaml --pack pret path/to/repoNote: legacy TOML-based pack configs have been removed; use configs/packs.yaml.
python3 optimize.py path/to/repoPattern packs live in a single YAML file, loaded at runtime.
regexes: named regex strings; compiled once at startup.patterns: reusable pattern definitions (named steps).packs: named lists of patterns to run.
Example (abridged):
regexes:
NO_OP_LD: '^ld ([abcdehl]), \1$'
patterns:
py_no_op_ld:
name: No-op ld
steps:
- when: { regex: NO_OP_LD }
packs:
rgbds:
patterns:
- id: py_no_op_ldThe compatibility goal is:
- For the same input files and pattern set, the Rust CLI output (stdout/stderr) and exit code match
optimize.py. - New functionality should be added behind flags and/or in new pattern packs to avoid breaking the compatibility contract.
A deterministic parity harness exists at tools/parity.py.
- Quick one-shot parity check (collects/sorts files, then diffs Python vs Rust):
python3 tools/parity.py /path/to/repo- Run with a specific pack and release profile:
python3 tools/parity.py --config configs/packs.yaml --pack pret --cargo-profile release /path/to/repoCI parity against a pinned pret/pokecrystal commit is implemented in .github/workflows/parity-pokecrystal.yml.
A deterministic timing harness exists at tools/bench.py.
python3 tools/bench.py --config configs/packs.yaml --pack pret /path/to/repoGenerate the third-party license bundle:
cargo install cargo-about --locked
python3 tools/generate_third_party_licenses.pyThis writes THIRD_PARTY_LICENSES.html in the repo root.
Run dependency/license/advisory checks:
cargo install cargo-deny --locked
cargo deny checkProfiling options:
- Rust (Linux, requires system
perf):
perf record -g -- cargo run --release -- --config configs/packs.yaml --pack pret /path/to/repo- Rust (flamegraph wrapper, requires
perf):
cargo install flamegraph
cargo flamegraph --root -- --config configs/packs.yaml --pack pret /path/to/repo- Rust (
pproffeature, useful whereperfis difficult to install):
cargo run --release --features pprof -- --config configs/packs.yaml --pack pret --pprof /tmp/optimize.svg --pprof-frequency 1000 /path/to/repo- Python:
python3 -m cProfile -o /tmp/optimize.prof optimize.py /path/to/repo
python3 -m pstats /tmp/optimize.profWhen adding or changing patterns:
- Prefer editing
configs/packs.yaml. - Regexes are compiled once at startup; try to reuse named regexes.
- Add fixture coverage under
tests/fixtures/parity/. - Run
cargo testandpython3 tools/parity.py <repo>(or CI) before sending a PR.