python-performance
npx machina-cli add skill athola/claude-night-market/python-performance --openclawPython Performance Optimization
Profiling and optimization patterns for Python code.
Table of Contents
Quick Start
# Basic timing
import timeit
time = timeit.timeit("sum(range(1000000))", number=100)
print(f"Average: {time/100:.6f}s")
Verification: Run the command with --help flag to verify availability.
When To Use
- Identifying performance bottlenecks
- Reducing application latency
- Optimizing CPU-intensive operations
- Reducing memory consumption
- Profiling production applications
- Improving database query performance
When NOT To Use
- Async concurrency - use python-async instead
- CPU/GPU system monitoring - use conservation:cpu-gpu-performance
- Async concurrency - use python-async instead
- CPU/GPU system monitoring - use conservation:cpu-gpu-performance
Modules
This skill is organized into focused modules for progressive loading:
profiling-tools
CPU profiling with cProfile, line profiling, memory profiling, and production profiling with py-spy. Essential for identifying where your code spends time and memory.
optimization-patterns
Ten proven optimization patterns including list comprehensions, generators, caching, string concatenation, data structures, NumPy, multiprocessing, and database operations.
memory-management
Memory optimization techniques including leak tracking with tracemalloc and weak references for caches. Depends on profiling-tools.
benchmarking-tools
Benchmarking tools including custom decorators and pytest-benchmark for verifying performance improvements.
best-practices
Best practices, common pitfalls, and exit criteria for performance optimization work. Synthesizes guidance from profiling-tools and optimization-patterns.
Exit Criteria
- Profiled code to identify bottlenecks
- Applied appropriate optimization patterns
- Verified improvements with benchmarks
- Memory usage acceptable
- No performance regressions
Troubleshooting
Common Issues
Command not found Ensure all dependencies are installed and in PATH
Permission errors Check file permissions and run with appropriate privileges
Unexpected behavior
Enable verbose logging with --verbose flag
Source
git clone https://github.com/athola/claude-night-market/blob/master/plugins/parseltongue/skills/python-performance/SKILL.mdView on GitHub Overview
Provides profiling and optimization patterns for Python code to cut latency, reduce memory usage, and validate improvements. It covers CPU profiling with cProfile, memory profiling, production profiling, and benchmarking through focused modules and best practices. Note: Do not use for async concurrency or CPU/GPU monitoring; use python-async or conservation:cpu-gpu-performance as applicable.
How This Skill Works
The skill is organized into focused modules: profiling-tools (CPU and memory profiling, production profiling), optimization-patterns (common speedups and efficiency improvements), memory-management (leak tracking with tracemalloc), benchmarking-tools (custom decorators and pytest-benchmark), and best-practices (guidance and exit criteria). Quick-start demonstrations and exit criteria guide evidence of improvements. It emphasizes identifying bottlenecks, applying the right patterns, and verifying gains with benchmarks to avoid regressions.
When to Use It
- Identifying performance bottlenecks
- Reducing application latency
- Optimizing CPU-intensive operations
- Reducing memory consumption
- Profiling production applications
Quick Start
- Step 1: Run a quick timing test with timeit.timeit("sum(range(1000000))", number=100) and print the average.
- Step 2: Profile the code using cProfile or py-spy to locate hotspots and assess memory with tracemalloc.
- Step 3: Apply an optimization pattern, then re-run benchmarks to verify performance gains.
Best Practices
- Profile first with profiling-tools to locate bottlenecks (cProfile, line profiling, memory profiling)
- Apply optimization-patterns such as list comprehensions, caching, and generators
- Use memory-management techniques (tracemalloc, weak references) to control leaks
- Benchmark improvements with benchmarking-tools to verify gains
- Check for regressions and ensure memory usage stays within acceptable limits
Example Use Cases
- Profile a hot loop with cProfile to identify the top function consuming time
- Replace slow string concatenation with join or f-strings and caching results
- Use generators to process large data streams without loading everything into memory
- Add memoization to expensive function calls to avoid repeated work
- Benchmark before/after changes with pytest-benchmark or custom decorators
Frequently Asked Questions
Related Skills
troubleshooting
chaterm/terminal-skills
性能问题排查
sql-optimization
chaterm/terminal-skills
SQL 优化与调优
benchmarking
chaterm/terminal-skills
性能基准测试
profiling
chaterm/terminal-skills
--- name: profiling description: 性能分析 version: 1.0.0 author: terminal-skills tags: [performance, profiling, perf, flamegraph, strace, cpu] --- # 性能分析 ## 概述 CPU/内存分析、火焰图、追踪技能。 ## perf 工具 ### 基础命令 ```bash # 安装 apt install linux-tools-common linux-tools-$(uname -r) # CPU 采样 perf record -g -p PID p
tuning
chaterm/terminal-skills
--- name: tuning description: 系统调优 version: 1.0.0 author: terminal-skills tags: [performance, tuning, sysctl, kernel, optimization] --- # 系统调优 ## 概述 内核参数、文件系统、网络优化技能。 ## 内核参数调优 ### 内存管理 ```bash # /etc/sysctl.d/99-memory.conf # 减少交换倾向 vm.swappiness = 10 # 脏页刷新 vm.dirty_ratio = 20 vm.dirty_backg
Database Design Expert
martinholovsky/claude-skills-generator
Expert in database schema design with focus on normalization, indexing strategies, FTS optimization, and performance-oriented architecture for desktop applications