# Python Performance Optimization (python-performance-optimization)

> Profiles Python code with cProfile, line_profiler, memory_profiler and py-spy, then optimizes bottlenecks using documented performance patterns.

- Category: [Performance](https://www.myskills.tools/en/categories/performance/)
- Source: Community · Seth Hobson
- Repository: https://github.com/wshobson/agents/tree/main/plugins/python-development/skills/python-performance-optimization (commit 0f73766)
- SKILL.md: https://github.com/wshobson/agents/blob/main/plugins/python-development/skills/python-performance-optimization/SKILL.md
- Install command: `npx skills add wshobson/agents --skill python-performance-optimization`
- License: MIT
- Compatible with: Claude Code, Codex, Cursor, Copilot, OpenCode
- Permissions: read-repo ✓, write-files ✓, shell ✓, network ✗
- Status: Scan passed
- A rule scan cannot catch every risk. Read this skill's SKILL.md and check its permissions before installing.

## Core rule

Profile before optimizing to find the real bottlenecks.

## Execution Phases

1. **Time it** — Get rough numbers with time and accurate, repeatable ones with timeit.
2. **Profile** — Use cProfile for CPU, line_profiler line by line, memory_profiler for memory, and py-spy for running production processes.
3. **Optimize hot paths** — Focus on frequently run code: dict and set lookups, comprehensions, generators, built-ins, lru_cache and batched I/O.
4. **Scale up when needed** — Use NumPy for numerics, multiprocessing for CPU-bound work, async I/O for I/O-bound work, and batched, optimized database queries.

## Permissions (summarised from SKILL.md)

| Capability | Needed | Details |
|---|---|---|
| File writes | Required | Edits Python code to apply optimization patterns. |
| Command execution | Required | Runs profiling tools such as timeit, cProfile, kernprof, memory_profiler and py-spy. |
| Network outbound | Not required | No network access is required, though some profilers may need a prior pip install. |

## SKILL.md frontmatter (YAML)

```yaml
---
name: python-performance-optimization
description: Profile and optimize Python code using cProfile, memory profilers, and performance best practices. Use when debugging slow Python code, optimizing bottlenecks, or improving application performance.
---
```

Home: https://www.myskills.tools/en/ · URL: https://www.myskills.tools/en/skills/python-performance-optimization/
