python-performance-optimization

Profile Python CPU, memory, and I/O usage with cProfile and py-spy.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps developers identify and fix Python performance bottlenecks by profiling CPU, memory, and I/O usage.

Core Features & Use Cases

  • CPU and memory profiling with built-in cProfile and memory_profiler to locate hotspots.
  • Line-by-line profiling with line_profiler to drill into hot paths.
  • Production profiling with py-spy to observe live applications and generate flamegraphs.
  • Use case: profile a long-running script or a web service to reduce latency and memory footprint.

Quick Start

Run a basic profiling session on your Python script by using cProfile to capture CPU time and pstats to view results. For example, run: python -m cProfile -o profile_output.prof app.py python -m pstats profile_output.prof

Frequently Asked Questions about python-performance-optimization

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

FAQPage Schema
How do I identify Python performance bottlenecks in a slow script?

Identify Python performance bottlenecks by profiling CPU, memory, and I/O usage. Use the built-in cProfile tool to capture execution time data and the pstats module to view the results, locating the specific hotspots causing the slowdown.

What is the best way to profile memory usage in Python?

Profile memory usage in Python using the memory_profiler tool. It helps locate memory hotspots by monitoring memory consumption over time, enabling you to reduce the memory footprint of long-running scripts or data processing workloads.

Can I profile a live Python web service in production without stopping it?

Profile a live Python web service in production using py-spy. It observes live applications without requiring code changes or restarts, and generates flamegraphs to visualize CPU usage and identify runtime bottlenecks.

How do I drill down into specific lines of Python code to find CPU hotspots?

Drill down into specific lines of Python code using line_profiler. It provides line-by-line profiling to pinpoint exact execution hot paths within a function, helping optimize latency in targeted data processing workloads.

What is the difference between cProfile and line_profiler for Python profiling?

cProfile captures overall CPU time across function calls to give a macro view of execution, while line_profiler provides line-by-line profiling to drill into hot paths. Use cProfile first to locate hotspots, then line_profiler for granular detail.