python-performance-optimization
Optimize Python performance with profiling
Also available from: ActiveInferenceInstitute
Slow Python code hides bottlenecks that waste resources and time. This skill guides you through profiling and optimization steps with concrete tools and patterns.
Download the skill ZIP
Upload in Claude
Go to Settings → Capabilities → Skills → Upload skill
Toggle on and start using
Test it
Using "python-performance-optimization". Help me profile a slow data processing function and suggest improvements.
Expected outcome:
- Run cProfile and sort by cumulative time to find the hottest functions
- Replace list accumulation with generators where possible to reduce memory
- Consider multiprocessing for CPU bound steps after profiling confirms bottlenecks
Using "python-performance-optimization". My Python API responds slowly under load. How do I find the bottleneck?
Expected outcome:
- Use cProfile to identify which functions consume the most time
- Check for N+1 query patterns in database access
- Consider adding lru_cache to repeated computations
- Profile with py-spy on production if safe
Using "python-performance-optimization". Show me how to optimize memory usage in a long-running script.
Expected outcome:
- Use tracemalloc to track allocations and find leaks
- Replace lists with generators for streaming data
- Use __slots__ in classes to reduce per-instance memory
- Consider WeakValueDictionary for caches
Security Audit
SafeDocumentation-only skill containing Python optimization guidance. All static findings are false positives caused by the scanner misinterpreting code examples in markdown documentation. The skill provides instructional content only; no code is executed, no network calls are made, and no files are accessed. Users receive guidance on profiling tools and optimization patterns.
Risk Factors
⚙️ External commands (53)
Quality Score
What You Can Build
Reduce API latency
Profile slow endpoints and apply caching or data structure changes for faster responses.
Speed up batch jobs
Optimize loops, memory usage, and I/O patterns in data pipelines.
Performance review plan
Create a profiling plan and prioritize fixes for the largest bottlenecks.
Try These Prompts
Show a minimal cProfile example for a slow function and explain how to read the top cumulative time results.
Explain how to use line_profiler on one function and how to interpret per line timings.
Provide a memory_profiler or tracemalloc approach to find peak allocations in a script.
Suggest optimization options for a CPU bound pipeline, including algorithm changes, caching, and multiprocessing.
Best Practices
- Profile before optimizing to confirm bottlenecks exist
- Benchmark each change to validate that improvements occurred
- Focus optimization effort on hot paths that run most often
Avoid
- Optimizing without first profiling to identify real bottlenecks
- Changing multiple variables between benchmarks making it hard to measure impact
- Over-optimizing cold code paths that rarely execute