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
- Distinctive: line 16
Profile before optimizing: - Use profiling tools to identify real bottlenecks.
≈ “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.
Files
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
| Tool | Use When | What It Shows |
| cProfile | Find slow functions | Function call times |
| line_profiler | Bottleneck in specific function | Time per line |
| memory_profiler | Memory issues suspected | Memory per line |
| py-spy | Production profiling | Sampling profiler |
| timeit | Micro-benchmarks | Execution 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.pySee 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:
passSee 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 + 1See 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 / nSee 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
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- jscott3201/yet-more-skills★ 4same name
- rafaelh/skills★ 2same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository38 other files it gives its agents.
- Data Engineering Cloud InfrastructureSkill
- data-eng-data-qualitySkill
- data-eng-streaming-patternsSkill
- data-eng-testing-patternsSkill
- data-eng-warehouse-patternsSkill
- DevOps CI/CD PatternsSkill
- devops-docker-patternsSkill
- devops-monitoring-observabilitySkill
- devops-terraform-patternsSkill
- git-advanced-operationsSkill
- git-workflow-patternsSkill
- modern-python-patternsSkill
- python-api-developmentSkill
- python-async-patternsSkill
- python-data-pipelinesSkill
- python-data-wranglingSkill
- python-devops-automationSkill
- python-error-handlingSkill
- python-package-developmentSkill
- python-testingSkill
- customizing-vectors-rSkill
- designing-oop-rSkill
- developing-packages-rSkill
- metaprogramming-rlangSkill
- optimizing-rSkill
- writing-tidyverse-rSkill
- sql-advanced-featuresSkill
- sql-analytics-patternsSkill
- sql-data-modelingSkill
- SQL Integration PatternsSkill
- sql-query-fundamentalsSkill
- sql-query-optimizationSkill
- sql-transformationsSkill
- API DesignSkill
- webdev-html-css-patternsSkill
- webdev-javascript-fundamentalsSkill
- webdev-react-patternsSkill
- webdev-typescript-patternsSkill
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
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.

