--- name: performance-optimization description: Performance optimization patterns for GoodGo microservices including database query optimization, memory leak detection, profiling, connection pooling, and caching strategies. --- # Performance Optimization Patterns ## When to Use This Skill Use this skill when: - Optimizing database queries - Detecting and fixing memory leaks - Profiling application performance - Optimizing connection pooling - Improving caching strategies - Identifying N+1 query problems ## Key Patterns ### Database Query Optimization ```typescript // Avoid N+1 queries // Bad: Multiple queries for (const user of users) { user.orders = await orderRepository.findByUserId(user.id); } // Good: Single query with join const users = await userRepository.findAll({ include: { orders: true }, }); ``` ### Memory Profiling ```typescript // Monitor memory usage const profiler = new MemoryProfiler(); profiler.start(); // Monitor every minute ``` ### Batch Operations ```typescript // Batch database operations await batchOperations.batchCreate(items, 100); // Process 100 at a time ``` ## Best Practices 1. Use indexes, avoid N+1 queries 2. Monitor memory usage, detect leaks 3. Cache frequently accessed data 4. Configure connection pools appropriately 5. Profile regularly to identify bottlenecks ## Resources - [Caching Patterns](./caching-patterns.md) - [Observability & Monitoring](./observability-monitoring.md) - Skill Source: `.cursor/skills/performance-optimization/SKILL.md`