Lift
Intent
Deliver aggressive, measurement-driven performance improvements (latency/throughput/memory/GC/tail) with correctness preserved and regressions guarded.
Double Diamond fit
Lift lives in Define -> Deliver:
- Define: write a performance contract and pick a proof workload.
- Deliver: measure baseline, profile, run tight experiments, then ship with a guard.
Hard Rules
- Measure before and after every optimization (numbers + environment + command).
- Optimize the bottleneck, not the loudest hunch (profile/trace/counters required).
- Avoid micro-optimizations until algorithmic wins are exhausted.
- Keep correctness and safety invariants intact.
- Require a correctness signal before and after; never accept a perf win with failing correctness.
- Do not change semantics without explicit user approval.
- If you cannot run a proof workload, label the output
UNMEASURED and provide exact benchmark/profiling commands; treat all optimization ideas as hypotheses.
- Stop and ask before raising resource/cost ceilings (CPU cores, memory footprint, I/O bytes, external calls), unless explicitly requested.
- Stop when ROI is negative or risk exceeds benefit.
- When running
/tw-lift on /tw-lift with /tw-ms, require a runnable proof bundle before done.
Default policy (non-interactive)
Goal: stay autonomous without inventing SLOs.
Mode selection (measured vs unmeasured)
If you can run a proof workload, operate in measured mode. Otherwise operate in unmeasured mode.
- Measured: run baseline + variant on the same workload; include numbers, bottleneck evidence, and a correctness signal.
- Unmeasured: start with
UNMEASURED: <why>; do not claim wins; provide the exact commands you would run to produce baseline/after + profiling evidence.
Contract derivation
If the user did not provide a numeric target:
- Define the contract as: "Improve on vs baseline; report delta; do not regress ."
- Do not invent SLO numbers; treat the goal as "maximize improvement within constraints".
Metric defaults (pick one):
- Request-like: latency p95 (also report p50/p99).
- Batch/offline: throughput (also report CPU% and memory).
- Memory issues: peak RSS + alloc rate / GC pause (also report latency).
Workload selection (proof signal)
Pick the first runnable, representative workload you can find:
- User-provided repro/command.
- Existing repo benchmark/harness (README, scripts, Makefile/justfile/taskfile).
- A minimal harness around the hot path (microbench) plus a correctness signal.
Stop and ask only if you cannot find or create any runnable proof workload without product ambiguity.
Experiment hygiene
- Change one variable at a time; keep diffs small and reversible.
- Reject wins smaller than the noise floor; re-run when variance is high.
- Track second-order regressions (memory, tail latency, CPU) even if the primary metric improves.
Workflow (Opinionated)
- Preflight
- Capture environment (hardware/OS/runtime flags).
- Pick a correctness signal and a performance workload; run each once to verify they work.
- Performance contract
- Metric + percentile + workload + environment + constraints.
- Baseline
- Warm up; collect enough samples for stable percentiles (keep raw samples when possible).
- Locate the bottleneck
- Profile/trace; classify bound (CPU/memory/I/O/lock/tail).
- Choose the highest-leverage lever
- Follow the optimization ladder: delete work -> algorithm -> data/layout -> concurrency -> I/O -> micro-arch -> runtime/compiler.
- Run tight experiments (loop)
- Hypothesis -> patch -> measure -> accept/reject -> record.
- Ship with guards
- Add/extend a benchmark, budget, or alert; document trade-offs.
- Report
- Present baseline vs variant and the evidence trail.
Decision Gates
- If the baseline is noisy or unstable, fix measurement first.
- If the complexity class dominates, change the algorithm first.
- If tail latency dominates, treat variance reduction as the primary goal.
- If I/O dominates, reduce bytes, syscalls, or round trips before CPU tuning.
- If the only remaining wins require higher resource/cost ceilings, surface the trade-off and ask.
- Stop when ROI is negative or risk exceeds benefit.
Deliverable format (chat)
If unmeasured, prefix the response with UNMEASURED: <reason> and fill sections with a concrete measurement plan (no claimed deltas).
Output exactly these sections (short, numbers-first):
Performance contract
- Metric + percentile:
- Workload command:
- Dataset:
- Environment:
- Constraints:
Baseline
- Samples + warmup:
- Results (min/p50/p95/p99/max):
- Notes on variance/noise (or estimated noise floor):
Bottleneck evidence
- Tool + key finding:
- Hot paths / contention points:
- Bound classification:
Experiments
- <1-3 entries> Hypothesis -> change -> measurement delta -> decision
Result
- Variant results (min/p50/p95/p99/max):
- Delta vs baseline:
- Confidence (noise/variance):
- Trade-offs / regressions checked:
Regression guard
- Benchmark/budget added:
- Threshold (if any):
Validation
- Correctness command(s) -> pass/fail
- Performance command(s) -> numbers
Residual risks / next steps
lift_compliance: mode=<measured|unmeasured>; workload=<yes|no>; baseline=<yes|no>; after=<yes|no>; correctness=<yes|no>; bottleneck_evidence=<yes|no>
Core References (Load on Demand)
- Read
references/playbook.md for the master flow and optimization ladder.
- Read
references/measurement.md for benchmarking and statistical rigor.
- Read
references/profiling-tools.md for a profiler/tool matrix and evidence artifacts.
- Read
references/algorithms-and-data-structures.md for algorithmic levers.
- Read
references/systems-and-architecture.md for CPU, memory, and OS tactics.
- Read
references/latency-throughput-tail.md for queueing and tail behavior.
- Read
references/optimization-tactics.md for a tactical catalog by layer.
- Read
references/checklists.md for fast triage and validation checklists.
- Read
references/anti-patterns.md to avoid common traps.
Assets
- Use
assets/perf-report-template.md as a ready-to-edit report.
- Use
assets/experiment-log-template.md to track experiments and results.
Output Expectations
- Deliver a baseline, bottleneck evidence, hypothesis, experiment plan, and measured result.
- Provide a minimal diff that preserves correctness and includes a regression guard.
- Explain trade-offs in plain language and record the measured delta.
1---2name: tw-lift3description: "Comprehensive, measurement-driven performance optimization for latency, throughput, memory/GC, and tail behavior. Use when the user asks to optimize/speed up, reduce latency (p95/p99), increase throughput/QPS, lower CPU/memory/allocations/GC pauses, profile hot paths, or run a benchmarked perf pass (including JSONL/query-heavy code). Requires before/after measurement on a runnable workload (or an explicit `UNMEASURED` plan) plus a correctness gate."4allowed-tools: Bash5---67# Lift89## Intent1011Deliver aggressive, measurement-driven performance improvements (latency/throughput/memory/GC/tail) with correctness preserved and regressions guarded.1213## Double Diamond fit1415Lift lives in Define -> Deliver:16- Define: write a performance contract and pick a proof workload.17- Deliver: measure baseline, profile, run tight experiments, then ship with a guard.1819## Hard Rules2021- Measure before and after every optimization (numbers + environment + command).22- Optimize the bottleneck, not the loudest hunch (profile/trace/counters required).23- Avoid micro-optimizations until algorithmic wins are exhausted.24- Keep correctness and safety invariants intact.25- Require a correctness signal before and after; never accept a perf win with failing correctness.26- Do not change semantics without explicit user approval.27- If you cannot run a proof workload, label the output `UNMEASURED` and provide exact benchmark/profiling commands; treat all optimization ideas as hypotheses.28- Stop and ask before raising resource/cost ceilings (CPU cores, memory footprint, I/O bytes, external calls), unless explicitly requested.29- Stop when ROI is negative or risk exceeds benefit.30- When running `/tw-lift` on `/tw-lift` with `/tw-ms`, require a runnable proof bundle before done.3132## Default policy (non-interactive)3334Goal: stay autonomous without inventing SLOs.3536### Mode selection (measured vs unmeasured)3738If you can run a proof workload, operate in measured mode. Otherwise operate in unmeasured mode.3940- Measured: run baseline + variant on the same workload; include numbers, bottleneck evidence, and a correctness signal.41- Unmeasured: start with `UNMEASURED: <why>`; do not claim wins; provide the exact commands you would run to produce baseline/after + profiling evidence.4243### Contract derivation4445If the user did not provide a numeric target:46- Define the contract as: "Improve <metric> on <workload> vs baseline; report delta; do not regress <constraints>."47- Do not invent SLO numbers; treat the goal as "maximize improvement within constraints".4849Metric defaults (pick one):50- Request-like: latency p95 (also report p50/p99).51- Batch/offline: throughput (also report CPU% and memory).52- Memory issues: peak RSS + alloc rate / GC pause (also report latency).5354### Workload selection (proof signal)5556Pick the first runnable, representative workload you can find:571. User-provided repro/command.582. Existing repo benchmark/harness (README, scripts, Makefile/justfile/taskfile).593. A minimal harness around the hot path (microbench) plus a correctness signal.6061Stop and ask only if you cannot find or create any runnable proof workload without product ambiguity.6263### Experiment hygiene6465- Change one variable at a time; keep diffs small and reversible.66- Reject wins smaller than the noise floor; re-run when variance is high.67- Track second-order regressions (memory, tail latency, CPU) even if the primary metric improves.6869## Workflow (Opinionated)70710. Preflight72 - Capture environment (hardware/OS/runtime flags).73 - Pick a correctness signal and a performance workload; run each once to verify they work.741. Performance contract75 - Metric + percentile + workload + environment + constraints.762. Baseline77 - Warm up; collect enough samples for stable percentiles (keep raw samples when possible).783. Locate the bottleneck79 - Profile/trace; classify bound (CPU/memory/I/O/lock/tail).804. Choose the highest-leverage lever81 - Follow the optimization ladder: delete work -> algorithm -> data/layout -> concurrency -> I/O -> micro-arch -> runtime/compiler.825. Run tight experiments (loop)83 - Hypothesis -> patch -> measure -> accept/reject -> record.846. Ship with guards85 - Add/extend a benchmark, budget, or alert; document trade-offs.867. Report87 - Present baseline vs variant and the evidence trail.88## Decision Gates8990- If the baseline is noisy or unstable, fix measurement first.91- If the complexity class dominates, change the algorithm first.92- If tail latency dominates, treat variance reduction as the primary goal.93- If I/O dominates, reduce bytes, syscalls, or round trips before CPU tuning.94- If the only remaining wins require higher resource/cost ceilings, surface the trade-off and ask.95- Stop when ROI is negative or risk exceeds benefit.9697## Deliverable format (chat)9899If unmeasured, prefix the response with `UNMEASURED: <reason>` and fill sections with a concrete measurement plan (no claimed deltas).100101Output exactly these sections (short, numbers-first):102103**Performance contract**104- Metric + percentile:105- Workload command:106- Dataset:107- Environment:108- Constraints:109110**Baseline**111- Samples + warmup:112- Results (min/p50/p95/p99/max):113- Notes on variance/noise (or estimated noise floor):114115**Bottleneck evidence**116- Tool + key finding:117- Hot paths / contention points:118- Bound classification:119120**Experiments**121- <1-3 entries> Hypothesis -> change -> measurement delta -> decision122123**Result**124- Variant results (min/p50/p95/p99/max):125- Delta vs baseline:126- Confidence (noise/variance):127- Trade-offs / regressions checked:128129**Regression guard**130- Benchmark/budget added:131- Threshold (if any):132133**Validation**134- Correctness command(s) -> pass/fail135- Performance command(s) -> numbers136137**Residual risks / next steps**138- <bullets>139140`lift_compliance: mode=<measured|unmeasured>; workload=<yes|no>; baseline=<yes|no>; after=<yes|no>; correctness=<yes|no>; bottleneck_evidence=<yes|no>`141142## Core References (Load on Demand)143144- Read `references/playbook.md` for the master flow and optimization ladder.145- Read `references/measurement.md` for benchmarking and statistical rigor.146- Read `references/profiling-tools.md` for a profiler/tool matrix and evidence artifacts.147- Read `references/algorithms-and-data-structures.md` for algorithmic levers.148- Read `references/systems-and-architecture.md` for CPU, memory, and OS tactics.149- Read `references/latency-throughput-tail.md` for queueing and tail behavior.150- Read `references/optimization-tactics.md` for a tactical catalog by layer.151- Read `references/checklists.md` for fast triage and validation checklists.152- Read `references/anti-patterns.md` to avoid common traps.153154## Assets155156- Use `assets/perf-report-template.md` as a ready-to-edit report.157- Use `assets/experiment-log-template.md` to track experiments and results.158159## Output Expectations160161- Deliver a baseline, bottleneck evidence, hypothesis, experiment plan, and measured result.162- Provide a minimal diff that preserves correctness and includes a regression guard.163- Explain trade-offs in plain language and record the measured delta.