agentleFS
Jonathan0823Jonathan0823/opencode-config/skills/performance-optimization/SKILL.md

performance-optimization

Skill8 starsChanged 10 months agoMITView on GitHub

Performance optimization strategies including caching, profiling, database query optimization, frontend optimization, and load testing. Use when optimizing application performance, reducing latency, improving throughput, or diagnosing performance bottlenecks.

83 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use constraint-driven-development, using-agent-skills and 10 more.

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.
  • vinvcnSkill

    constraint-driven-development

    把一个项目的质量线确立为书面契约,并阻止 agent 悄悄降低它。通过访谈确定用户在意哪些维度,当用户心里没有数字时提供合理的默认阈值,把一切记录进 CONSTRAINTS.md,并盯住 diff 中质量线被削弱的迹象——新增的 @ts-ignore 或 eslint-disable 抑制注释、被跳过或删除的测试、被剥掉的断言、未实现的 stub、被调低的阈值。当没有任何质量线被写下来时使用;当用户说 "set up constraints" 或 "define our standards" 时;当用户希望把他们在意的维度——无障碍性、Web 性能、覆盖率——设置成被强制执行的约束时;当 agent 为了变绿不断静默检查或跳过测试时;当你需要一个覆盖率或性能阈值却不知道该选什么数字时;或者当 agent 写下的代码超出任何人会读的体量时。

    Also in 4 projects that use this

  • LLl0k0laDSkill

    using-agent-skills

    Use when starting a session or when you need to discover which skill applies to the current task. This is the meta-skill that governs how all other skills are discovered and invoked.

    Also in 21 projects that use this

  • LLl0k0laDSkill

    git-workflow-and-versioning

    Use when making any code change. Use when committing, branching, resolving conflicts, or when you need to organize work across multiple parallel streams.

    Also in 23 projects that use this

  • borhen68Skill

    observability-and-instrumentation

    Instruments code so production behavior is visible and diagnosable. Use when adding logging, metrics, tracing, or alerting. Use when shipping any feature that runs in production and you need evidence it works. Use when production issues are reported but you can't tell what happened from the available data.

    Also in 12 projects that use this

  • az9713Skill

    deprecation-and-migration

    Manages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when deciding whether to maintain or sunset existing code.

    Also in 21 projects that use this

  • az9713Skill

    code-simplification

    Simplifies code for clarity. Use when refactoring code for clarity without changing behavior. Use when code works but is harder to read, maintain, or extend than it should be. Use when reviewing code that has accumulated unnecessary complexity.

    Also in 29 projects that use this

  • +6 more from LLl0k0laD

The file

We split this skill into the rules it gives an agent

1 rule. 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 72 edited versions we read keep these.

  • 1

    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
  1. Distinctive:

    Use this skill when:

    line 251

“Common” is measured: kept by at least 6 in 10 of the 72 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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Performance Optimization Skill

Overview

This skill provides comprehensive performance optimization strategies covering application profiling, caching strategies, database optimization, frontend performance, and load testing methodologies.

Quick Start

Performance Checklist

  • Profile to identify bottlenecks before optimizing
  • Optimize database queries and add indexes
  • Implement caching at appropriate layers
  • Use CDN for static assets
  • Enable compression and minification
  • Implement lazy loading
  • Use connection pooling
  • Load test before production

Common Bottlenecks

  1. N+1 Query Problem - Missing eager loading
  2. Missing Indexes - Full table scans
  3. Synchronous I/O - Blocking operations
  4. Large Payloads - Unoptimized responses
  5. Memory Leaks - Unreleased resources
  6. Cold Starts - Unoptimized initialization

Caching Strategies

Application-Level Caching

# Python with functools.lru_cache
from functools import lru_cache

@lru_cache(maxsize=128)
def get_user_by_id(user_id: int) -> dict:
    return db.query(User).get(user_id)

# Redis caching
import redis
from functools import wraps

r = redis.Redis(host='localhost', port=6379, db=0)

def cache_with_ttl(seconds=300):
    def decorator(func):
        @wraps(func)
        def wrapper(*args, **kwargs):
            key = f"{func.__name__}:{args}:{kwargs}"
            cached = r.get(key)
            if cached:
                return json.loads(cached)
            
            result = func(*args, **kwargs)
            r.setex(key, seconds, json.dumps(result))
            return result
        return wrapper
    return decorator

@cache_with_ttl(seconds=600)
def get_expensive_data(param: str):
    # Expensive operation
    return result

CDN Caching

# CloudFront/CloudFlare headers
Cache-Control: public, max-age=31536000, immutable  # Static assets
Cache-Control: public, max-age=3600                 # API responses
Cache-Control: private, no-cache                    # User-specific data

Database Query Caching

# SQLAlchemy query caching
from sqlalchemy.orm import joinedload

# ❌ N+1 Problem
users = db.query(User).all()
for user in users:
    print(user.profile.bio)  # N additional queries

# ✅ Eager Loading
users = db.query(User).options(joinedload(User.profile)).all()

# ✅ Selective Loading
users = db.query(User).options(
    joinedload(User.profile),
    joinedload(User.posts)
).all()

Database Optimization

Query Optimization

-- ❌ Full table scan
SELECT * FROM orders WHERE YEAR(created_at) = 2024;

-- ✅ Index-friendly query
SELECT * FROM orders 
WHERE created_at >= '2024-01-01' 
AND created_at < '2025-01-01';

-- ✅ Covering index
CREATE INDEX idx_orders_user_date ON orders(user_id, created_at) 
INCLUDE (total_amount, status);

-- ✅ Composite index for range queries
CREATE INDEX idx_products_category_price ON products(category, price);

Connection Pooling

# SQLAlchemy connection pooling
from sqlalchemy import create_engine

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

# Node.js with pg-pool
const pool = new Pool({
  host: 'localhost',
  port: 5432,
  database: 'myapp',
  max: 20,        // Maximum pool size
  idleTimeoutMillis: 30000,
  connectionTimeoutMillis: 2000,
});

Frontend Optimization

Code Splitting

// React lazy loading
const Dashboard = lazy(() => import('./Dashboard'));
const Analytics = lazy(() => import('./Analytics'));

// Route-based splitting
<Route path="/dashboard" component={Dashboard} />
<Route path="/analytics" component={Analytics} />

Image Optimization

<!-- Responsive images -->
<picture>
  <source srcset="image.webp" type="image/webp">
  <source srcset="image.jpg" type="image/jpeg">
  <img src="image.jpg" alt="Description" loading="lazy">
</picture>

<!-- Next.js Image component -->
import Image from 'next/image';

<Image
  src="/photo.jpg"
  alt="Photo"
  width={800}
  height={600}
  placeholder="blur"
  priority={false}
/>

Profiling

Python Profiling

# cProfile
import cProfile
import pstats

profiler = cProfile.Profile()
profiler.enable()

# Your code here
result = expensive_function()

profiler.disable()
stats = pstats.Stats(profiler)
stats.sort_stats('cumulative')
stats.print_stats(20)

# Line profiler
from line_profiler import LineProfiler

profiler = LineProfiler()

@profiler  # Add decorator
def my_function():
    for i in range(1000):
        x = [i ** 2 for i in range(1000)]
    return x

my_function()
profiler.print_stats()

Database Query Analysis

-- PostgreSQL EXPLAIN ANALYZE
EXPLAIN (ANALYZE, BUFFERS, FORMAT JSON)
SELECT * FROM orders o
JOIN users u ON o.user_id = u.id
WHERE o.status = 'pending';

-- MySQL EXPLAIN
EXPLAIN ANALYZE
SELECT * FROM orders 
WHERE user_id = 123 
ORDER BY created_at DESC 
LIMIT 10;

Detailed References

See comprehensive guides in references/:

  • Caching Strategies - Redis, CDN, application caching, cache invalidation
  • Database Optimization - Query optimization, indexing, connection pooling
  • Frontend Performance - Code splitting, lazy loading, image optimization, Core Web Vitals
  • Load Testing - k6, Artillery, JMeter, performance testing strategies

When to Use This Skill

Use this skill when:

  • Application is slow or unresponsive
  • Database queries are taking too long
  • API response times need improvement
  • Implementing caching strategies
  • Optimizing frontend performance
  • Preparing for high traffic events
  • Conducting performance audits
  • Setting up monitoring and alerting

Related Skills

  • @kubernetes-patterns - Scaling and resource optimization
  • @docker-patterns - Container optimization
  • @postgresql-patterns - Database-specific optimization
  • @mongodb-patterns - NoSQL optimization
  • @observability-monitoring - Performance monitoring

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.