python-performance-optimization

Profile Python services with py-spy and apply GIL-aware optimizations.

1|Updated Jun 20, 2026
One-click install
npx skills add https://github.com/shafibabar/SDLC-Artifact-Factory --skill python-performance-optimization-shafibabar
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: python-performance-optimization
Source: https://github.com/shafibabar/SDLC-Artifact-Factory/tree/main/skills/python-performance-optimization
Command: npx skills add https://github.com/shafibabar/SDLC-Artifact-Factory --skill python-performance-optimization-shafibabar

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires py-spy, scalene, and includes references (resource) components.

What problem does it solve?

This skill addresses performance bottlenecks in Python services by providing a rigorous, measurement-driven methodology to diagnose and resolve CPU-bound and I/O-bound latency issues.

Core Features & Use Cases

  • Profiling Toolkit: Provides standardized workflows for py-spy (live sampling), scalene (line-level CPU/memory), and tracemalloc (allocation tracking).
  • GIL-Bound Diagnosis: Offers a clear decision framework to distinguish between I/O-bound tasks and GIL-bound CPU work, preventing common anti-patterns like misusing asyncio for CPU-heavy operations.
  • Optimization Patterns: Includes proven techniques for reducing object churn, tuning asyncpg connection pools, and implementing efficient concurrency models.

Quick Start

Use the python-performance-optimization skill to profile the current service process and identify the primary hot path using py-spy.

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 service latency to find CPU-bound and I/O-bound bottlenecks?▼

Profile Python service latency using py-spy for live sampling, scalene for line-level CPU and memory analysis, and tracemalloc for allocation tracking to pinpoint bottleneck locations.

What is the best way to optimize asyncio performance for CPU-heavy Python tasks?▼

Optimizing asyncio for CPU-heavy tasks requires GIL-aware architectural adjustments, as asyncio is designed for I/O-bound concurrency and misapplying it to CPU-bound work creates performance anti-patterns.

How do I reduce memory churn and backend latency in Python applications?▼

Reduce memory churn and backend latency by applying diagnostic tools to identify hot paths, then implementing optimization patterns like tuning asyncpg connection pools and reducing object churn.

Does py-spy work with scalene for Python performance benchmarking?▼

Py-spy and scalene work together within a measurement-first profiling toolkit, requiring strict adherence to before-and-after performance benchmarking for all code changes to validate improvements.

When should I not use asyncio for Python performance optimization?▼

Avoid using asyncio for Python performance optimization when diagnosing GIL-bound CPU work, as it is strictly intended for I/O-bound tasks and will not resolve CPU-bound latency issues.