Skip to main content
skill CX Codex

performance-expert — Claude Code skill: what it does, how to install

performance-expert guides code profiling, database query tuning, and caching strategies to resolve latency and throughput issues.

Apache-2.0 198 installs ★ 45 updated 2026-10-12

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add personamanagmentlayer/pcl --skill performance-expert -a claude-code
Open on GitHub

What performance-expert does

This skill delivers patterns for optimizing backend execution and data access. It covers CPU and memory profiling using cProfile and memory_profiler, function benchmarking via timeit, NumPy vectorization, and generator-based memory savings.

For database workloads, it details resolving SQLAlchemy N+1 query patterns using eager loading, tuning connection pool recycling, setting up composite indexes, and batch inserts. It also provides Redis cache-aside implementations and frontend debouncing examples.

Execution access is scoped in the manifest. The agent is restricted to python, python3, pip, and pytest in Bash, meaning raw OS tools like htop or kernel profilers cannot be run directly.

What it helps with

  • Profile CPU bottlenecks and memory consumption with cProfile
  • Fix N+1 query overhead in SQLAlchemy models
  • Implement cache-aside query storage with Redis
  • Replace slow Python iteration with vectorized NumPy routines

Example prompts for the agent

  • Profile this Python module and show the cumulative time breakdown
  • Rewrite these SQLAlchemy relationships to eliminate N+1 queries
  • Benchmark this function with timeit across 1000 iterations

How to install performance-expert

1Skills CLI (Vercel)

npx skills add personamanagmentlayer/pcl --skill performance-expert -a claude-code

2Manually: put the files in place

~/.claude/skills/performance-expert/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/performance-expert/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about performance-expert

How to install performance-expert in Claude Code?

Run npx skills add personamanagmentlayer/pcl --skill performance-expert -a claude-code in your terminal.

What does performance-expert do?

It equips the agent with specific patterns for latency tuning, database batching, memory profiling, and Redis caching.

Which terminal commands are allowed by this skill?

The skill restricts shell execution strictly to python, python3, pip, and pytest.

Source text

SKILL.md · Apache-2.0
---
name: performance-expert
version: 2.0.0
description: >-
  Expert-level performance optimization, profiling, benchmarking, and tuning. Use when the
  user mentions optimization, profiling, benchmarking, or scalability, or when the task
  involves Performance Fundamentals, Optimization Areas, Profiling Tools, or General.
category: devops
tags: [performance, optimization, profiling, benchmarking, scalability]
allowed-tools:
  - Read
  - Write
  - Edit
  - Bash(python:*, python3:*, pip:*, pytest:*)
---

# Performance Expert

Expert guidance for performance optimization, profiling, benchmarking, and system tuning.

## Core Concepts

### Performance Fundamentals

- Response time vs throughput
- Latency vs bandwidth
- CPU, memory, I/O bottlenecks
- Concurrency vs parallelism
- Caching strategies
- Load balancing

### Optimization Areas

- Algorithm optimization
- Database optimization
- Network optimization
- Frontend performance
- Backend performance
- Infrastructure tuning

### Profiling Tools

- CPU profilers
- Memory profilers
- Network profilers
- Application Performance Monitoring (APM)
- Load testing tools

## Python Performance

```python
import cProfile
import pstats
import timeit
import memory_profiler
from functools import lru_cache
from typing import List
import numpy as np

# Performance Profiling
def profile_function(func):
    """Decorator for profiling function execution"""
    def wrapper(*args, **kwargs):
        profiler = cProfile.Profile()
        profiler.enable()

        result = func(*args, **kwargs)

        profiler.disable()
        stats = pstats.Stats(profiler)
        stats.sort_stats('cumulative')
        stats.print_stats(10)  # Top 10 functions

        return result
    return wrapper

@profile_function
def slow_function():
    total = 0
    for i in range(1000000):
        total += i
    return total

# Memoization for expensive computations
@lru_cache(maxsize=128)
def fibonacci(n: int) -> int:
    """Cached Fibonacci calculation"""
    if n < 2:
        return n
    return fibonacci(n-1) + fibonacci(n-2)

# Vectorization with NumPy
def slow_loop(data: List[float]) -> List[float]:
    """Slow: Using Python loops"""
    return [x ** 2 + 2 * x + 1 for x in data]

def fast_vectorized(data: np.ndarray) -> np.ndarray:
    """Fast: Using NumPy vectorization"""
    return data ** 2 + 2 * data + 1

# Benchmarking
def benchmark_function(func, *args, iterations=1000):
    """Benchmark function execution time"""
    total_time = timeit.timeit(
        lambda: func(*args),
        number=iterations
    )
    avg_time = total_time / iterations

    return {
        'total_time': total_time,
        'avg_time': avg_time,
        'iterations': iterations
    }

# Memory profiling
@memory_profiler.profile
def memory_intensive_function():
    """Function that uses significant memory"""
    data = [i for i in range(1000000)]
    return sum(data)

# Efficient string concatenation
def slow_string_concat(items: List[str]) -> str:
    """Slow: String concatenation in loop"""
    result = ""
    for item in items:
        result += item  # Creates new string each time
    return result

def fast_string_concat(items: List[str]) -> str:
    """Fast: Using join"""
    return "".join(items)

# Generator for memory efficiency
def slow_list_comprehension(n: int) -> List[int]:
    """Returns all squares at once"""
    return [i ** 2 for i in range(n)]

def fast_generator(n: int):
    """Yields squares one at a time"""
    for i in range(n):
        yield i ** 2
```

## Database Optimization

```python
from sqlalchemy import create_engine, Index, text
from sqlalchemy.orm import sessionmaker
import redis

# Connection pooling
engine = create_engine(
    'postgresql://user:pass@localhost/db',
    pool_size=20,
    max_overflow=0,
    pool_pre_ping=True,
    pool_recycle=3600
)

# Query optimization
class DatabaseOptimizer:
    def __init__(self, session):
        self.session = session

    def bad_n_plus_one(self):
        """N+1 query problem"""
        users = self.session.query(User).all()
        for user in users:
            posts = user.posts  # Triggers additional query per user
            print(f"{user.name}: {len(posts)} posts")

    def good_eager_loading(self):
        """Eager loading to avoid N+1"""
        from sqlalchemy.orm import joinedload

        users = self.session.query(User)\
            .options(joinedload(User.posts))\
            .all()

        for user in users:
            posts = user.posts  # No additional query
            print(f"{user.name}: {len(posts)} posts")

    def use_indexes(self):
        """Create indexes for frequent queries"""
        # Index on frequently queried columns
        Index('idx_user_email', User.email)
        Index('idx_post_created_at', Post.created_at)

        # Composite index
        Index('idx_post_user_status', Post.user_id, Post.status)

    def batch_operations(self, items: List[dict]):
        """Batch insert instead of individual inserts"""
        # Bad: Individual inserts
        # for item in items:
        #     self.session.add(User(**item))
        #     self.session.commit()

        # Good: Batch insert
        self.session.bulk_insert_mappings(User, items)
        self.session.commit()

    def use_pagination(self, page: int = 1, page_size: int = 20):
        """Paginate large result sets"""
        offset = (page - 1) * page_size

        return self.session.query(User)\
            .order_by(User.created_at.desc())\
            .limit(page_size)\
            .offset(offset)\
            .all()

# Redis caching
class CacheOptimizer:
    def __init__(self, redis_client: redis.Redis):
        self.redis = redis_client

    def cache_query_result(self, key: str, query_func, ttl: int = 3600):
        """Cache database query results"""
        # Check cache first
        cached = self.redis.get(key)
        if cached:
            return json.loads(cached)

        # Execute query
        result = query_func()

        # Cache result
        self.redis.setex(key, ttl, json.dumps(result))

        return result

    def cache_aside_pattern(self, key: str, fetch_func, ttl: int = 3600):
        """Implement cache-aside pattern"""
        data = self.redis.get(key)

        if data is None:
            data = fetch_func()
            self.redis.setex(key, ttl, json.dumps(data))
        else:
            data = json.loads(data)

        return data
```

## Frontend Performance

```javascript
// Debouncing for expensive operations
function debounce(func, wait) {
  let timeout;
  return function executedFunction(...args) {
    const later = () => {
      clearTimeout(timeout);
      func(...args);
    };
    clearTimeout(timeout);
    timeout = setTimeout(later, wait);
  };
}

// Example: Debounce search input
const searchInput = document.getElementById('search');
const debouncedSearch = debounce((query) => {
  // Expensive search operation
  fetchSearchResults(query);
}, 300);

searchInput.addEventListener('input', (e) => {
  debouncedSearch(e.target.value);
});

// Lazy loading images
const lazyLoadImages = () => {
  const images = document.querySelectorAll('img[data-src]');

  const imageObserver = new IntersectionObserver((entries) => {
    entries.forEach((entry) => {
      if (entry.isIntersecting) {
        const img = entry.target;
        img.src = img.dataset.src;
        img.removeAttribute('data-src');
        imageObserver.unobserve(img);
      }
    });
  });

  images.forEach((img) => imageObserver.observe(img));
};

// Virtual scrolling for large lists
class VirtualScroller {
  constructor(container, items, itemHeight) {
    this.container = container;
    this.items = items;
    this.itemHeight = itemHeight;
    this.visibleItems = Math.ceil(container.clientHeight / itemHeight);
    this.render();
  }

  render() {
    const scrollTop = this.container.scrollTop;
    const startIndex = Math.floor(scrollTop / this.itemHeight);
    const endIndex = startIndex + this.visibleItems;

    // Only render visible items
    const visibleData = this.items.slice(startIndex, endIndex);

    this.container.innerHTML = visibleData
      .map((item) => `<div style="height: ${this.itemHeight}px">${item}</div>`)
      .join('');
  }
}

// Code splitting with dynamic imports
async function loadModule() {
  const module = await import('./heavy-module.js');
  module.init();
}
```

## API Performance

```python
from fastapi import FastAPI, BackgroundTasks
from fastapi.responses import StreamingResponse
import asyncio
from typing import AsyncGenerator

app = FastAPI()

# Async endpoints for I/O bound operations
@app.get("/users/{user_id}")
async def get_user(user_id: str):
    """Async endpoint for database queries"""
    user = await db.fetch_user(user_id)
    return user

# Streaming responses for large data
async def generate_large_file() -> AsyncGenerator[bytes, None]:
    """Stream large file in chunks"""
    chunk_size = 8192
    with open("large_file.csv", "rb") as f:
        while chunk := f.read(chunk_size):
            yield chunk
            await asyncio.sleep(0)  # Allow other tasks to run

@app.get("/download")
async def download_large_file():
    return StreamingResponse(
        generate_large_file(),
        media_type="text/csv"
    )

# Background tasks for long-running operations
@app.post("/process")
async def process_data(background_tasks: BackgroundTasks):
    """Offload heavy processing to background"""
    background_tasks.add_task(heavy_processing_task)
    return {"status": "processing started"}

# Connection pooling
import aiohttp

class APIClient:
    def __init__(self):
        self.session = None

    async def __aenter__(self):
        self.session = aiohttp.ClientSession(
            connector=aiohttp.TCPConnector(limit=100)
        )
        return self

    async def __aexit__(self, *args):
        await self.session.close()

    async def fetch(self, url: str):
        async with self.session.get(url) as response:
            return await response.json()
```

## Load Testing

```python
from locust import HttpUser, task, between

class PerformanceTest(HttpUser):
    wait_time = between(1, 3)

    @task(3)
    def get_users(self):
        """High frequency endpoint"""
        self.client.get("/api/users")

    @task(1)
    def create_user(self):
        """Lower frequency endpoint"""
        self.client.post("/api/users", json={
            "email": "[email protected]",
            "name": "Test User"
        })

    def on_start(self):
        """Login once per user"""
        response = self.client.post("/api/login", json={
            "username": "test",
            "password": "password"
        })
        self.token = response.json()["token"]
```

## Best Practices

### General

- Measure before optimizing
- Focus on bottlenecks
- Use appropriate data structures
- Cache expensive computations
- Minimize I/O operations
- Use connection pooling
- Implement pagination

### Database

- Create proper indexes
- Avoid N+1 queries
- Use eager loading
- Batch operations
- Optimize queries
- Use read replicas
- Implement caching

### Frontend

- Minimize bundle size
- Code splitting
- Lazy loading
- Compress assets
- Use CDN
- Optimize images
- Debounce/throttle events

### Backend

- Use async for I/O
- Implement caching
- Connection pooling
- Background processing
- Horizontal scaling
- Load balancing

## Anti-Patterns

❌ Premature optimization
❌ No profiling/measurement
❌ Optimizing wrong bottlenecks
❌ Ignoring caching
❌ Synchronous I/O operations
❌ No database indexes
❌ Loading all data at once

## Resources

- Python Performance Tips: https://wiki.python.org/moin/PythonSpeed/PerformanceTips
- Web Performance: https://web.dev/performance/
- Locust Load Testing: https://locust.io/
- py-spy Profiler: https://github.com/benfred/py-spy
- Chrome DevTools: https://developer.chrome.com/docs/devtools/

© personamanagmentlayer · Apache-2.0 · personamanagmentlayer/pcl

Similar skills

All skills for DevOps and infrastructure →

From the same set104

The whole set →
elasticsearch-expert elasticsearch-expert is a Claude Code skill that helps design Elasticsearch mappings, build search queries and aggregations, and optimize ELK stacks. CX Codex +1 205installs prometheus-expert prometheus-expert — a skill that gives your coding agent solid Prometheus knowledge: metric collection, PromQL, recording and alerting rules. Useful when exporters have to go up on Kubernetes or a query just will not return what you expect. CX Codex +1 204installs kotlin-expert The kotlin-expert skill guides Kotlin work across Android, coroutines, JVM, and Kotlin Multiplatform. Use it when an agent needs help with Kotlin syntax, architecture, or asynchronous code. CX Codex +1 203installs react-expert react-expert configures coding agents for React 18+ and Next.js, enforcing clean TypeScript interfaces, proper hook usage, and tests with React Testing Library. CX Codex +1 200installs javascript-expert javascript-expert — a skill that makes the assistant work as a seasoned JavaScript developer across ES2024+, Node.js and npm, so the code it writes stays in one style. CX Codex +1 197installs stockbreeder-expert stockbreeder-expert is a Claude Code skill with Python domain models and workflows for livestock records, breeding, animal health monitoring, and vaccination schedules. CX Codex +1 195installs mongodb-expert The mongodb-expert skill covers MongoDB schema design, aggregation pipelines, indexes, replication, and production operations when database or performance work needs review. CX Codex +1 195installs elixir-expert elixir-expert is a Claude Code skill with Elixir, OTP, and Phoenix reference material for coding agents. It covers tasks involving a GenServer, supervision tree, or LiveView page. CX Codex +1 194installs

Project sponsors

Companies that keep this analytics open