performance-tuning
Skill0 starsChanged 5 months agoMITView on GitHub
Use when code is slow, a pipeline has a bottleneck, a job is taking too long, memory usage is too high, or you need to benchmark before and after an optimization. Trigger on: "this is slow", "optimize", "profile this", "this job takes too long", "pipeline bottleneck", "memory usage", "benchmark", "it's hanging", "takes forever", "needs to be faster", "latency", "why is this slow". Always measure before optimizing — no guessing.
- Installs packages
8 other projects use a version of this.
Adopted by
Most recently taken up by
- NoobyGains/godmodetheir own version, first seen Nov 1, 2026
- 0King0P/Claude-Skillstheir own version, first seen Oct 13, 2026
- devpilotX/skillstheir own version, first seen Sep 22, 2026
- jdanigo/hydraiatheir own version, first seen Sep 12, 2026
- kiko197/skilltheir own version, first seen Aug 11, 2026
- polardb/polardb-pg-skillstheir own version, first seen May 11, 2026
Used with
Projects with it also use code-review.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
GoogleSkillcode-review
Adversarial systems, concurrency, memory-model, and architecture code review protocol. Use this skill whenever asked to review code, PRs, diffs, or branches in Filament.
Also in 4 projects that use this
Other versions8 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 8
- NoobyGains/godmode★ 118same name
- jdanigo/hydraia★ 8same name
- polardb/polardb-pg-skills★ 2same name
- harrissohail6/claude-code-config★ 1same name
- 0King0P/Claude-Skills★ 0same name
- devpilotX/skills★ 0same name
- kiko197/skill★ 0same name
- poteto0/my-skills★ 0same 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 repository10 other files it gives its agents.
- code-review-sessionSkill
- debug-sessionSkill
- decision-logSkill
- devil-advocateSkill
- judge-panelSkill
- pre-mortemSkill
- refactor-sessionSkill
- security-auditSkill
- spec-driven-devSkill
- tdd-workflowSkill
The file
We split this skill into the rules it gives an agent
9 rules. 0 are common, 9 are distinctive, and 0 are very specific to this project.
0
Common
Most of the 6 edited versions we read keep these.
9
Distinctive
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 19
Verify correctness after every optimization: Run the full test suite and confirm output matches the original within acceptable tolerance.
- Distinctive: line 42
Only proceed when: (1) you have a measured bottleneck and (2) it actually impacts the user.
- Distinctive: line 94
Hot-loop amplification: Look for functions called thousands of times inside a tight loop (per frame, per row, per request, per event).
- Distinctive: line 174
Always record results. No "I think it's faster now."
- Distinctive: line 187
Commit this table alongside the change so the gain is part of the record, not folklore.
- Distinctive: line 207
Use this skill when:
- Distinctive: line 220
NOT for fixing bugs that produce wrong output — run a systematic diagnosis (use debug-session) for correctness issues.
- Distinctive: line 221
NOT for refactoring code structure without a measured bottleneck — use refactor-session for structural improvements.
- Distinctive: line 222
NOT for slowness caused by missing or stale data rather than code — diagnose the data path first (use debug-session) if the problem isn't …
“Common” is measured: kept by at least 6 in 10 of the 6 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Hard Rules
- Never optimize code you haven't profiled. Intuition about what's slow is wrong more often than it's right. Measure first, every time.
- Verify correctness after every optimization. Run the full test suite and confirm output matches the original within acceptable tolerance. A faster wrong answer is still wrong.
- Record before/after numbers. No "I think it's faster now." If you can't show a measured delta, the optimization isn't done.
Performance Tuning
Measure first. Optimize second. Verify improvement with data.
The diagnostic workflow is: measure → identify the bottleneck → optimize → benchmark. If your host also exposes a profiling-tool skill (cProfile flags, memory profiler setup), use it alongside this workflow — this skill owns the method, that owns the tool syntax.
Before Optimizing: Check if You Should
Premature optimization checklist — if ANY of these are true, stop and reconsider:
- The code runs fast enough for current usage (users aren't waiting)
- This code runs rarely (not in a hot path)
- You haven't profiled to confirm this is the bottleneck
- There's a simpler architectural fix (e.g., cache the result, reduce API calls)
- The code is hard to understand and optimizing will make it worse
Only proceed when: (1) you have a measured bottleneck and (2) it actually impacts the user.
Step 1: Measure (Profile First)
Python — cProfile
# Profile a script
python -m cProfile -s cumtime your_script.py
# Profile with output to file (for large reports)
python -m cProfile -o profile.out your_script.py
python -c "import pstats; p = pstats.Stats('profile.out'); p.sort_stats('cumulative'); p.print_stats(20)"Python — memory_profiler
pip install memory_profiler
# Add @profile decorator to the function
# Then run:
python -m memory_profiler your_script.pyPython — line_profiler (line-by-line)
pip install line_profiler
# Add @profile decorator to the function
# Then run:
kernprof -l -v your_script.pyNode.js
# Built-in profiler
node --prof your_script.js
# Analyze output
node --prof-process isolate-*.log > profile.txtStep 2: Read the Profile Output
What to look for:
cumtime(Python) — total time spent in function including callees → find the top offenderstottime(Python) — time in function excluding callees → find the actual slow code- High call counts on unexpected functions → loop-in-loop or unnecessary repeated work
Hot-loop amplification: Look for functions called thousands of times inside a tight loop (per frame, per row, per request, per event). One slow function called 10,000 times = 10,000x the pain. Pull invariant work out of the loop.
Step 3: Optimize the Bottleneck
Python — Common Patterns
Vectorize with pandas/numpy instead of loops:
# SLOW: Python loop over DataFrame
for i, row in df.iterrows():
result.append(row['price'] * row['qty'])
# FAST: Vectorized operation
result = df['price'] * df['qty']Chunk large DataFrames:
# Process in chunks instead of loading all data at once
for chunk in pd.read_csv('large_file.csv', chunksize=10000):
process(chunk)Use sets for membership testing:
# SLOW: O(n) list lookup
if item in my_list: # searches entire list
# FAST: O(1) set lookup
if item in my_set:Cache expensive computations:
from functools import lru_cache
@lru_cache(maxsize=128)
def expensive_calc(n: int) -> float:
... # computed once, cached afterHoist invariant work out of hot loops
A common bottleneck in any tick-by-tick or row-by-row pipeline: recomputing a derived series on every iteration when it could be computed once before the loop.
# SLOW: recompute the same indicator on every iteration
for i, row in df.iterrows():
signal = compute_metric_for_one_row(row)
# FAST: pre-compute the entire series once, vectorized
df['metric'] = compute_metric_series(df['value']) # once, vectorizedDatabase / SQL query optimization
# Add an index on frequently filtered columns
conn.execute("CREATE INDEX IF NOT EXISTS idx_entity_date ON records (entity_id, record_date)")
# Inspect the query plan to see what the engine is doing
conn.execute("EXPLAIN QUERY PLAN SELECT ...") # SQLite; use EXPLAIN ANALYZE on PostgresAvoid per-row Python callbacks
# SLOW: apply() calls a Python function per row
df['result'] = df.apply(lambda row: complex_calc(row), axis=1)
# FAST: vectorized numpy operation
df['result'] = np.where(df['value'] > threshold, df['a'], df['b'])Step 4: Benchmark Before and After
Always record results. No "I think it's faster now."
## Performance Benchmark — [Feature/Script Name]
Date: YYYY-MM-DD
| Metric | Before | After | Improvement |
|--------|--------|-------|-------------|
| Job runtime (full dataset) | 45s | 8s | 82% faster |
| Memory peak | 2.1 GB | 340 MB | 84% less |
| Rows processed/sec | 1,200 | 8,400 | 7x faster |Commit this table alongside the change so the gain is part of the record, not folklore.
Quick Reference
| Situation | Tool |
| "What's slow?" | Python: cProfile -s cumtime |
| "Why is memory high?" | Python: memory_profiler |
| "Which line?" | Python: line_profiler |
| "Node.js bottleneck" | node --prof |
| "pandas loop slow" | Vectorize: replace df.apply(...) / iterrows() with column ops |
| "SQL query slow" | EXPLAIN QUERY PLAN (or EXPLAIN ANALYZE) + add an index |
| "Tick/row loop too slow" | Pre-calculate invariant series before the loop |
Trigger Conditions
Use this skill when:
- Code works correctly but runs too slowly, hangs, or "takes forever"
- A pipeline, batch job, or simulation has a bottleneck
- Memory usage is too high or grows over a long-running process
- Latency on a hot path needs to come down
- You need a before/after benchmark to justify an optimization
Phrases that trigger: "this is slow", "optimize", "profile this", "pipeline bottleneck", "memory usage", "benchmark", "it's hanging", "needs to be faster", "latency", "why is this slow".
Out of Scope
- NOT for fixing bugs that produce wrong output — run a systematic diagnosis (use debug-session) for correctness issues; this skill is for code that works correctly but runs too slowly.
- NOT for refactoring code structure without a measured bottleneck — use refactor-session for structural improvements; this skill requires a profiled performance problem.
- NOT for slowness caused by missing or stale data rather than code — diagnose the data path first (use debug-session) if the problem isn't the code itself.
Common Traps
- Optimizing without profiling first: Intuition about what's slow is wrong more often than right. Spending hours optimizing a function that accounts for 2% of runtime while the real bottleneck (database query, network call, serialization) goes untouched. Always profile before touching code.
- Micro-benchmarks that don't reflect real workloads: A function benchmarked in isolation with 100 items may behave completely differently with 1M items (cache misses, memory pressure, GC pauses). Benchmark with production-representative data sizes and shapes.
- Optimization that breaks correctness: Replacing a stable sort with an unstable one, caching a result that should be recomputed, or removing a "redundant" check that handled an edge case. Always run the full test suite after any optimization and verify output matches exactly.
- Caching without an invalidation strategy: Adding
@lru_cacheor a manual cache speeds things up until stale data causes wrong results. Every cache needs a clear invalidation policy — time-based, event-based, or size-based. Unbounded caches also leak memory over long-running processes. - Vectorization that changes floating-point results: NumPy/pandas vectorized operations may use a different floating-point evaluation order than Python loops, producing slightly different results. For financial calculations or ML model reproducibility, verify that optimized output matches the original within acceptable tolerance.
Skill Chain
| Stage | Skill |
| Before optimizing | Confirm there's a real bottleneck — profile first (this skill) |
| This skill | performance-tuning — measure → optimize → benchmark |
| After optimizing | tdd-workflow — verify behavior unchanged with tests |
| If introduced a regression | debug-session — diagnose what broke |
| Reviewing the optimized change | code-review-session — catch subtle correctness issues |
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.

