agentleFS
justanestajustanesta/claude-code-resources/skills/python/python-performance/SKILL.md

python-performance

Skill2 starsChanged 10 months agoMITView on GitHub

Python performance profiling and optimization. Use this skill when code is slow, comparing implementations, or need to improve performance. Covers profiling tools (cProfile, line_profiler, memory_profiler), optimization strategies, numba, and when to use C extensions.

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Profile before optimizing: - Use profiling tools to identify real bottlenecks.

    line 16

≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Python Performance

Performance profiling, benchmarking, and optimization for Python.

Core Principle

Profile before optimizing - Use profiling tools to identify real bottlenecks. Premature optimization wastes time.

Profiling Tools Decision Matrix

ToolUse WhenWhat It Shows
cProfileFind slow functionsFunction call times
line_profilerBottleneck in specific functionTime per line
memory_profilerMemory issues suspectedMemory per line
py-spyProduction profilingSampling profiler
timeitMicro-benchmarksExecution time only

Basic Profiling

cProfile - Function-level

import cProfile
import pstats

profiler = cProfile.Profile()
profiler.enable()

result = expensive_function()

profiler.disable()
stats = pstats.Stats(profiler)
stats.sort_stats('cumulative')
stats.print_stats(20)

line_profiler - Line-level

@profile
def slow_function():
    results = []
    for i in range(10000):
        results.append(i ** 2)
    return results

# Run: kernprof -l -v script.py

See profiling-workflow.md for:

  • Complete profiling workflow
  • Interpreting profiler output

Optimization Strategies

Algorithm Optimization (Biggest Impact)

# BAD - O(n²)
def find_duplicates_slow(items):
    for i, item in enumerate(items):
        for j, other in enumerate(items[i+1:]):
            if item == other:
                return True

# GOOD - O(n)
def find_duplicates_fast(items):
    return len(items) != len(set(items))

Data Structure Choice

# Use set for membership testing
allowed_set = {1, 2, 3, 4, 5}  # O(1) lookup
if x in allowed_set:
    pass

See optimization-strategies.md for:

  • Function call overhead
  • String operations
  • Dictionary optimizations

NumPy for Numerical Computing

import numpy as np

# BAD - Pure Python loop
result = [x**2 + 2*x + 1 for x in data]

# GOOD - NumPy vectorization (10-100x faster)
arr = np.array(data)
result = arr**2 + 2*arr + 1

See numpy-optimization.md for:

  • Broadcasting
  • Avoiding loops with vectorization

Numba for JIT Compilation

from numba import jit

@jit(nopython=True)
def monte_carlo_pi_fast(n):
    inside = 0
    for i in range(n):
        x = np.random.random()
        y = np.random.random()
        if x**2 + y**2 <= 1:
            inside += 1
    return 4 * inside / n

See numba-patterns.md for:

  • Type signatures
  • Parallel execution

Multiprocessing for CPU-Bound Work

from multiprocessing import Pool

def process_parallel(datasets):
    with Pool() as pool:
        return pool.map(cpu_intensive_task, datasets)

See parallel-processing.md for:

  • Process vs thread pools
  • Shared memory

Performance Anti-Patterns

See performance-anti-patterns.md for examples.

source: Python performance docs

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.