About python-performance-optimization
A Python performance-optimization skill for developers diagnosing and improving measured bottlenecks. It emphasizes profiling, correctness checks, and reporting before-and-after results.
Key features
- 01Collects workload and target metrics
- 02Guides profiling by bottleneck type
- 03Suggests optimization approaches
- 04Requires correctness checks and remeasurement
- 05Provides a results-reporting template
Use cases
- 01Investigating a slow Python workload
- 02Choosing a profiler for CPU or memory
- 03Planning changes against a measured bottleneck
- 04Documenting performance results
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ jurgendn/ agent-skills --skill python-performance-optimizationAfter installing, type/python-performance-optimizationin Claude Code to confirm it loaded.
Bundled filesreferences/advanced-patterns.md
Details
From the project READMEPython Performance Optimization
Measure first. Optimize the bottleneck that matters. Keep correctness tests around every performance change.
For advanced patterns such as NumPy vectorization, caching, memory management,
parallelism, async I/O, database optimization, and benchmarking tools, read
references/advanced-patterns.md.
Intake
Collect:
- workload and input size;
- target metric: latency, throughput, memory, CPU, I/O;
- current measurement and desired target;
- environment and hardware;
- correctness tests or golden outputs.
Profiling Order
- Reproduce the slow path with a realistic input.
- Add a simple wall-clock measurement.
- Use the right profiler:
cProfile/py-spyfor CPU;line_profilerfor line-level hot spots;memory_profiler/tracemallocfor memory;- application metrics for production latency.
- Identify the smallest hot path worth changing.
- Optimize one bottleneck.
- Re-measure and verify correctness.
Common Fix Classes
- Better algorithm or data structure.
- Avoid repeated work with caching.
- Batch I/O or database calls.
- Use generators/streaming for memory.
- Vectorize numerical work with NumPy/Pandas/JAX/PyTorch when appropriate.
- Move true CPU-bound parallelism to multiprocessing/native libraries.
Rules
- Do not optimize without a baseline measurement.
- Do not trade correctness for speed silently.
- Do not optimize cold code.
- Prefer algorithmic wins over micro-optimizations.
- Record before/after numbers and input sizes.
Output
Return:
- performance target;
- measurement method;
- bottleneck evidence;
- optimization plan ranked by expected impact;
- correctness guard;
- before/after reporting template.
Comments
Markdown supported