performance-optimizer

A performance-improvement guide for Python programs and web backends. It requires measuring with profiling or benchmarks before changing code, then measuring again after each fix.

In plain words
What is it for?
Use it to investigate slow requests, high costs, or load failures, identify the main hot path, apply a targeted fix, and verify the result.
Why use it?
It avoids guesswork by focusing work on the measured bottleneck and checking that an optimization actually improves speed without causing regressions.

Skill for Claude CodeCodex

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.

agentmods
npx agentmods add skills/chandrudp29/skillhub/performance-optimizer
Any agent
npx skills add chandrudp29/skillhub --skill performance-optimizer
Clone the repo
git clone --depth 1 https://github.com/chandrudp29/skillhub

Made for: Claude Code, Codex.

Per session 26 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,214 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
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 $0.00026 $0.01214
Opus 5 $0.00013 $0.00607
Sonnet 5 $0.00005 $0.00243
Haiku 4.5 $0.00003 $0.00121

Measured 2d ago against content hash c09d8220f25e, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

performance-optimizer 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 2d 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/performance-optimizer/SKILL.md · 149 lines

How it starts

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

When to Use

Apply when a system is slow, costs too much, or fails under load. Always measure before optimizing — guessing wastes time.

Core Rules

  • Measure first, always. Never optimize without a profiler or benchmark showing the bottleneck
  • Fix the biggest bottleneck first — fixing #2 before #1 gives partial gains at best
  • Define a target before optimizing: "p99 < 200ms" not "faster"
  • After every optimization, re-measure — sometimes fixes have side effects

The Loop

1. Measure    → profiler, APM, benchmark (establish baseline)
2. Identify   → find the hot path (usually 1-3 functions cause 80%+ of time)
3. Hypothesize → why is this slow? (N+1 query, GIL contention, memory copy, etc.)
4. Fix        → smallest change that addresses root cause
5. Verify     → re-run benchmark — is it faster? Regressions elsewhere?
6. Repeat     → next bottleneck

Python Profiling

# cProfile — CPU profiling
import cProfile, pstats, io
pr = cProfile.Profile()
pr.enable()
# ... code to profile ...
pr.disable()
s = io.StringIO()
ps = pstats.Stats(pr, stream=s).sort_stats('cumulative')
ps.print_stats(20)
print(s.getvalue())

# line_profiler — line-by-line (use @profile decorator)
# pip install line_profiler
# kernprof -l -v script.py

# memory_profiler — memory usage line-by-line
# pip install memory_profiler
# @profile decorator, then: python -m memory_profiler script.py

# py-spy — sampling profiler, zero-code-change, attach to running process
# pip install py-spy
# py-spy top --pid 12345
# py-spy record -o profile.svg --pid 12345

Common Python Bottlenecks

# ❌ String concatenation in loop — O(n²) allocations
result = ""
for item in items:
    result += str(item)  # new string object each time

# ✓ join — one allocation
result = "".join(str(item) for item in items)

# ❌ Repeated dict/set lookup in hot loop
for item in items:
    if item in some_list:  # O(n) each time if it's a list
        ...

# ✓ Convert to set once
lookup = set(some_list)  # O(1) lookup
for item in items:
    if item in lookup:
        ...

# ❌ Unnecessary object creation in loop
for i in range(1_000_000):
    temp = MyClass(i)  # constructor overhead × 1M

# ✓ Reuse or use slots
class MyClass:
    __slots__ = ['value']  # ~40% less memory, faster attribute access

# ❌ GIL-bound CPU work in threads
from threading import Thread  # threads share GIL — no real parallelism for CPU

# ✓ Use ProcessPoolExecutor for CPU-bound work
from concurrent.futures import ProcessPoolExecutor
with ProcessPoolExecutor() as pool:
    results = list(pool.map(cpu_intensive_fn, items))

Read the full file on GitHub · 149 lines

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. 2d ago First seen · 149 lines · 26 tokens per session scan A c09d8220f25e

Subscribe to this mod's changes

performance-optimizer is a skill published in the GitHub repository chandrudp29/skillhub (13 stars, last pushed 2mo ago), licensed MIT. It adds 26 tokens to every session and 1,214 once invoked, about $0.0001 per session on Opus 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-08-30.