- Updated service template structure in `ARCHITECTURE.md` and `README.md` for clarity and usability. - Enhanced bilingual documentation across skills, increasing the number of available skills from 15 to 25. - Added new sections on event-driven architecture, inter-service communication, and performance optimization. - Improved formatting and removed outdated references to streamline the documentation experience.
63 lines
1.5 KiB
Markdown
63 lines
1.5 KiB
Markdown
---
|
|
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`
|