# Py Performance Tuning

> Advanced techniques for profiling and optimizing Python code for speed and memory.

- Skill: `jcorpac/py-performance-tuning` (Agent Skill)
- Install (CLI): `npx skillmds@latest add jcorpac/py-performance-tuning`
- Raw SKILL.md: https://api.skillmd.com/api/skills/jcorpac/py-performance-tuning/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: jcorpac (https://skillmd.com/u/jcorpac)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/jcorpac/py-performance-tuning

---


# Python Performance Tuning

Optimization should always follow measurement. This skill focuses on a data-driven approach to making Python go fast.

## The Performance Loop
1.  **Measure**: Profile with `cProfile` or `Pyinstrument`.
2.  **Analyze**: Identify bottlenecks (CPU-bound vs. I/O-bound).
3.  **Optimize**: Apply targeted fixes.
4.  **Verify**: Re-profile to confirm gains.

## Optimization Strategies
- **Vectorization**: Use NumPy/Pandas to replace explicit loops.
- **Just-in-Time (JIT)**: Use `Numba` for numerical heavy-lifting.
- **Compiled Extensions**: Write performance-critical modules in Cython or Rust (PyO3).
- **Algorithmic Fixes**: Check O(n) complexity before micro-optimizing.

## Tools
- `timeit`: For micro-benchmarking snippets.
- `memory_profiler`: For tracking memory leaks and peaks.
- `scalene`: A high-performance CPU, GPU, and memory profiler.


