Performance Expert

The Performance Expert agent specializes in optimization, profiling, and making applications faster.

Expertise Areas#

  • Frontend Performance - Core Web Vitals, bundle size, rendering
  • Backend Performance - Response times, throughput, concurrency
  • Database Performance - Query optimization, indexing, caching
  • Caching Strategies - Redis, CDN, browser caching
  • Profiling - CPU, memory, network analysis
  • Load Testing - Stress testing, benchmarking

Usage Examples#

Performance Audit#

Use the performance-expert agent to audit the performance of our Next.js application.

Response includes:

  • Core Web Vitals analysis
  • Bundle size review
  • Rendering optimization opportunities
  • Caching recommendations

Query Optimization#

Use the performance-expert agent to optimize this slow database query.

Response includes:

  • Query analysis
  • Index recommendations
  • Rewritten query
  • Execution plan explanation

Load Testing#

Use the performance-expert agent to create a load testing strategy for our API.

Response includes:

  • Test scenarios
  • Tool recommendations
  • Metrics to track
  • Baseline targets

Frontend Performance#

Core Web Vitals#

MetricTargetDescription
LCP< 2.5sLargest Contentful Paint
FID< 100msFirst Input Delay
CLS< 0.1Cumulative Layout Shift
TTFB< 800msTime to First Byte
FCP< 1.8sFirst Contentful Paint

Bundle Optimization#

1// Dynamic imports for code splitting 2const HeavyComponent = dynamic(() => import('./HeavyComponent'), { 3 loading: () => <Skeleton />, 4 ssr: false, // Client-only if needed 5}); 6 7// Route-based splitting (automatic in Next.js) 8// Each page is a separate bundle 9 10// Analyze bundle 11// npx @next/bundle-analyzer

Image Optimization#

1import Image from 'next/image'; 2 3// Optimized image loading 4<Image 5 src="/hero.jpg" 6 alt="Hero" 7 width={1200} 8 height={600} 9 priority // LCP image 10 placeholder="blur" 11 blurDataURL={blurDataUrl} 12/> 13 14// Responsive images 15<Image 16 src="/product.jpg" 17 alt="Product" 18 sizes="(max-width: 768px) 100vw, 50vw" 19 fill 20 style={{ objectFit: 'cover' }} 21/>

React Performance#

1// Memoize expensive computations 2const expensiveResult = useMemo(() => { 3 return heavyComputation(data); 4}, [data]); 5 6// Memoize callbacks 7const handleClick = useCallback(() => { 8 doSomething(id); 9}, [id]); 10 11// Memoize components 12const MemoizedComponent = memo(function Component({ data }) { 13 return <div>{/* ... */}</div>; 14}); 15 16// Virtualize long lists 17import { FixedSizeList } from 'react-window'; 18 19<FixedSizeList 20 height={600} 21 itemCount={10000} 22 itemSize={50} 23> 24 {({ index, style }) => ( 25 <div style={style}>{items[index].name}</div> 26 )} 27</FixedSizeList>

Backend Performance#

Response Time Optimization#

1// Parallel data fetching 2const [users, posts, comments] = await Promise.all([ 3 fetchUsers(), 4 fetchPosts(), 5 fetchComments(), 6]); 7 8// vs Sequential (slower) 9const users = await fetchUsers(); 10const posts = await fetchPosts(); 11const comments = await fetchComments();

Caching Strategies#

1import { Redis } from 'ioredis'; 2 3const redis = new Redis(); 4const CACHE_TTL = 3600; // 1 hour 5 6async function getCachedData(key: string, fetcher: () => Promise<any>) { 7 // Try cache first 8 const cached = await redis.get(key); 9 if (cached) { 10 return JSON.parse(cached); 11 } 12 13 // Fetch and cache 14 const data = await fetcher(); 15 await redis.setex(key, CACHE_TTL, JSON.stringify(data)); 16 17 return data; 18} 19 20// Usage 21const user = await getCachedData( 22 `user:${id}`, 23 () => prisma.user.findUnique({ where: { id } }) 24);

Connection Pooling#

// Prisma with connection pooling // DATABASE_URL="postgresql://...?connection_limit=20&pool_timeout=20" // PgBouncer for PostgreSQL // Transaction mode for serverless

Database Performance#

Index Optimization#

1-- Identify missing indexes 2SELECT 3 relname, 4 seq_scan, 5 idx_scan, 6 seq_scan - idx_scan AS difference 7FROM pg_stat_user_tables 8WHERE seq_scan > idx_scan 9ORDER BY difference DESC; 10 11-- Create covering index 12CREATE INDEX idx_orders_user_status 13ON orders(user_id, status) 14INCLUDE (total, created_at); 15 16-- Partial index for common queries 17CREATE INDEX idx_active_users 18ON users(email) 19WHERE deleted_at IS NULL;

Query Analysis#

1-- Explain analyze 2EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT) 3SELECT * 4FROM orders o 5JOIN users u ON o.user_id = u.id 6WHERE o.status = 'pending' 7ORDER BY o.created_at DESC 8LIMIT 10;

Caching Layers#

┌─────────────────────────────────────────────────────────┐ │ Browser Cache │ │ (Service Worker, HTTP Cache) │ ├─────────────────────────────────────────────────────────┤ │ CDN │ │ (Edge caching, static assets) │ ├─────────────────────────────────────────────────────────┤ │ Application Cache │ │ (Redis, in-memory cache) │ ├─────────────────────────────────────────────────────────┤ │ Database Cache │ │ (Query cache, buffer pool) │ └─────────────────────────────────────────────────────────┘

Sample Prompts#

TaskPrompt
Audit"Audit Core Web Vitals for our landing page"
Bundle"Reduce JavaScript bundle size by 50%"
Caching"Design a caching strategy for product listings"
Database"Optimize queries for the dashboard endpoint"
Load test"Create k6 load tests for our checkout API"

Configuration#

1// bootspring.config.js 2module.exports = { 3 agents: { 4 customInstructions: { 5 'performance-expert': ` 6 - Measure before optimizing 7 - Focus on user-perceived performance 8 - Consider trade-offs (complexity vs. gains) 9 - Recommend monitoring solutions 10 - Provide benchmarks and targets 11 `, 12 }, 13 }, 14};