optimizing-python-performance

optimizing-python-performance is a skill for Claude Code, Codex from CHENyiru3/AI-Skills-Collections. It costs 60 tokens per session (859 once invoked), scanned A, original, MIT.

A measurement-led guide for making Python code run faster and use less memory. It covers CPU and memory profiling, benchmarks, and checks that help prevent slowdowns from returning.

In plain words
What is it for?
Use it to investigate slow Python functions, find possible memory leaks, measure changes, and choose practical optimizations such as better data structures or generators.
Why use it?
It replaces guesses about slow code with measurements that show where time or memory is being used. It also helps compare changes and catch performance regressions.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it to investigate slow Python functions, find possible memory leaks, measure changes, and choose practical optimizations such as better data structures or generators.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/chenyiru3/ai-skills-collections/performance
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add CHENyiru3/AI-Skills-Collections --skill performance
Clone the repo
git clone --depth 1 https://github.com/CHENyiru3/AI-Skills-Collections

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for optimizing-python-performance

README.md
[![agentmods](https://agentmods.dev/badge/skills/chenyiru3/ai-skills-collections/performance/github.svg)](https://agentmods.dev/skills/chenyiru3/ai-skills-collections/performance)
Your own site
<a href="https://agentmods.dev/skills/chenyiru3/ai-skills-collections/performance"><img src="https://agentmods.dev/badge/skills/chenyiru3/ai-skills-collections/performance/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for optimizing-python-performance

Your own site · 80×15
<a href="https://agentmods.dev/skills/chenyiru3/ai-skills-collections/performance"><img src="https://agentmods.dev/badge/skills/chenyiru3/ai-skills-collections/performance.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 60 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 859 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00060 $0.00859
Opus 5.5 $0.00024 $0.00344
Sonnet 5.5 $0.00012 $0.00172
Haiku 4.5 $0.00006 $0.00086

Measured 6d ago against content hash e4d766018e91, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

optimizing-python-performance scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 6d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills-market/programming/python/performance/SKILL.md · 128 lines

How it starts

The opening of the file, as written. The whole thing — 128 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Python Performance Optimization

Profiling Quick Start

# PyInstrument (statistical, readable output)
python -m pyinstrument script.py

# cProfile (detailed, built-in)
python -m cProfile -s cumulative script.py

# Memory profiling
pip install memray
memray run script.py
memray flamegraph memray-*.bin

PyInstrument Usage

from pyinstrument import Profiler

profiler = Profiler()
profiler.start()
result = my_function()
profiler.stop()
print(profiler.output_text(unicode=True, color=True))

Memory Analysis

import tracemalloc

tracemalloc.start()
# ... code ...
snapshot = tracemalloc.take_snapshot()
for stat in snapshot.statistics('lineno')[:10]:
    print(stat)

Benchmarking (pytest-benchmark)

def test_encode_benchmark(benchmark):
    result = benchmark(encode, 37.7749, -122.4194)
    assert len(result) == 12
pytest tests/ --benchmark-only
pytest tests/ --benchmark-compare

Common Optimizations

# Use set for membership (O(1) vs O(n))
valid = set(items)
if item in valid: ...

# Use deque for queue operations
from collections import deque
queue = deque()
queue.popleft()  # O(1) vs list.pop(0) O(n)

# Use generators for large data
def process(items):
    for item in items:
        yield transform(item)

# Cache expensive computations
from functools import lru_cache

@lru_cache(maxsize=1000)
def expensive(x):
    return compute(x)

# String building
result = "".join(str(x) for x in items)  # Not += in loop

Algorithm Complexity

Operation list set dict
Lookup O(n) O(1) O(1)
Insert O(1) O(1) O(1)
Delete O(n) O(1) O(1)

For detailed strategies, see:

Optimization Checklist

Before Optimizing:
- [ ] Confirm there's a real problem
- [ ] Profile to find actual bottleneck
- [ ] Establish baseline measurements

Process:
- [ ] Algorithm improvements first
- [ ] Then data structures
- [ ] Then implementation details
- [ ] Measure after each change

After:
- [ ] Add benchmarks to prevent regression
- [ ] Verify correctness unchanged
- [ ] Document why optimization needed

Read the full file on GitHub · 128 lines

Files

What ships with it

2 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 6d ago First seen · 128 lines · 60 tokens per session scan A e4d766018e91

Subscribe to this mod's changes

optimizing-python-performance is a skill published in the GitHub repository CHENyiru3/AI-Skills-Collections (1 stars, last pushed 7d ago), licensed MIT. It adds 60 tokens to every session and 859 once invoked, about $0.0002 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-10-02.

Related

Other skills, from other repositories

python-code-quality

Code quality checks, linting, formatting, and type checking commands for the Agent Framework Python codebase. Use this when running checks, fixing lint errors, or troubleshooting CI failures.

microsoft/agent-framework · 40 tokens

plugin-architecture-patterns

Design, implement, or diagnose Xberg plugin traits, typed registries, priority collisions, lifecycle, native extractors, and Alef-generated Python plugin bridges. Load for plugin-system work, not ordinary extractor parsing.

xberg-io/xberg · 49 tokens

test-corpus

The testdocuments submodule is a bucket-fetched fixture corpus that is not committed. This skill covers readtestfixture, missing fixtures, valid A/B controls, and submodule push order. Load before running Rust tests on a fresh clone, setting up an A/B control, adding a fixture-backed test, or diagnosing…

xberg-io/xberg · 72 tokens

idapython

IDA Pro Python scripting for reverse engineering. Use when writing IDAPython scripts, analyzing binaries, working with IDA's API for disassembly, decompilation (Hex-Rays), type systems, cross-references, functions, segments, or any IDA database manipulation. Covers ida modules (50+), idautils iterators, and common…

mrexodia/ida-pro-mcp · 77 tokens

stack-trace-python-probe

Internal helper for meta-stack-trace-investigator. Use when a Python traceback needs Python-specific root-cause checks, pytest reproducer guidance, and defensive patch targets.

opensquilla/opensquilla · 40 tokens

prismer-python-debugpy

Debug Python: pdb REPL + debugpy remote (DAP).

Prismer-AI/PrismerCloud · 19 tokens