Get the FREE Ultimate OpenClaw Setup Guide →

python-performance

npx machina-cli add skill athola/claude-night-market/python-performance --openclaw
Files (1)
SKILL.md
3.2 KB

Python Performance Optimization

Profiling and optimization patterns for Python code.

Table of Contents

  1. Quick Start

Quick Start

# Basic timing
import timeit
time = timeit.timeit("sum(range(1000000))", number=100)
print(f"Average: {time/100:.6f}s")

Verification: Run the command with --help flag to verify availability.

When To Use

  • Identifying performance bottlenecks
  • Reducing application latency
  • Optimizing CPU-intensive operations
  • Reducing memory consumption
  • Profiling production applications
  • Improving database query performance

When NOT To Use

  • Async concurrency - use python-async instead
  • CPU/GPU system monitoring - use conservation:cpu-gpu-performance
  • Async concurrency - use python-async instead
  • CPU/GPU system monitoring - use conservation:cpu-gpu-performance

Modules

This skill is organized into focused modules for progressive loading:

profiling-tools

CPU profiling with cProfile, line profiling, memory profiling, and production profiling with py-spy. Essential for identifying where your code spends time and memory.

optimization-patterns

Ten proven optimization patterns including list comprehensions, generators, caching, string concatenation, data structures, NumPy, multiprocessing, and database operations.

memory-management

Memory optimization techniques including leak tracking with tracemalloc and weak references for caches. Depends on profiling-tools.

benchmarking-tools

Benchmarking tools including custom decorators and pytest-benchmark for verifying performance improvements.

best-practices

Best practices, common pitfalls, and exit criteria for performance optimization work. Synthesizes guidance from profiling-tools and optimization-patterns.

Exit Criteria

  • Profiled code to identify bottlenecks
  • Applied appropriate optimization patterns
  • Verified improvements with benchmarks
  • Memory usage acceptable
  • No performance regressions

Troubleshooting

Common Issues

Command not found Ensure all dependencies are installed and in PATH

Permission errors Check file permissions and run with appropriate privileges

Unexpected behavior Enable verbose logging with --verbose flag

Source

git clone https://github.com/athola/claude-night-market/blob/master/plugins/parseltongue/skills/python-performance/SKILL.mdView on GitHub

Overview

Provides profiling and optimization patterns for Python code to cut latency, reduce memory usage, and validate improvements. It covers CPU profiling with cProfile, memory profiling, production profiling, and benchmarking through focused modules and best practices. Note: Do not use for async concurrency or CPU/GPU monitoring; use python-async or conservation:cpu-gpu-performance as applicable.

How This Skill Works

The skill is organized into focused modules: profiling-tools (CPU and memory profiling, production profiling), optimization-patterns (common speedups and efficiency improvements), memory-management (leak tracking with tracemalloc), benchmarking-tools (custom decorators and pytest-benchmark), and best-practices (guidance and exit criteria). Quick-start demonstrations and exit criteria guide evidence of improvements. It emphasizes identifying bottlenecks, applying the right patterns, and verifying gains with benchmarks to avoid regressions.

When to Use It

  • Identifying performance bottlenecks
  • Reducing application latency
  • Optimizing CPU-intensive operations
  • Reducing memory consumption
  • Profiling production applications

Quick Start

  1. Step 1: Run a quick timing test with timeit.timeit("sum(range(1000000))", number=100) and print the average.
  2. Step 2: Profile the code using cProfile or py-spy to locate hotspots and assess memory with tracemalloc.
  3. Step 3: Apply an optimization pattern, then re-run benchmarks to verify performance gains.

Best Practices

  • Profile first with profiling-tools to locate bottlenecks (cProfile, line profiling, memory profiling)
  • Apply optimization-patterns such as list comprehensions, caching, and generators
  • Use memory-management techniques (tracemalloc, weak references) to control leaks
  • Benchmark improvements with benchmarking-tools to verify gains
  • Check for regressions and ensure memory usage stays within acceptable limits

Example Use Cases

  • Profile a hot loop with cProfile to identify the top function consuming time
  • Replace slow string concatenation with join or f-strings and caching results
  • Use generators to process large data streams without loading everything into memory
  • Add memoization to expensive function calls to avoid repeated work
  • Benchmark before/after changes with pytest-benchmark or custom decorators

Frequently Asked Questions

Add this skill to your agents

Related Skills

Sponsor this space

Reach thousands of developers