/perfup — Autonomous Performance Optimization
Inspired by karpathy/autoresearch: you are an autonomous performance researcher for vllm-mlx. You propose optimizations, benchmark them, keep what works, discard what doesn't, and ship a production PR.
Key Files
- Results log:
reports/perfup-results.tsv — append-only experiment log (commit, metric, status, description)
- Optimization queue:
memory/knowledge/perf_optimization_queue.md — ranked list of candidates
- Memory index:
memory/MEMORY.md — what's been done, what's known
- Benchmark script:
scripts/benchmark_engines.py
- Model for benchmarking: Check memory for current model path. If unavailable, ask user.
The 6 Phases
Phase 1: Research
Read existing state, then discover new opportunities.
- Read
memory/knowledge/perf_optimization_queue.md and memory/MEMORY.md
- If
$ARGUMENTS is provided (e.g. /perfup decode), focus on that area. Otherwise broad search.
- Scan codebase for optimization opportunities:
- Use Task(subagent_type=Explore) on critical paths
- Search for TODO/FIXME/PERF/HACK comments
- Check ml-explore/mlx-lm recent releases (
gh release list --repo ml-explore/mlx-lm --limit 5)
- WebSearch for latest MLX inference optimizations if needed
- Produce candidate list, each with: problem, solution, estimated impact, effort, coverage, risk
Phase 2: Prioritize
Score and rank. Persist to memory.
- Score each candidate (1-5 per axis):
- Impact: Performance gain magnitude (5 = >2x)
- Ease: Implementation effort (5 = <1 day)
- Coverage: Models that benefit (5 = all)
- Safety: Regression risk (5 = zero)
- Sort by composite = Impact x Ease x Coverage x Safety
- Update
memory/knowledge/perf_optimization_queue.md:
- Completed items → "Completed" section (date + results)
- Failed/rejected → "Rejected" section (reason)
- Active queue → "Queue" section with [P0]-[P3] tags
- Present top 3 to user. Wait for confirmation before proceeding.
Phase 3: PoC Experiment Loop
This is the core loop. Inspired by autoresearch: try, measure, keep or discard. Repeat.
SETUP:
git checkout -b perfup/<optimization-name>
Record baseline metrics (run benchmark on current code)
Initialize reports/perfup-results.tsv if not exists
LOOP:
1. Implement minimal PoC change in code
2. git commit -m "perfup: <brief description>"
3. Run benchmark: python3.12 scripts/benchmark_engines.py (or custom)
Redirect output: > reports/perfup-run.log 2>&1
4. Extract metrics from log (TTFT, decode tok/s, etc.)
5. Record to reports/perfup-results.tsv:
commit<TAB>decode_tps<TAB>ttft_ms<TAB>status<TAB>description
6. DECISION:
- If metric improved: KEEP. Log "keep" status. This is the new baseline.
- If metric same or worse: DISCARD. Log "discard". git reset --hard to previous keep.
- If crashed: Log "crash". Try to fix (1-2 attempts). If unfixable, discard and move on.
7. If improvement confirmed and significant (>5%): break loop → Phase 4
8. If no candidate works after trying top 3: inform user and stop.
Rules for the loop:
- Each PoC should be MINIMAL — smallest change that tests the hypothesis
- Benchmark must run on a REAL model (not mocks)
- If benchmark takes too long or model not loaded, ask user
- Do NOT ask "should I continue?" between iterations — just keep going
- DO stop and ask if you need user action (download model, start server, etc.)
Phase 4: Full Implementation
PoC validated. Now build it properly.
- Clean up or rewrite the PoC code for production quality
- Enter plan mode — design clean architecture, tests, docs
- Implement:
- Clean code, proper error handling, logging
- Unit tests matching existing patterns in
tests/
- No hacks, no dead code
- Run full test suite:
python3.12 -m pytest tests/ -v
- Run benchmark again — confirm improvement matches PoC
Phase 5: Review Loop
Independent review via Codex.
- Invoke:
/review-loop <description of optimization>
- Address all findings (P0 = blocker, P1 = should fix, P2 = nice to have)
- After review passes, run final benchmarks on all relevant models
- Update README/docs with new benchmark numbers if applicable
Phase 6: PR & Ship
- Ensure all changes are on
perfup/<name> or feat/<name> branch
- Push to
raullenchai remote (NEVER origin, NEVER main directly)
- Create PR:
gh pr create --repo raullenchai/vllm-mlx --base main
PR body must include:
- Summary: What was optimized and why
- Benchmark results: Before/after table from perfup-results.tsv
- Test plan: How to verify
- Update memory:
- Move optimization to "Completed" in
perf_optimization_queue.md with PR#, date, confirmed speedup
- Remove from todo if applicable
- Present PR URL to user
Results TSV Format
commit decode_tps ttft_ms status description
a1b2c3d 68.4 245 baseline current main branch
b2c3d4e 72.1 240 keep reduce redundant mx.eval in decode loop
c3d4e5f 67.9 248 discard speculative prefill chunking
d4e5f6g 0.0 0 crash fused MoE kernel (import error)
Focus Areas
If $ARGUMENTS provided:
ttft — Time to first token (prefill optimization)
decode — Decode throughput (tok/s)
tools — Tool calling accuracy/reliability
accuracy — Model output quality
memory — Memory usage / longer contexts
prefill — Prefill speed
cache — Cache hit rate / prompt reuse
- No argument → broad research across all areas
Important Rules
- Benchmark proves everything. No optimization ships without measured improvement.
- Memory is truth.
perf_optimization_queue.md is the canonical record of what's tried/works/failed.
- Git discipline. Feature branch → PR on raullenchai/vllm-mlx. Never push to main.
- Keep it simple. A small improvement with clean code beats a large improvement with ugly code. Removing code for equal performance is a win.
- Ask only when blocked. Don't ask "should I continue?" — just keep iterating. Ask only for user actions (model download, server restart, etc.).
1---2name: perfup3description: Autonomous performance optimization: research, PoC, benchmark, implement, review, PR4---56# /perfup — Autonomous Performance Optimization78Inspired by [karpathy/autoresearch](https://github.com/karpathy/autoresearch): you are an autonomous performance researcher for vllm-mlx. You propose optimizations, benchmark them, keep what works, discard what doesn't, and ship a production PR.910## Key Files1112- **Results log**: `reports/perfup-results.tsv` — append-only experiment log (commit, metric, status, description)13- **Optimization queue**: `memory/knowledge/perf_optimization_queue.md` — ranked list of candidates14- **Memory index**: `memory/MEMORY.md` — what's been done, what's known15- **Benchmark script**: `scripts/benchmark_engines.py`16- **Model for benchmarking**: Check memory for current model path. If unavailable, ask user.1718## The 6 Phases1920### Phase 1: Research2122Read existing state, then discover new opportunities.23241. Read `memory/knowledge/perf_optimization_queue.md` and `memory/MEMORY.md`252. If `$ARGUMENTS` is provided (e.g. `/perfup decode`), focus on that area. Otherwise broad search.263. Scan codebase for optimization opportunities:27 - Use Task(subagent_type=Explore) on critical paths28 - Search for TODO/FIXME/PERF/HACK comments29 - Check ml-explore/mlx-lm recent releases (`gh release list --repo ml-explore/mlx-lm --limit 5`)304. WebSearch for latest MLX inference optimizations if needed315. Produce candidate list, each with: problem, solution, estimated impact, effort, coverage, risk3233### Phase 2: Prioritize3435Score and rank. Persist to memory.36371. Score each candidate (1-5 per axis):38 - **Impact**: Performance gain magnitude (5 = >2x)39 - **Ease**: Implementation effort (5 = <1 day)40 - **Coverage**: Models that benefit (5 = all)41 - **Safety**: Regression risk (5 = zero)422. Sort by composite = Impact x Ease x Coverage x Safety433. Update `memory/knowledge/perf_optimization_queue.md`:44 - Completed items → "Completed" section (date + results)45 - Failed/rejected → "Rejected" section (reason)46 - Active queue → "Queue" section with [P0]-[P3] tags474. Present top 3 to user. Wait for confirmation before proceeding.4849### Phase 3: PoC Experiment Loop5051**This is the core loop. Inspired by autoresearch: try, measure, keep or discard. Repeat.**5253```54SETUP:55 git checkout -b perfup/<optimization-name>56 Record baseline metrics (run benchmark on current code)57 Initialize reports/perfup-results.tsv if not exists5859LOOP:60 1. Implement minimal PoC change in code61 2. git commit -m "perfup: <brief description>"62 3. Run benchmark: python3.12 scripts/benchmark_engines.py (or custom)63 Redirect output: > reports/perfup-run.log 2>&164 4. Extract metrics from log (TTFT, decode tok/s, etc.)65 5. Record to reports/perfup-results.tsv:66 commit<TAB>decode_tps<TAB>ttft_ms<TAB>status<TAB>description67 6. DECISION:68 - If metric improved: KEEP. Log "keep" status. This is the new baseline.69 - If metric same or worse: DISCARD. Log "discard". git reset --hard to previous keep.70 - If crashed: Log "crash". Try to fix (1-2 attempts). If unfixable, discard and move on.71 7. If improvement confirmed and significant (>5%): break loop → Phase 472 8. If no candidate works after trying top 3: inform user and stop.73```7475**Rules for the loop:**76- Each PoC should be MINIMAL — smallest change that tests the hypothesis77- Benchmark must run on a REAL model (not mocks)78- If benchmark takes too long or model not loaded, ask user79- Do NOT ask "should I continue?" between iterations — just keep going80- DO stop and ask if you need user action (download model, start server, etc.)8182### Phase 4: Full Implementation8384PoC validated. Now build it properly.85861. Clean up or rewrite the PoC code for production quality872. Enter plan mode — design clean architecture, tests, docs883. Implement:89 - Clean code, proper error handling, logging90 - Unit tests matching existing patterns in `tests/`91 - No hacks, no dead code924. Run full test suite: `python3.12 -m pytest tests/ -v`935. Run benchmark again — confirm improvement matches PoC9495### Phase 5: Review Loop9697Independent review via Codex.98991. Invoke: `/review-loop <description of optimization>`1002. Address all findings (P0 = blocker, P1 = should fix, P2 = nice to have)1013. After review passes, run final benchmarks on all relevant models1024. Update README/docs with new benchmark numbers if applicable103104### Phase 6: PR & Ship1051061. Ensure all changes are on `perfup/<name>` or `feat/<name>` branch1072. Push to `raullenchai` remote (NEVER origin, NEVER main directly)1083. Create PR:109 ```110 gh pr create --repo raullenchai/vllm-mlx --base main111 ```112 PR body must include:113 - **Summary**: What was optimized and why114 - **Benchmark results**: Before/after table from perfup-results.tsv115 - **Test plan**: How to verify1164. Update memory:117 - Move optimization to "Completed" in `perf_optimization_queue.md` with PR#, date, confirmed speedup118 - Remove from todo if applicable1195. Present PR URL to user120121---122123## Results TSV Format124125```126commit decode_tps ttft_ms status description127a1b2c3d 68.4 245 baseline current main branch128b2c3d4e 72.1 240 keep reduce redundant mx.eval in decode loop129c3d4e5f 67.9 248 discard speculative prefill chunking130d4e5f6g 0.0 0 crash fused MoE kernel (import error)131```132133## Focus Areas134135If `$ARGUMENTS` provided:136- `ttft` — Time to first token (prefill optimization)137- `decode` — Decode throughput (tok/s)138- `tools` — Tool calling accuracy/reliability139- `accuracy` — Model output quality140- `memory` — Memory usage / longer contexts141- `prefill` — Prefill speed142- `cache` — Cache hit rate / prompt reuse143- No argument → broad research across all areas144145## Important Rules1461471. **Benchmark proves everything.** No optimization ships without measured improvement.1482. **Memory is truth.** `perf_optimization_queue.md` is the canonical record of what's tried/works/failed.1493. **Git discipline.** Feature branch → PR on raullenchai/vllm-mlx. Never push to main.1504. **Keep it simple.** A small improvement with clean code beats a large improvement with ugly code. Removing code for equal performance is a win.1515. **Ask only when blocked.** Don't ask "should I continue?" — just keep iterating. Ask only for user actions (model download, server restart, etc.).