mcpField
P
performance

performance

github.com/krzysztofsurdyDevelopment3641 installsUpdated 3d ago
Repository

About performance

A performance optimization reference skill for developers investigating slow or resource-intensive software. It emphasizes profiling before changes and covers caching, database queries, memory management, and measurement workflows.

Key features

  1. 01Profile-first optimization workflow
  2. 02Performance budgets and benchmarking
  3. 03Cache layers and invalidation
  4. 04Database query optimization
  5. 05Memory and resource management

Use cases

  1. 01Finding CPU, memory, or I/O bottlenecks
  2. 02Reducing repeated database queries
  3. 03Choosing cache invalidation strategies
  4. 04Verifying the effect of code changes

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/krzysztofsurdy/code-virtuoso --skill performance

After installing, type/performancein Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

references/
caching-strategies.md
database-optimization.md
profiling-patterns.md

Details

From the project README

Performance Optimization

Performance work follows one rule: measure before you change anything. Intuition about bottlenecks is wrong more often than right. Every optimization starts with profiling, forms a hypothesis, applies a targeted fix, and ends with another measurement.

Core principles

PrincipleMeaning
Measure firstNever optimize without profiling data. Gut feelings about bottlenecks are unreliable
Optimize the critical pathFocus on the code that runs most often or blocks user-visible latency
Set budgetsDefine acceptable latency, throughput, and resource usage before you start
Avoid premature optimizationWrite readable, correct code first. Optimize only when measurements show a real problem
Know the tradeoffsEvery optimization costs something (memory for speed, complexity for throughput, freshness for latency)

Profiling and benchmarking

Profiling shows where time and resources go. Without it you are guessing.

Types of profiling
TypeWhat it revealsWhen to use
CPU profilingHot functions, call frequency, execution time distributionSlow request handling, high CPU usage
Memory profilingAllocation rates, heap size, object retention, leaksGrowing memory usage, OOM errors, GC pressure
I/O profilingDisk reads/writes, network calls, blocking waitsSlow file operations, external service latency
Database profilingQuery execution time, query count per request, slow queriesHigh DB load, N+1 patterns, missing indexes
The profiling workflow
  1. Baseline: capture metrics under normal conditions before any changes
  2. Identify: find the hotspot using the most time or resources
  3. Hypothesize: form a specific theory about why it is slow
  4. Fix: apply a single, targeted change
  5. Verify: measure again to confirm the improvement and check for regressions
Performance budgets

Define limits that trigger action when exceeded:

  • Response time: P50, P95, P99 latency targets per endpoint
  • Throughput: Minimum requests per second under expected load
  • Resource usage: CPU, memory, and connection limits per service
  • Page weight: Maximum transfer size for frontend assets

See Profiling Patterns Reference for profiling workflows, bottleneck signatures, and load testing strategies.


Caching strategies

Caching removes redundant computation and data fetching by storing results closer to where they are needed.

Cache layers
LayerLocationLatencyUse case
L1 - In-processApplication memory (object cache, memoization)NanosecondsHot data accessed many times per request
L2 - DistributedRedis, Memcached, shared cacheSub-millisecond to low millisecondsData shared across application instances
HTTP cacheBrowser, reverse proxy (Varnish, Nginx)Zero network round-trip for client cacheStatic assets, cacheable API responses
CDNEdge servers worldwideLow latency from geographic proximityStatic files, pre-rendered pages, media
Database cacheQuery result cache, buffer poolVariesRepeated identical queries
Invalidation approaches
StrategyHow it worksBest for
TTL-basedCache entries expire after a fixed durationData that tolerates bounded staleness
Event-basedCache is cleared when the source data changesData that must stay fresh after writes
Write-throughWrites update both the cache and the backing store at the same timeRead-heavy workloads needing strong consistency
Write-behindWrites update the cache immediately; backing store is updated asynchronouslyHigh write throughput where eventual consistency is acceptable
Cache stampede prevention

When a popular cache key expires, many concurrent requests may all try to regenerate it at once and overwhelm the backend. Three approaches prevent this:

  • Locking: only one request regenerates; others wait or serve stale data
  • Probabilistic early recomputation: requests randomly refresh the cache before expiration, spreading regeneration over time
  • Request coalescing: duplicate in-flight requests are collapsed into a single backend call

See Caching Strategies Reference for implementation patterns with multi-language examples.


Database optimization

Database queries are the most common performance bottleneck in web applications.

Index strategy
  • Create indexes on columns used in WHERE, JOIN, and ORDER BY clauses
  • Use composite indexes that match the most frequent query patterns (leftmost prefix rule)
  • Covering indexes include all columns a query needs, so no table lookup is required
  • Monitor unused indexes, since they slow down writes without helping reads
N+1 query prevention

The N+1 problem occurs when code fetches a list of N records and then runs one more query per record to load related data. Instead of 1 query, it runs N+1.

Detection signals:

  • Query count scales linearly with result set size
  • Many nearly identical queries differing only in a single parameter
  • Profiler shows dozens or hundreds of queries for a single page load

Prevention strategies:

  • Eager loading (JOIN or separate batch query upfront)
  • Batch loading (collect IDs, fetch all related records in one query)
  • DataLoader pattern (batching and deduplication within a request)
Connection pooling

Opening a database connection is expensive (TCP handshake, authentication, TLS negotiation). A connection pool keeps a set of reusable connections:

  • Size the pool for expected concurrency: too small causes queueing, too large overwhelms the database
  • Return connections to the pool as soon as the work is done, because leaked connections exhaust the pool
  • Set idle timeouts to reclaim unused connections
  • Use external poolers (like PgBouncer for PostgreSQL) when application-level pooling is not enough

See Database Optimization Reference for query patterns, explain plan analysis, and multi-language examples.


Memory and resource management

Memory optimization patterns
PatternDescription
Object poolingReuse expensive objects instead of allocating and discarding them
StreamingProcess large datasets as streams instead of loading everything into memory
Lazy initializationDefer creation of expensive objects until they are needed
Weak referencesHold references that do not prevent garbage collection
Buffer reuseAllocate buffers once and reuse them across operations
Lazy loading

Lazy loading defers work until the result is needed. It reduces startup time and memory use, but adds complexity and can cause surprise latency later.

Where lazy loading helps:

  • Loading related database records only when accessed
  • Initializing expensive service connections on first use
  • Loading UI components or assets only when they become visible

Where lazy loading hurts:

  • When the deferred work always happens anyway (it only adds overhead)
  • When it moves latency from a predictable startup phase to unpredictable user interactions
  • When it creates N+1 query patterns (see Database Optimization above)
Batch operations

Replace individual operations with batch alternatives where possible:

  • Batch inserts instead of inserting one row at a time
  • Batch API calls instead of calling an external service N times
  • Bulk file operations instead of processing files individually

Quick reference: common bottleneck patterns

SymptomLikely causeFirst investigation step
Slow response times, low CPUI/O waits (database, network, disk)Profile I/O and check query logs
High CPU, normal response timesInefficient algorithms or excessive computationCPU profile to find hot functions
Growing memory over timeMemory leak (unreleased references, unbounded caches)Heap dump comparison over time
Intermittent slowness under loadResource contention (locks, connection pool exhaustion)Check pool sizes and lock wait times
Fast locally, slow in productionNetwork latency, missing caches, different data volumesCompare profiling data between environments

Reference Files

ReferenceContents
Caching StrategiesCache layers, invalidation patterns, stampede prevention, with multi-language examples
Database OptimizationQuery optimization, N+1 prevention, connection pooling, batch operations, with multi-language examples
Profiling PatternsProfiling workflows, bottleneck signatures, performance budgets, load testing strategies

Integration with Other Skills

SituationRecommended Skill
Performance issues caused by poor architectureclean-architecture
Need to refactor slow code pathsrefactoring
API response time optimizationapi-design
Database schema and query designdatabase-design

Comments

Markdown supported