Skip to content
Skills Library
Programming · Analysis

python-performance

/python-performance

Profile first, then remove Python-level overhead through vectorization, better algorithms, or a compiled extension. Use when Python code is too slow and you must decide where and how to optimize.

Repository
AI-SKILLS ↗
Licence
MIT
Last repository change
05.09.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 05.09.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Profile first, then remove Python-level overhead through vectorization, better algorithms, or a compiled extension. Use when Python code is too slow and you must decide where and how to optimize.

Original author description

Profile first, then remove Python-level overhead through vectorization, better algorithms, or a compiled extension. Use when Python code is too slow and you must decide where and how to optimize.

How it works

  1. Method
  2. Boundaries
Original SKILL.md headings · 43 lines, 314 words
SKILL.md preview
---
name: python-performance
description: Profile first, then remove Python-level overhead through vectorization, better algorithms, or a compiled extension. Use when Python code is too slow and you must decide where and how to optimize.
---

# Python performance

Python overhead is per-operation, so wins come from doing fewer Python-level
operations: better algorithms first, then batch work into C-backed calls,
then compile the hot loop.

## Method

1. **Profile before touching code.** `python -m cProfile -s cumtime app.py`
   for call-level, `py-spy top --pid N` for live processes without
   restarting, `line_profiler` for a single hot function. Optimizing an
   unprofiled guess wastes days; the hot spot is rarely where you think.
2. **Fix the algorithm before the language.** An O(n^2) membership scan
   beaten into a set lookup outruns any rewrite. Check data-structure fit:
   list for order, set/dict for membership, deque for both-ends, heapq for
   top-k.
3. **Vectorize numeric loops.** A numpy expression over an array replaces a
   Python loop with one C loop, commonly 10-100x. The trap is accidental
   element-wise Python (calling `float()` per item, object-dtype arrays);
   keep dtypes numeric and operations whole-array.
4. **Cut allocation and attribute churn in hot loops.** Hoist
   `self.method` and global lookups to locals, reuse buffers, prefer
   comprehensions over `append` loops. These 10-30% wins are free but only
   matter inside the measured hot path.
5. **Escalate to compiled code deliberately.** Order of preference: an
   existing C-backed library (numpy, polars, re2), `functools.lru_cache`
   over recomputation, Cython or a small Rust extension (pyo3/maturin) for
   the one hot function. Keep the compiled surface minimal; it is the code
   you can no longer read in a debugger.
6. **Verify with a benchmark, not a feeling.** `timeit` or `pytest-benchmark`
   with realistic data sizes, before and after, committed next to the code
   so regressions are visible.

## Boundaries

- Do not optimize I/O-bound code with these techniques; overlap the waiting
  instead (async, threads, batching requests).
- Free-threaded and JIT builds change constants, not complexity; algorithmic
  wins carry across interpreters, micro-tricks may not.
- Readability is a cost you pay forever; take the 2x that keeps the code
  plain over the 2.3x that obfuscates it.

Versions

RepositoryScoreLicence
This page · Amey-Thakur/AI-SKILLS100MIT
seaworld008/commonly-used-high-value-skills100MIT
athola/claude-night-market100MIT

Database snapshot: 13.11.2026 · package version 929c0cfb642a (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 90python-performance-optimization
    Profile and optimize Python code using cProfile, memory profilers, and performance best practices. Use when debugging slow Python code, optimizing bottlenecks, or improving application performance.
  • 95matlab-performance-optimizer
    Optimize MATLAB code for better performance through vectorization, memory management, and profiling. Use when user requests optimization, mentions slow code, performance issues, speed improvements, or asks to make code faster or more efficient.
  • 100python-performance-optimization
    Profile and optimize Python code using cProfile, memory profilers, and performance best practices. Use when debugging slow Python code, optimizing bottlenecks, or improving application performance.
  • 95python-performance-optimization
    Profile and optimize Python code using cProfile, memory profilers, and performance best practices. Use when debugging slow Python code, optimizing bottlenecks, or improving application performance.
  • 100python-performance-optimization
    Profile and optimize Python code using cProfile, memory profilers, and performance best practices. Use when debugging slow Python code, optimizing bottlenecks, or improving application performance.
  • 100python-performance-optimization
    Profile and optimize Python code using cProfile, memory profilers, and performance best practices. Use when debugging slow Python code, optimizing bottlenecks, or improving application performance.

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.