python-performance-optimization

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

Updated Sep 24, 2021
One-click install
npx skills add https://github.com/coolguy1771/dotfiles --skill python-performance-optimization-coolguy1771
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-performance-optimization
Source: https://github.com/coolguy1771/dotfiles/tree/main/chezmoi/private_dot_cursor/skills/python-performance-optimization
Command: npx skills add https://github.com/coolguy1771/dotfiles --skill python-performance-optimization-coolguy1771

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you identify and fix performance bottlenecks in your Python code, making your applications faster and more resource-efficient.

Core Features & Use Cases

  • Profiling: Analyze CPU usage, memory consumption, and line-by-line execution.
  • Optimization Strategies: Learn techniques like algorithmic improvements, caching, parallelization, and using optimized libraries.
  • Use Case: If your Python script is taking too long to run or consuming excessive memory, this Skill provides the tools and knowledge to diagnose the issue and implement effective solutions.

Quick Start

Use the python-performance-optimization skill to profile the execution time of the provided slow_function in the main function.

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 execution bottlenecks?

Profile Python code using cProfile for CPU usage, memory_profiler for memory consumption, and line_profiler for line-by-line analysis to pinpoint exact bottlenecks.

What's the best way to optimize slow Python scripts?

Optimize slow Python scripts by applying algorithmic improvements, implementing caching, leveraging parallelization, and using optimized libraries like NumPy to boost code speed.

Can I profile Python performance in a production environment?

Profile Python performance in production using py-spy to sample running applications without restarting or modifying the production code.

Why is my Python code consuming excessive memory and how do I fix it?

Excessive memory consumption is diagnosed using memory_profiler to track memory usage line-by-line, allowing you to fix it by optimizing data structures and leveraging efficient libraries.

What are common pitfalls when trying to improve Python code speed?

Common pitfalls when improving Python code speed include ignoring algorithmic complexity, prematurely optimizing without profiling, and overlooking optimized libraries like NumPy for heavy computations.