Performance Speedup
Purpose
Turn a vague "it is slow" signal into an evidence-based performance improvement workflow:
- find the real bottleneck
- avoid guessing
- rank optimizations by expected impact, cost, and risk
- implement the strongest changes first
- remeasure after changes
This is a runtime and performance skill, not a generic debugging skill.
Use when
Use this skill when:
- the user says a module, handler, job, query, or pipeline is slow
- logs or traces show large runtime, latency spikes, throughput collapse, or obvious stalls
- profiling data exists or should be added
- the task is to speed up code rather than only make it correct
- a refactor is blocked by uncertainty about where time is being spent
Typical trigger phrases:
- "ускорь это"
- "что-то медленно работает"
- "этот модуль слишком долгий"
- "посмотри логи, тут очень долго"
- "optimize performance"
- "speed this up"
- "find the bottleneck"
- "why is this handler taking 2.8s"
- "сделай аудит производительности"
Do not use when
Do not use this skill for:
- ordinary bug fixing where the issue is correctness, not speed
- generic refactoring with no performance signal
- build speed, install speed, or CI speed unless the task is explicitly about those
- infra provisioning or hardware sizing
- "clean up code" tasks without bottleneck evidence
- premature micro-optimization of cold code paths
Inputs
Expected inputs:
- the slow module, code path, query, handler, or pipeline
- logs, traces, timings, or a code location
- any reproduction command, benchmark, or failing workload
Optional inputs:
- profiler output
- flamegraph, trace, or query plan
- dependency or runtime version info
- sample data shape, batch size, or request volume
Outputs
Always produce:
- bottleneck summary
- evidence used
- bottleneck classification
- ranked optimization opportunities
- changes applied, if any
- before/after measurement, or the exact measurement gap if no benchmark was possible
- residual risks or unknowns
Constraints
- Start with evidence, not optimization folklore.
- Do not select tools before locating the hot path.
- Preserve correctness, ordering semantics, and acceptable memory bounds.
- Prefer the smallest high-confidence change that plausibly removes the dominant bottleneck.
- Use a bounded subagent for heavy log, trace, or profile reading when that reduces main-thread noise.
- If measurement is missing, the first useful output is a measurement plan, not a speculative rewrite.
Procedure
Start with evidence, not guesses.
First inspect the strongest available signals:
- logs
- traces
- profiler output
- query plans
- timings already present in code
- reproduction commands
If evidence is weak, add minimal measurement.
Introduce the smallest instrumentation needed to localize the slowdown:
- timing around suspicious stages
- a lightweight benchmark
- a profiler run
- a database
EXPLAIN or ANALYZE when relevant
Localize the hot path.
Identify where time is actually going:
- one function
- one loop
- one query
- one serialization step
- repeated network round trips
- file I/O
- object allocation or copying
- lock contention
- redundant recomputation
- logging overhead
Classify the bottleneck before proposing tools.
Classify into one or more of:
- algorithmic or asymptotic
- CPU-bound compute
- memory, allocation, or copy pressure
- disk or object-store I/O
- database or query planning or indexing
- network latency or too many round trips
- serialization, parsing, or encoding
- concurrency, locking, or synchronization
- startup, import, or initialization
- redundant work, no caching, or no batching
- excessive logging or tracing overhead
Build a ranked optimization plan.
For each candidate speedup, estimate:
- why it should help
- expected impact
- implementation cost
- correctness risk
- whether it needs benchmarking first
Prioritize high-confidence, high-leverage fixes.
Prefer in this order when supported by evidence:
- remove unnecessary work
- fix bad asymptotics or data structures
- reduce round trips or passes over data
- push computation closer to the data
- batch operations
- add caching only when reuse exists
- use vectorized, columnar, or query-engine paths for tabular workloads
- improve query plans and indexing
- reduce allocations, copies, or serialization
- introduce concurrency only when the bottleneck actually benefits from it
- apply micro-optimizations last
Use tools as options, not dogma.
Tools are suggestions, not defaults:
- DuckDB, Polars, or Arrow for large local tabular transformations or pushdown-style processing
- query plans and indexes for database bottlenecks
- vectorization for numeric or dataframe-heavy loops
- batching and connection reuse for chatty network or DB traffic
- memoization or caching for repeated pure work
- worker pools or async concurrency for latency hiding where appropriate
Do not force a tool if the evidence points elsewhere.
Keep correctness constraints explicit.
Every speedup must preserve:
- outputs
- ordering semantics, if important
- numerical stability, if relevant
- transactional or concurrency guarantees
- acceptable memory bounds for the target environment
Re-measure after changes.
Compare before and after with the narrowest reliable measurement available.
If measurement cannot be reproduced, state that clearly.
Stop at the right point.
If the remaining gains require architectural redesign, say so explicitly instead of silently over-refactoring.
Decision rules
Evidence rule
Never choose an optimization path only because it is fashionable or fast in general.
Always tie it to observed evidence.
Algorithm-first rule
If the slowdown is dominated by asymptotics, redundant passes, N+1 behavior, or repeated work,
prefer structural fixes over micro-tuning.
Tool-selection rule
DuckDB, Polars, caching, vectorization, concurrency, or specialized engines are options.
Use them only when the workload shape actually matches them.
Measurement rule
If there is no trustworthy measurement yet, the first output should be a measurement plan or instrumentation step,
not a speculative rewrite.
Risk rule
Prefer the smallest change that can plausibly remove the dominant bottleneck.
Do not trade large correctness or maintainability risk for minor speedups.
Subagent use
Prefer the custom subagent perf-auditor when performance investigation would otherwise bloat the main thread.
Typical good uses:
- one concrete slow module
- one request handler
- one batch job
- one SQL path
- one pipeline stage
- one suspicious hot path after a refactor
The subagent is not limited to reading large logs or traces. It can also:
- inspect the relevant code path
- synthesize incomplete timing evidence
- classify the bottleneck
- propose the next measurement step when evidence is still weak
- return a compact ranked speedup memo
The main thread should then:
- decide what to implement
- apply the changes
- remeasure
- summarize the result
Definition of done
- The dominant bottleneck is identified from evidence or the exact missing measurement is named.
- Optimization candidates are ranked rather than listed randomly.
- At least one high-confidence improvement path is selected or explicitly deferred with reason.
- Before/after measurement exists, or the absence of measurement is called out precisely.
- Remaining risks and unknowns are explicit.
Final response format
Return a compact summary with:
- Bottleneck
- Evidence
- Bottleneck type
- Ranked speedups
- Changes applied
- Before/after measurement
- Remaining risks or next steps
Positive examples
Use this skill for:
- "ускорь этот handler"
- "этот batch job идёт 18 минут, разберись"
- "смотри логи, тут всё тормозит"
- "find the bottleneck in this pipeline"
- "optimize this pandas-heavy path"
- "эта SQL-часть слишком медленная"
- "this module is slow after the refactor"
Negative examples
Do not use this skill for:
- "исправь баг в парсере"
- "сделай код чище"
- "почему тесты падают"
- "ускорь npm install"
- "сделай rebase"
- "напиши PR description"
1---2name: performance-speedup3description: Audit and speed up a slow module, code path, query, batch job, pipeline, or request handler. Trigger when the user asks to speed up or optimize performance, reports that something is slow, shares logs, traces, timings, or profiles showing high latency or low throughput, or when the current coding task clearly depends on fixing a runtime bottleneck. Diagnose before changing code: identify the hot path, classify the bottleneck (algorithmic, CPU, I/O, database, network, memory, serialization, contention, logging, or redundant work), propose ranked optimizations, apply the highest-confidence improvements, and remeasure. Use profiling, query plans, logs, benchmarks, and suitable tools such as vectorization, batching, caching, indexing, concurrency, DuckDB, or Polars when justified by evidence. Do not use for generic bug fixing, correctness-only debugging, build or install speed, infra provisioning, or vague optimize requests with no performance signal.4---56# Performance Speedup78## Purpose910Turn a vague "it is slow" signal into an evidence-based performance improvement workflow:11- find the real bottleneck12- avoid guessing13- rank optimizations by expected impact, cost, and risk14- implement the strongest changes first15- remeasure after changes1617This is a runtime and performance skill, not a generic debugging skill.1819## Use when2021Use this skill when:22- the user says a module, handler, job, query, or pipeline is slow23- logs or traces show large runtime, latency spikes, throughput collapse, or obvious stalls24- profiling data exists or should be added25- the task is to speed up code rather than only make it correct26- a refactor is blocked by uncertainty about where time is being spent2728Typical trigger phrases:29- "ускорь это"30- "что-то медленно работает"31- "этот модуль слишком долгий"32- "посмотри логи, тут очень долго"33- "optimize performance"34- "speed this up"35- "find the bottleneck"36- "why is this handler taking 2.8s"37- "сделай аудит производительности"3839## Do not use when4041Do not use this skill for:42- ordinary bug fixing where the issue is correctness, not speed43- generic refactoring with no performance signal44- build speed, install speed, or CI speed unless the task is explicitly about those45- infra provisioning or hardware sizing46- "clean up code" tasks without bottleneck evidence47- premature micro-optimization of cold code paths4849## Inputs5051Expected inputs:52- the slow module, code path, query, handler, or pipeline53- logs, traces, timings, or a code location54- any reproduction command, benchmark, or failing workload5556Optional inputs:57- profiler output58- flamegraph, trace, or query plan59- dependency or runtime version info60- sample data shape, batch size, or request volume6162## Outputs6364Always produce:651. bottleneck summary662. evidence used673. bottleneck classification684. ranked optimization opportunities695. changes applied, if any706. before/after measurement, or the exact measurement gap if no benchmark was possible717. residual risks or unknowns7273## Constraints7475- Start with evidence, not optimization folklore.76- Do not select tools before locating the hot path.77- Preserve correctness, ordering semantics, and acceptable memory bounds.78- Prefer the smallest high-confidence change that plausibly removes the dominant bottleneck.79- Use a bounded subagent for heavy log, trace, or profile reading when that reduces main-thread noise.80- If measurement is missing, the first useful output is a measurement plan, not a speculative rewrite.8182## Procedure83841. Start with evidence, not guesses.85 First inspect the strongest available signals:86 - logs87 - traces88 - profiler output89 - query plans90 - timings already present in code91 - reproduction commands92932. If evidence is weak, add minimal measurement.94 Introduce the smallest instrumentation needed to localize the slowdown:95 - timing around suspicious stages96 - a lightweight benchmark97 - a profiler run98 - a database `EXPLAIN` or `ANALYZE` when relevant991003. Localize the hot path.101 Identify where time is actually going:102 - one function103 - one loop104 - one query105 - one serialization step106 - repeated network round trips107 - file I/O108 - object allocation or copying109 - lock contention110 - redundant recomputation111 - logging overhead1121134. Classify the bottleneck before proposing tools.114 Classify into one or more of:115 - algorithmic or asymptotic116 - CPU-bound compute117 - memory, allocation, or copy pressure118 - disk or object-store I/O119 - database or query planning or indexing120 - network latency or too many round trips121 - serialization, parsing, or encoding122 - concurrency, locking, or synchronization123 - startup, import, or initialization124 - redundant work, no caching, or no batching125 - excessive logging or tracing overhead1261275. Build a ranked optimization plan.128 For each candidate speedup, estimate:129 - why it should help130 - expected impact131 - implementation cost132 - correctness risk133 - whether it needs benchmarking first1341356. Prioritize high-confidence, high-leverage fixes.136 Prefer in this order when supported by evidence:137 - remove unnecessary work138 - fix bad asymptotics or data structures139 - reduce round trips or passes over data140 - push computation closer to the data141 - batch operations142 - add caching only when reuse exists143 - use vectorized, columnar, or query-engine paths for tabular workloads144 - improve query plans and indexing145 - reduce allocations, copies, or serialization146 - introduce concurrency only when the bottleneck actually benefits from it147 - apply micro-optimizations last1481497. Use tools as options, not dogma.150 Tools are suggestions, not defaults:151 - DuckDB, Polars, or Arrow for large local tabular transformations or pushdown-style processing152 - query plans and indexes for database bottlenecks153 - vectorization for numeric or dataframe-heavy loops154 - batching and connection reuse for chatty network or DB traffic155 - memoization or caching for repeated pure work156 - worker pools or async concurrency for latency hiding where appropriate157 Do not force a tool if the evidence points elsewhere.1581598. Keep correctness constraints explicit.160 Every speedup must preserve:161 - outputs162 - ordering semantics, if important163 - numerical stability, if relevant164 - transactional or concurrency guarantees165 - acceptable memory bounds for the target environment1661679. Re-measure after changes.168 Compare before and after with the narrowest reliable measurement available.169 If measurement cannot be reproduced, state that clearly.17017110. Stop at the right point.172 If the remaining gains require architectural redesign, say so explicitly instead of silently over-refactoring.173174## Decision rules175176### Evidence rule177178Never choose an optimization path only because it is fashionable or fast in general.179Always tie it to observed evidence.180181### Algorithm-first rule182183If the slowdown is dominated by asymptotics, redundant passes, N+1 behavior, or repeated work,184prefer structural fixes over micro-tuning.185186### Tool-selection rule187188DuckDB, Polars, caching, vectorization, concurrency, or specialized engines are options.189Use them only when the workload shape actually matches them.190191### Measurement rule192193If there is no trustworthy measurement yet, the first output should be a measurement plan or instrumentation step,194not a speculative rewrite.195196### Risk rule197198Prefer the smallest change that can plausibly remove the dominant bottleneck.199Do not trade large correctness or maintainability risk for minor speedups.200201## Subagent use202203Prefer the custom subagent `perf-auditor` when performance investigation would otherwise bloat the main thread.204205Typical good uses:206- one concrete slow module207- one request handler208- one batch job209- one SQL path210- one pipeline stage211- one suspicious hot path after a refactor212213The subagent is not limited to reading large logs or traces. It can also:214- inspect the relevant code path215- synthesize incomplete timing evidence216- classify the bottleneck217- propose the next measurement step when evidence is still weak218- return a compact ranked speedup memo219220The main thread should then:221- decide what to implement222- apply the changes223- remeasure224- summarize the result225226## Definition of done227228- The dominant bottleneck is identified from evidence or the exact missing measurement is named.229- Optimization candidates are ranked rather than listed randomly.230- At least one high-confidence improvement path is selected or explicitly deferred with reason.231- Before/after measurement exists, or the absence of measurement is called out precisely.232- Remaining risks and unknowns are explicit.233234## Final response format235236Return a compact summary with:237- Bottleneck238- Evidence239- Bottleneck type240- Ranked speedups241- Changes applied242- Before/after measurement243- Remaining risks or next steps244245## Positive examples246247Use this skill for:248- "ускорь этот handler"249- "этот batch job идёт 18 минут, разберись"250- "смотри логи, тут всё тормозит"251- "find the bottleneck in this pipeline"252- "optimize this pandas-heavy path"253- "эта SQL-часть слишком медленная"254- "this module is slow after the refactor"255256## Negative examples257258Do not use this skill for:259- "исправь баг в парсере"260- "сделай код чище"261- "почему тесты падают"262- "ускорь npm install"263- "сделай rebase"264- "напиши PR description"