python-performance

Profile and optimize Python code performance using cProfile, line_profiler, memory_profiler, and py-spy.

Updated May 20, 2025
One-click install
npx skills add https://github.com/flext-sh/flext --skill python-performance-flext-sh
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-performance
Source: https://github.com/flext-sh/flext/tree/main/.claude/skills/python-performance
Command: npx skills add https://github.com/flext-sh/flext --skill python-performance-flext-sh

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill addresses slow or inefficient Python code by providing tools and techniques for profiling, identifying bottlenecks, and implementing performance optimizations.

Core Features & Use Cases

  • CPU Profiling: Pinpoint functions consuming the most CPU time using cProfile.
  • Line-by-Line Profiling: Analyze performance at the individual line level with line_profiler.
  • Memory Profiling: Detect and reduce memory leaks or high memory usage with memory_profiler.
  • Production Profiling: Monitor live Python applications without code changes using py-spy.
  • Optimization Patterns: Apply best practices like comprehensions, generators, caching, and efficient string concatenation.
  • Use Case: Debugging a data pipeline that is running significantly slower than expected.

Quick Start

Profile the execution of your python script 'my_script.py' to identify performance bottlenecks.

Frequently Asked Questions about python-performance

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

FAQPage Schema
How do I find a performance bottleneck in a slow Python data pipeline?

To find a performance bottleneck in a Python data pipeline, profile the execution using cProfile to pinpoint high CPU functions, or use line_profiler to analyze individual lines and identify hot paths.

How do I profile memory usage in Python to detect leaks?

Profile memory usage in Python by running the memory_profiler tool, which detects and helps reduce memory leaks or high memory consumption in data transformation hot paths.

What's the best way to profile a live Python application without modifying code?

The best way to profile a live Python application without code changes is using py-spy, a production profiling tool that monitors performance and identifies bottlenecks in real-time.

What optimization patterns should I apply to improve Python code performance?

Apply Python optimization patterns like comprehensions, generators, caching, and efficient string concatenation to ensure efficient code execution in performance-critical paths.

Can I use line_profiler to analyze specific functions in my Python script?

Yes, line_profiler analyzes performance at the individual line level within specific functions, allowing you to pinpoint exact statements consuming excessive execution time in your Python script.

When should I use cProfile instead of py-spy for Python profiling?

Use cProfile for standard CPU profiling during development to pinpoint functions consuming CPU time, whereas py-spy is intended for production profiling to monitor live Python applications.