python-performance-optimization

Profile Python code with cProfile, memory_profiler, line_profiler, and py-spy to identify bottlenecks.

Updated Jan 26, 2026
One-click install
npx skills add https://github.com/erikhoward/agent-rules --skill python-performance-optimization-erikhoward
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-performance-optimization
Source: https://github.com/erikhoward/agent-rules/tree/main/claude/skills/python-performance-optimization
Command: npx skills add https://github.com/erikhoward/agent-rules --skill python-performance-optimization-erikhoward

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Profile and optimize Python code to identify bottlenecks and improve runtime performance.

Core Features & Use Cases

  • Profiling with cProfile, memory_profiler, line_profiler, and py-spy to measure CPU, memory, and function-level performance.
  • Optimization strategies including algorithmic improvements, memory management, caching, parallelism, and NumPy acceleration when appropriate.
  • Use cases include debugging slow Python apps, optimizing hot paths, and speeding up data processing pipelines in production.

Quick Start

Run a profiling workflow on your Python script to identify bottlenecks and implement targeted optimizations.

Frequently Asked Questions about python-performance-optimization

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I find bottlenecks in slow Python code?

To find bottlenecks in slow Python code, you can profile it using cProfile for CPU usage, line_profiler for function-level metrics, and memory_profiler to detect memory leaks. This identifies hot paths for targeted runtime optimization.

What's the best way to profile memory usage in a Python data processing pipeline?

Profiling memory usage in a Python data processing pipeline is best done using memory_profiler to track memory consumption over time. This helps identify memory leaks and optimize memory management within your production pipelines.

Can I optimize CPU-bound Python tasks across large codebases?

Yes, you can optimize CPU-bound Python tasks across large codebases by profiling with py-spy and applying algorithmic improvements, caching, and parallelism. These strategies effectively target and speed up slow hot paths.

Does this approach support integrating py-spy workflows for production profiling?

Yes, this approach supports integrating py-spy workflows for production profiling. It allows you to sample CPU performance of running Python applications without code modifications, enabling real-time bottleneck identification.

When should I use NumPy acceleration for Python performance optimization?

You should use NumPy acceleration for Python performance optimization when handling numerical data processing tasks. It replaces slow Python loops with vectorized operations, significantly speeding up CPU-bound mathematical computations.

Why does my Python app experience memory leaks during execution?

Your Python app experiences memory leaks during execution due to unreferenced objects remaining in memory. Profiling with memory_profiler isolates the specific functions causing the memory buildup so you can apply targeted memory management fixes.