agentleFS
ai-enhanced-engineerai-enhanced-engineer/aiee-skills/skills/performance-engineering/SKILL.md

performance-engineering

Skill4 starsChanged 5 months agoMITView on GitHub

Profiling, load testing, and optimization patterns for Python web services. Use for CPU/memory profiling (py-spy), load testing (Locust/k6), query optimization, or scaling WebSocket connections.

10 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use clack-cli-patterns, drag-to-reorder 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.
  • openchamberSkill

    clack-cli-patterns

    Use when creating or modifying OpenChamber CLI commands, prompts, terminal output, non-TTY behavior, `--quiet`, or `--json` behavior.

    Also in 3 projects that use this

  • openchamberSkill

    drag-to-reorder

    Use when implementing or modifying OpenChamber sortable or drag-to-reorder behavior, especially `@dnd-kit`, touch/mobile interactions, variable-width items, or wrapping layouts.

    Also in 3 projects that use this

  • gabriellstSkill

    desktop-shell

    Work on the CODM desktop shell — the Tauri v2 host (packages/app/tauri), the react client-side services DI (packages/app/react/src/services — ports + platform services + Container/Token + ServicesProvider), sidecar supervision, or any OS-integration capability (folder picker, notifications, badge, secrets, autostart). Use whenever a task mentions Tauri, the desktop app, sidecars, or an OS capability the react console needs.

    Also in 3 projects that use this

  • +9 more from openchamber

The file

Files
SKILL.md

Performance Engineering Skill

Profiling, load testing, and optimization patterns for Python web services.

When to Use

  • Profiling CPU/memory bottlenecks
  • Running load tests with Locust or k6
  • Optimizing database queries
  • Scaling WebSocket connections
  • Debugging async performance issues

Quick Reference

Performance Optimization Flow

Measure → Identify Bottleneck → Hypothesize → Fix → Verify → Monitor

Common Bottleneck Categories

CategorySymptomsFirst Tool
CPUHigh CPU, slow computepy-spy, cProfile
MemoryOOM, high RSSmemory_profiler
I/OSlow responses, waitsasyncio debug
DatabaseSlow queriespg_stat_statements
NetworkLatency varianceCloud Trace

Key Metrics (SLOs)

MetricTargetAlert
P50 latency<100ms>200ms
P95 latency<500ms>1s
P99 latency<2s>5s
Error rate<0.1%>1%
ThroughputVaries>20% drop

Quick Profiling Commands

CPU Profiling (py-spy)

# Profile running process
py-spy record -o profile.svg --pid <PID>

# Profile command
py-spy record -o profile.svg -- python app.py

Memory Profiling

# Line-by-line memory
python -m memory_profiler script.py

# Track allocations
python -m tracemalloc script.py

Load Testing (Locust)

# Run load test
locust -f locustfile.py --host=https://api.example.com

# Headless with params
locust -f locustfile.py --headless -u 100 -r 10 -t 60s

Common Optimizations

PatternWhen to ApplyImpact
Connection poolingDB bottleneckHigh
Async I/OI/O-bound codeHigh
CachingRepeated readsMedium-High
Query optimizationSlow queriesHigh
Batch processingMany small opsMedium
Startup warmupFirst-request latencyMedium-High

Startup Warmup Pattern

Eliminate first-request latency penalty by warming HTTP connection pools during application startup.

Problem: Lazy connection pool initialization causes 500-1000ms penalty on first request (TCP + SSL/TLS + HTTP/2 setup).

Quick Implementation:

# FastAPI lifespan warmup
@asynccontextmanager
async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
    try:
        await client.models.list(limit=1)  # Lightweight authenticated call
        logger.info("Connection pool warmed")
    except Exception as e:
        logger.warning("Warmup failed - will lazy-init", error=str(e))
        # Non-fatal: first request will initialize

    yield

When to use: Any HTTP client (OpenAI, httpx, aiohttp) in Cloud Run / serverless.

See reference.md for full pattern with timing measurement and error handling.

Database Query Anti-Patterns

MD5 Hash JOINs on Large Tables

Anti-Pattern:

-- SLOW: MD5 JOIN between raw data and materialized view
SELECT mv.category, m.content AS example
FROM mv_top_questions mv
JOIN messages m ON MD5(m.content) = mv.content_hash
WHERE mv.customer_id = 'cust_123';

Why it's slow:

  • MD5() computes for every row in messages table
  • Hash functions prevent index usage
  • Full table scan (millions of rows) = 10-60 seconds per query

Correct Pattern:

-- Pre-compute during MV refresh - store needed data directly
CREATE MATERIALIZED VIEW mv_top_questions AS
SELECT customer_id, category, COUNT(*) as frequency,
       ARRAY_AGG(content ORDER BY created_at DESC LIMIT 3) as examples
FROM categorized_messages
GROUP BY customer_id, category;

-- Query is instant (no JOIN needed)
SELECT category, frequency, examples
FROM mv_top_questions WHERE customer_id = 'cust_123';

Rule: For MVs serving user-facing queries, pre-compute every needed column during refresh. JOINing raw tables to an MV at query time defeats the entire purpose of materializing — the MV becomes a slow indirection layer instead of a cache.

Impact: 10-60 sec → <50ms (100-1000x improvement)

Files

  • reference.md - Detailed profiling, load testing, optimization patterns
  • examples.md - Working code for profiling, Locust tests, async patterns

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.