{
  "markdown": "# perf\n\nStructured performance investigation with baselines, profiling, and evidence-backed decisions - run by AI agents inside your editor.\n\n## Why\n\nPerformance work without structure leads to random micro-optimizations, unmeasured changes, and wasted time. `/perf` enforces a rigorous 10-phase methodology - derived from recorded real investigation sessions - that ensures every optimization is baselined, isolated, measured, and documented.\n\nUse cases:\n\n- Investigating a reported performance regression\n- Establishing baselines before and after a refactor\n- Finding breaking points under load\n- Profiling CPU and memory hotspots with language-native tools\n- Making evidence-backed continue/stop decisions on optimization efforts\n\n## Installation\n\n```bash\nagentsys install perf\n```\n\nRequires [agentsys](https://github.com/agent-sh/agentsys) to be set up in your project.\n\n## Quick Start\n\n```\n/perf --phase setup --scenario \"API response time regression\" --command \"npm run bench\" --version v1.2.0\n```\n\nThis initializes an investigation, records the scenario, and prepares for baselining. The orchestrator walks you through each phase sequentially, checkpointing progress after every step.\n\nTo resume an in-progress investigation:\n\n```\n/perf --resume\n```\n\n## How It Works\n\nEvery investigation follows 10 phases in order. The orchestrator enforces strict rules: sequential benchmarks only, 60-second minimum run durations, one change per experiment, and checkpoint commits after each phase.\n\n1. **Setup** - Confirm the scenario, success criteria, and benchmark command. The benchmark must emit metrics between `PERF_METRICS_START` / `PERF_METRICS_END` markers.\n\n2. **Baseline** - Run the benchmark for 60+ seconds with a 10-second warmup. Results are stored as `baselines/<version>.json`. This is the reference point for all comparisons.\n\n3. **Breaking point** - Binary search across a parameterized range to find the threshold where performance degrades. Uses 30-second runs (the only exception to the 60-second rule).\n\n4. **Constraints** - Run the benchmark under CPU and memory limits (default: 1 CPU, 1GB RAM). Compare against the unconstrained baseline to identify resource sensitivity.\n\n5. **Hypotheses** - Generate up to 5 hypotheses about the root cause, each backed by evidence from git history and code analysis. No guessing - every hypothesis needs a file path or commit reference.\n\n6. **Code paths** - Use repo-intel to identify entry points, hot files, and call chains relevant to the scenario. Narrows the search space before profiling.\n\n7. **Profiling** - Run language-specific profilers: `--cpu-prof` for Node.js, JFR for Java, cProfile for Python, pprof for Go. Capture file:line hotspots and flame graphs.\n\n8. **Optimization** - Apply one change at a time. Validate with 2+ benchmark runs. Revert between experiments to keep the baseline clean.\n\n9. **Decision** - Based on measured improvement, decide whether to continue optimizing or stop. The verdict and rationale are recorded in the investigation log.\n\n10. **Consolidation** - Write the final baseline, close the evidence log, and mark the investigation complete.\n\n## Usage\n\n```bash\n/perf --phase setup --scenario \"startup time\" --command \"node bench.js\" --version v2.0.0\n/perf --resume                                          # continue where you left off\n/perf --resume --phase profiling                        # jump to a specific phase\n/perf --resume --phase baseline --runs 5 --aggregate median\n/perf --resume --phase optimization --change \"replaced O(n^2) loop with hash lookup\"\n/perf --resume --phase decision --verdict continue --rationale \"20% improvement\"\n```\n\n### Key Flags\n\n| Flag | Description |\n|------|-------------|\n| `--resume` | Continue the active investigation |\n| `--phase <name>` | Target a specific phase |\n| `--command <cmd>` | Benchmark command (must emit PERF_METRICS markers) |\n| `--version <ver>` | Baseline version label |\n| `--duration <sec>` | Override benchmark duration (default 60s) |\n| `--runs <n>` | Number of runs for multi-run benchmarks |\n| `--aggregate <method>` | median, mean, min, or max (default median) |\n| `--change <summary>` | Description of the optimization being tested |\n| `--verdict <v>` | continue or stop |\n\n### Investigation Artifacts\n\nState is persisted under `{state-dir}/perf/`: `investigation.json` (active state), `investigations/<id>.md` (evidence log), and `baselines/<version>.json` (metrics per version).\n\n## Architecture\n\n| Component | Type | Model | Role |\n|-----------|------|-------|------|\n| `perf-orchestrator` | agent | opus | Coordinates all phases, enforces rules |\n| `perf-theory-gatherer` | agent | sonnet | Generates hypotheses from git history and code |\n| `perf-theory-tester` | agent | sonnet | Runs controlled experiments for hypotheses |\n| `perf-analyzer` | agent | sonnet | Synthesizes findings into recommendations |\n| `perf-code-paths` | agent | sonnet | Identifies hot files and entry points |\n| `perf-investigation-logger` | agent | sonnet | Writes structured evidence log entries |\n| `perf-baseline-manager` | skill | - | Baseline storage, one JSON per version |\n| `perf-benchmarker` | skill | - | Sequential benchmark execution |\n| `perf-profiler` | skill | - | Language-specific profiling (CPU, memory, flame graphs) |\n| `perf-analyzer` | skill | - | Synthesis patterns and recommendation templates |\n| `perf-code-paths` | skill | - | Entry-point and hot-file identification patterns |\n| `perf-investigation-logger` | skill | - | Structured evidence log formatting |\n| `perf-theory-gatherer` | skill | - | Hypothesis generation backed by git/code evidence |\n| `perf-theory-tester` | skill | - | Controlled experiment execution patterns |\n\n## Requirements\n\n- [agentsys](https://github.com/agent-sh/agentsys) runtime\n- A benchmark command that emits `PERF_METRICS_START` / `PERF_METRICS_END` markers\n- Language-specific profiler tools installed for the profiling phase (e.g., Node.js `--cpu-prof`, Java JFR, Python cProfile)\n\n## Related Plugins\n\n- [repo-intel](https://github.com/agent-sh/repo-intel) - Unified static analysis: AST symbols, git history, and doc-code sync, used during the code-paths phase\n- [enhance](https://github.com/agent-sh/enhance) - Code analysis that can complement perf findings\n\n## License\n\nMIT\n",
  "bytes": 6284,
  "sha": "81a95eeee6b6f35f4d9d7a3de65a7a1bd1a0eb118fe6e344facedc6937d9d768",
  "repo_slug": "agent-sh/perf",
  "fonte": "repo",
  "truncated": false,
  "api": "https://agentalog.com/api/listings/plg_agent_sh_perf_perf_f504d85f/readme"
}