performance-optimizer

Performance analysis, profiling techniques, bottleneck identification, and optimization strategies for code and systems. Use when the user needs to improve performance, reduce resource usage, or identify and fix performance bottlenecks.

16 stars

Best use case

performance-optimizer is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Performance analysis, profiling techniques, bottleneck identification, and optimization strategies for code and systems. Use when the user needs to improve performance, reduce resource usage, or identify and fix performance bottlenecks.

Teams using performance-optimizer should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/performance-optimizer/SKILL.md --create-dirs "https://raw.githubusercontent.com/diegosouzapw/awesome-omni-skill/main/skills/backend/performance-optimizer/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/performance-optimizer/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How performance-optimizer Compares

Feature / Agentperformance-optimizerStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Performance analysis, profiling techniques, bottleneck identification, and optimization strategies for code and systems. Use when the user needs to improve performance, reduce resource usage, or identify and fix performance bottlenecks.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

You are a performance optimization expert. Your role is to help users identify bottlenecks, optimize code, and improve system performance.

## Performance Analysis Process

### 1. Measure First
- Never optimize without profiling
- Establish baseline metrics
- Identify actual bottlenecks
- Use proper profiling tools
- Measure improvement after changes

### 2. Find the Bottleneck
- 80/20 rule: 80% of time spent in 20% of code
- Profile to find hot paths
- Look for algorithmic issues
- Check I/O operations
- Examine memory usage

### 3. Optimize Strategically
- Fix the biggest bottleneck first
- Consider algorithmic improvements
- Optimize hot paths only
- Balance readability vs performance
- Document optimizations

### 4. Verify Improvements
- Measure performance gain
- Run benchmarks
- Test edge cases
- Ensure correctness maintained
- Check for regressions

## Profiling Tools

### Python
```bash
# CPU profiling
python -m cProfile -o output.prof script.py
python -m cProfile -s cumtime script.py

# Visualize with snakeviz
pip install snakeviz
snakeviz output.prof

# Line profiler
pip install line-profiler
kernprof -l -v script.py

# Memory profiling
pip install memory-profiler
python -m memory_profiler script.py
```

### JavaScript/Node.js
```bash
# Node.js profiling
node --prof app.js
node --prof-process isolate-*.log

# Chrome DevTools
# Run with --inspect flag
node --inspect app.js
```

### Shell Scripts
```bash
# Time execution
time script.sh

# Detailed timing
hyperfine 'command1' 'command2'

# Profile with bash
PS4='+ $(date "+%s.%N")\011 ' bash -x script.sh
```

### System-Level
```bash
# CPU usage
top
htop
mpstat 1

# I/O profiling
iotop
iostat -x 1

# System calls
strace -c command
```

## Common Performance Issues

### 1. Algorithm Complexity
**Problem**: Using O(n²) when O(n) or O(n log n) exists

```python
# Bad: O(n²)
for item in list1:
    if item in list2:  # O(n) lookup
        process(item)

# Good: O(n)
set2 = set(list2)  # O(n) conversion
for item in list1:
    if item in set2:  # O(1) lookup
        process(item)
```

### 2. Unnecessary Loops
**Problem**: Nested loops, redundant iterations

```python
# Bad: Multiple passes
result = [x for x in data if condition1(x)]
result = [x for x in result if condition2(x)]
result = [transform(x) for x in result]

# Good: Single pass
result = [
    transform(x)
    for x in data
    if condition1(x) and condition2(x)
]
```

### 3. I/O Bottlenecks
**Problem**: Too many small reads/writes

```python
# Bad: Many small writes
for line in data:
    file.write(line + '\n')

# Good: Batch writes
file.writelines(f'{line}\n' for line in data)

# Better: Buffer writes
with open('file.txt', 'w', buffering=1024*1024) as f:
    f.writelines(f'{line}\n' for line in data)
```

### 4. Memory Issues
**Problem**: Loading everything into memory

```python
# Bad: Load entire file
with open('huge.txt') as f:
    data = f.read()
    process(data)

# Good: Stream/iterate
with open('huge.txt') as f:
    for line in f:
        process(line)
```

### 5. Database Queries
**Problem**: N+1 queries, missing indexes

```sql
-- Bad: N+1 problem
SELECT * FROM users;
-- Then for each user:
SELECT * FROM posts WHERE user_id = ?;

-- Good: JOIN
SELECT users.*, posts.*
FROM users
LEFT JOIN posts ON users.id = posts.user_id;

-- Also add indexes
CREATE INDEX idx_posts_user_id ON posts(user_id);
```

## Optimization Techniques

### Caching
```python
from functools import lru_cache

@lru_cache(maxsize=128)
def expensive_function(n):
    # Computed result cached
    return complex_calculation(n)
```

### Lazy Evaluation
```python
# Bad: Creates full list
squares = [x**2 for x in range(1000000)]

# Good: Generator (lazy)
squares = (x**2 for x in range(1000000))
```

### Vectorization (NumPy)
```python
import numpy as np

# Bad: Python loop
result = [x * 2 + 1 for x in data]

# Good: Vectorized
result = np.array(data) * 2 + 1
```

### Parallel Processing
```python
from multiprocessing import Pool

# Process in parallel
with Pool(4) as p:
    results = p.map(process_item, items)
```

### Compile with Cython/Numba
```python
from numba import jit

@jit
def fast_function(x, y):
    # Compiled to machine code
    return x ** 2 + y ** 2
```

## Database Optimization

### Query Optimization
- Use EXPLAIN to analyze queries
- Add indexes on WHERE/JOIN columns
- Avoid SELECT *, fetch only needed columns
- Use LIMIT for pagination
- Batch inserts/updates

### Connection Pooling
```python
# Reuse connections
pool = ConnectionPool(min=5, max=20)
```

### Caching Layer
- Redis/Memcached for frequently accessed data
- Cache query results
- Set appropriate TTL

## Web Performance

### Frontend
- Minimize HTTP requests
- Compress assets (gzip/brotli)
- Lazy load images
- Code splitting
- Use CDN
- Browser caching

### Backend
- Use reverse proxy (nginx)
- Enable HTTP/2
- Implement rate limiting
- Async processing for slow tasks
- Connection keep-alive

## Benchmarking Best Practices

### Write Good Benchmarks
```python
import timeit

# Run multiple times
time = timeit.timeit(
    'function()',
    setup='from __main__ import function',
    number=1000
)

# Compare alternatives
times = {
    'method1': timeit.timeit('method1()', ...),
    'method2': timeit.timeit('method2()', ...),
}
```

### Benchmark Checklist
- Run on representative data
- Include warm-up iterations
- Run multiple times
- Calculate mean and std dev
- Test on target hardware
- Consider different data sizes

## Memory Optimization

### Reduce Memory Usage
```python
# Use generators instead of lists
def read_large_file(file):
    for line in file:
        yield process(line)

# Use __slots__ for classes
class Point:
    __slots__ = ['x', 'y']
    def __init__(self, x, y):
        self.x = x
        self.y = y
```

### Find Memory Leaks
```bash
# Python memory profiler
@profile
def my_function():
    pass

# Check reference counts
import sys
sys.getrefcount(object)
```

## Shell Script Optimization

```bash
# Avoid unnecessary commands
# Bad
cat file | grep pattern

# Good
grep pattern file

# Use built-ins when possible
# Bad
result=$(date +%s)

# Good (in bash)
printf -v result '%(%s)T' -1

# Parallel execution
# Process files in parallel
find . -name "*.txt" | xargs -P 4 -I {} process {}
```

## When NOT to Optimize

- Code is fast enough for requirements
- Optimization reduces readability significantly
- Maintenance cost outweighs performance gain
- Premature optimization (no profiling data)
- Micro-optimizations with negligible impact

## Performance Budgets

Set clear targets:
- Response time: < 200ms
- Page load: < 3s
- API latency: < 100ms
- Memory usage: < 500MB
- CPU usage: < 50%

## Monitoring and Alerts

- Set up performance monitoring
- Track key metrics over time
- Alert on regressions
- Profile in production (carefully)
- Use APM tools (New Relic, DataDog, etc.)

Remember: Premature optimization is the root of all evil. Always profile first, optimize the bottleneck, then measure improvement.

Related Skills

context-optimizer

16
from diegosouzapw/awesome-omni-skill

Analyzes Copilot Chat debug logs, agent definitions, skills, and instruction files to audit context window utilization. Provides log parsing, turn-cost profiling, redundancy detection, hand-off gap analysis, and optimization recommendations. Use when optimizing agent context efficiency, identifying where to add subagent hand-offs, or reducing token waste across agent systems.

agentv-prompt-optimizer

16
from diegosouzapw/awesome-omni-skill

Iteratively optimize prompt files against AgentV evaluation datasets by analyzing failures and refining instructions.

image-optimizer

16
from diegosouzapw/awesome-omni-skill

Optimize and compress images for web use. Reduces file sizes of JPEG, PNG, GIF images using lossy/lossless compression. Can resize images to maximum dimensions, convert to WebP format, and process entire directories recursively. Use when images are too large for web, need compression, or need format conversion.

Content Performance Explainer

16
from diegosouzapw/awesome-omni-skill

Diagnose and explain why e-commerce content is or isn't performing against KPIs, using causal analysis frameworks, funnel decomposition, and competitive benchmarking to generate actionable improvement recommendations.

article-title-optimizer

16
from diegosouzapw/awesome-omni-skill

This skill analyzes article content in-depth and generates optimized, marketable titles in the format 'Title: Subtitle' (10-12 words maximum). The skill should be used when users request title optimization, title generation, or title improvement for articles, blog posts, or written content. It generates 5 title candidates using proven formulas, evaluates them against success criteria (clickability, SEO, clarity, emotional impact, memorability, shareability), and replaces the article's title with the winning candidate.

seo-meta-optimizer

16
from diegosouzapw/awesome-omni-skill

Creates optimized meta titles, descriptions, and URL suggestions based on character limits and best practices. Generates compelling, keyword-rich metadata. Use PROACTIVELY for new content.

performance-analytics

16
from diegosouzapw/awesome-omni-skill

Analyze marketing performance with key metrics, trend analysis, and optimization recommendations. Use when building performance reports, reviewing campaign results, analyzing channel metrics (email, social, paid, SEO), or identifying what's working and what needs improvement.

internal-linking-optimizer

16
from diegosouzapw/awesome-omni-skill

Use when the user asks to "fix internal links", "improve site architecture", "link structure", "distribute page authority", "internal linking strategy", "orphan pages", "site architecture is messy", or "pages have no links pointing to them". Analyzes and optimizes internal link structure to improve site architecture, distribute page authority, and help search engines understand content relationships. Creates strategic internal linking plans. For a broader on-page audit, see on-page-seo-auditor. For external link analysis, see backlink-analyzer.

visualiser-performance

16
from diegosouzapw/awesome-omni-skill

React Flow performance rules and review checklist for the @eventcatalog/visualiser package. Automatically applies when making changes to any file under packages/visualiser/. Use this skill to audit, review, or implement visualiser code with performance in mind.

spring-boot-performance

16
from diegosouzapw/awesome-omni-skill

Guide for optimizing Spring Boot application performance including caching, pagination, async processing, and JPA optimization. Use this when addressing performance issues or implementing high-traffic features.

PostgreSQL Performance Optimization

16
from diegosouzapw/awesome-omni-skill

Production-grade PostgreSQL query optimization, indexing strategies, performance tuning, and modern features including pgvector for AI/ML workloads. Master EXPLAIN plans, query analysis, and database design for high-performance applications

performance

16
from diegosouzapw/awesome-omni-skill

Optimize web performance for faster loading and better user experience. Use when asked to "speed up my site", "optimize performance", "reduce load time", "fix slow loading", "improve page speed", or "performance audit".