python-performance-optimization

Profile and optimize Python code with cProfile, memory_profiler, and line_profiler.

Updated Dec 23, 2025
One-click install
npx skills add https://github.com/drgaciw/academic-compliance-hub-glm --skill python-performance-optimization-drgaciw
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-performance-optimization
Source: https://github.com/drgaciw/academic-compliance-hub-glm/tree/main/agents/plugins/python-development/skills/python-performance-optimization
Command: npx skills add https://github.com/drgaciw/academic-compliance-hub-glm --skill python-performance-optimization-drgaciw

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps identify and resolve performance bottlenecks in Python code, leading to faster execution times and reduced resource consumption.

Core Features & Use Cases

  • CPU Profiling: Pinpoint functions consuming the most CPU time using cProfile.
  • Memory Profiling: Detect memory leaks and high memory usage with memory_profiler.
  • Line Profiling: Analyze performance at a granular, line-by-line level with line_profiler.
  • Optimization Strategies: Apply best practices like using list comprehensions, generators, NumPy, and caching.
  • Use Case: A Python script is running too slowly. Use this Skill to profile it, identify the slowest function, and apply optimizations like using NumPy for array operations or lru_cache for repeated calculations.

Quick Start

Use the python-performance-optimization skill to profile the attached python script 'my_slow_script.py' and identify its top 5 performance bottlenecks.

Frequently Asked Questions about python-performance-optimization

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

FAQPage Schema
How do I profile Python code to find performance bottlenecks?

Profile Python code using cProfile to pinpoint functions consuming the most CPU time, then use line_profiler for line-by-line analysis to identify specific performance bottlenecks. This approach isolates slow execution paths for targeted optimization.

What's the best way to reduce high memory usage in a Python application?

Reduce high memory usage by profiling your Python application with memory_profiler to detect memory leaks and identify high consumption areas. Analyzing memory allocation patterns helps resolve resource consumption issues and application latency.

How do I optimize slow Python scripts beyond basic profiling?

Optimize slow Python scripts by applying algorithmic improvements, using list comprehensions, generators, and caching with lru_cache. Leveraging libraries like NumPy for array operations also significantly improves execution times after profiling.

When should I use line_profiler instead of cProfile for Python performance optimization?

Use line_profiler instead of cProfile when you need granular, line-by-line performance analysis within a specific function. cProfile identifies which functions consume the most CPU time, while line_profiler isolates exact statements causing latency.

Does Python performance optimization work with NumPy for array operations?

Python performance optimization works seamlessly with NumPy by leveraging its optimized array operations to replace slow loops. Using NumPy is a recommended strategy to improve execution times for numerical computations identified during profiling.