locus-product-planning 1.1.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +2 -2
- package/LICENSE +21 -21
- package/README.md +11 -7
- package/agents/engineering/architect-reviewer.md +122 -122
- package/agents/engineering/engineering-manager.md +101 -101
- package/agents/engineering/principal-engineer.md +98 -98
- package/agents/engineering/staff-engineer.md +86 -86
- package/agents/engineering/tech-lead.md +114 -114
- package/agents/executive/ceo-strategist.md +81 -81
- package/agents/executive/cfo-analyst.md +97 -97
- package/agents/executive/coo-operations.md +100 -100
- package/agents/executive/cpo-product.md +104 -104
- package/agents/executive/cto-architect.md +90 -90
- package/agents/product/product-manager.md +70 -70
- package/agents/product/project-manager.md +95 -95
- package/agents/product/qa-strategist.md +132 -132
- package/agents/product/scrum-master.md +70 -70
- package/dist/index.cjs +13012 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{lib/skills-core.d.ts → index.d.cts} +46 -12
- package/dist/index.d.ts +113 -5
- package/dist/index.js +12963 -237
- package/dist/index.js.map +1 -0
- package/package.json +88 -82
- package/skills/01-executive-suite/ceo-strategist/SKILL.md +132 -132
- package/skills/01-executive-suite/cfo-analyst/SKILL.md +187 -187
- package/skills/01-executive-suite/coo-operations/SKILL.md +211 -211
- package/skills/01-executive-suite/cpo-product/SKILL.md +231 -231
- package/skills/01-executive-suite/cto-architect/SKILL.md +173 -173
- package/skills/02-product-management/estimation-expert/SKILL.md +139 -139
- package/skills/02-product-management/product-manager/SKILL.md +265 -265
- package/skills/02-product-management/program-manager/SKILL.md +178 -178
- package/skills/02-product-management/project-manager/SKILL.md +221 -221
- package/skills/02-product-management/roadmap-strategist/SKILL.md +186 -186
- package/skills/02-product-management/scrum-master/SKILL.md +212 -212
- package/skills/03-engineering-leadership/architect-reviewer/SKILL.md +249 -249
- package/skills/03-engineering-leadership/engineering-manager/SKILL.md +207 -207
- package/skills/03-engineering-leadership/principal-engineer/SKILL.md +206 -206
- package/skills/03-engineering-leadership/staff-engineer/SKILL.md +237 -237
- package/skills/03-engineering-leadership/tech-lead/SKILL.md +296 -296
- package/skills/04-developer-specializations/core/api-designer/SKILL.md +579 -0
- package/skills/04-developer-specializations/core/backend-developer/SKILL.md +205 -205
- package/skills/04-developer-specializations/core/frontend-developer/SKILL.md +233 -233
- package/skills/04-developer-specializations/core/fullstack-developer/SKILL.md +202 -202
- package/skills/04-developer-specializations/core/mobile-developer/SKILL.md +220 -220
- package/skills/04-developer-specializations/data-ai/data-engineer/SKILL.md +316 -316
- package/skills/04-developer-specializations/data-ai/data-scientist/SKILL.md +338 -338
- package/skills/04-developer-specializations/data-ai/llm-architect/SKILL.md +390 -390
- package/skills/04-developer-specializations/data-ai/ml-engineer/SKILL.md +349 -349
- package/skills/04-developer-specializations/design/ui-ux-designer/SKILL.md +337 -0
- package/skills/04-developer-specializations/infrastructure/cloud-architect/SKILL.md +354 -354
- package/skills/04-developer-specializations/infrastructure/database-architect/SKILL.md +430 -0
- package/skills/04-developer-specializations/infrastructure/devops-engineer/SKILL.md +306 -306
- package/skills/04-developer-specializations/infrastructure/kubernetes-specialist/SKILL.md +419 -419
- package/skills/04-developer-specializations/infrastructure/platform-engineer/SKILL.md +289 -289
- package/skills/04-developer-specializations/infrastructure/security-engineer/SKILL.md +336 -336
- package/skills/04-developer-specializations/infrastructure/sre-engineer/SKILL.md +425 -425
- package/skills/04-developer-specializations/languages/golang-pro/SKILL.md +366 -366
- package/skills/04-developer-specializations/languages/java-architect/SKILL.md +296 -296
- package/skills/04-developer-specializations/languages/python-pro/SKILL.md +317 -317
- package/skills/04-developer-specializations/languages/rust-engineer/SKILL.md +309 -309
- package/skills/04-developer-specializations/languages/typescript-pro/SKILL.md +251 -251
- package/skills/04-developer-specializations/quality/accessibility-tester/SKILL.md +338 -338
- package/skills/04-developer-specializations/quality/performance-engineer/SKILL.md +384 -384
- package/skills/04-developer-specializations/quality/qa-expert/SKILL.md +413 -413
- package/skills/04-developer-specializations/quality/security-auditor/SKILL.md +359 -359
- package/skills/04-developer-specializations/quality/test-automation-engineer/SKILL.md +711 -0
- package/skills/05-specialists/compliance-specialist/SKILL.md +171 -171
- package/skills/05-specialists/technical-writer/SKILL.md +576 -0
- package/skills/using-locus/SKILL.md +5 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/lib/skills-core.d.ts.map +0 -1
- package/dist/lib/skills-core.js +0 -361
|
@@ -1,384 +1,384 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: performance-engineer
|
|
3
|
-
description: Performance testing, profiling, optimization, and ensuring systems meet performance requirements at scale
|
|
4
|
-
metadata:
|
|
5
|
-
version: "1.0.0"
|
|
6
|
-
tier: developer-specialization
|
|
7
|
-
category: quality
|
|
8
|
-
council: code-review-council
|
|
9
|
-
---
|
|
10
|
-
|
|
11
|
-
# Performance Engineer
|
|
12
|
-
|
|
13
|
-
You embody the perspective of a Performance Engineer with expertise in identifying bottlenecks, load testing, and optimizing systems for speed and scalability.
|
|
14
|
-
|
|
15
|
-
## When to Apply
|
|
16
|
-
|
|
17
|
-
Invoke this skill when:
|
|
18
|
-
- Identifying performance bottlenecks
|
|
19
|
-
- Designing load tests
|
|
20
|
-
- Profiling applications
|
|
21
|
-
- Optimizing database queries
|
|
22
|
-
- Improving frontend performance
|
|
23
|
-
- Setting performance budgets
|
|
24
|
-
- Analyzing performance metrics
|
|
25
|
-
|
|
26
|
-
## Core Competencies
|
|
27
|
-
|
|
28
|
-
### 1. Performance Testing
|
|
29
|
-
- Load testing design
|
|
30
|
-
- Stress testing
|
|
31
|
-
- Spike testing
|
|
32
|
-
- Capacity planning
|
|
33
|
-
|
|
34
|
-
### 2. Profiling
|
|
35
|
-
- CPU profiling
|
|
36
|
-
- Memory profiling
|
|
37
|
-
- Database query analysis
|
|
38
|
-
- Network analysis
|
|
39
|
-
|
|
40
|
-
### 3. Frontend Performance
|
|
41
|
-
- Core Web Vitals
|
|
42
|
-
- Bundle optimization
|
|
43
|
-
- Rendering performance
|
|
44
|
-
- Caching strategies
|
|
45
|
-
|
|
46
|
-
### 4. Backend Optimization
|
|
47
|
-
- Query optimization
|
|
48
|
-
- Caching layers
|
|
49
|
-
- Connection pooling
|
|
50
|
-
- Async processing
|
|
51
|
-
|
|
52
|
-
## Load Testing
|
|
53
|
-
|
|
54
|
-
### k6 Load Test
|
|
55
|
-
```javascript
|
|
56
|
-
import http from 'k6/http';
|
|
57
|
-
import { check, sleep } from 'k6';
|
|
58
|
-
import { Rate, Trend } from 'k6/metrics';
|
|
59
|
-
|
|
60
|
-
// Custom metrics
|
|
61
|
-
const errorRate = new Rate('errors');
|
|
62
|
-
const responseTime = new Trend('response_time');
|
|
63
|
-
|
|
64
|
-
export const options = {
|
|
65
|
-
stages: [
|
|
66
|
-
{ duration: '2m', target: 100 }, // Ramp up
|
|
67
|
-
{ duration: '5m', target: 100 }, // Steady state
|
|
68
|
-
{ duration: '2m', target: 200 }, // Peak load
|
|
69
|
-
{ duration: '5m', target: 200 }, // Sustained peak
|
|
70
|
-
{ duration: '2m', target: 0 }, // Ramp down
|
|
71
|
-
],
|
|
72
|
-
thresholds: {
|
|
73
|
-
http_req_duration: ['p(95)<500', 'p(99)<1000'],
|
|
74
|
-
errors: ['rate<0.01'],
|
|
75
|
-
},
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
export default function () {
|
|
79
|
-
const res = http.get('https://api.example.com/products');
|
|
80
|
-
|
|
81
|
-
check(res, {
|
|
82
|
-
'status is 200': (r) => r.status === 200,
|
|
83
|
-
'response time < 500ms': (r) => r.timings.duration < 500,
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
errorRate.add(res.status !== 200);
|
|
87
|
-
responseTime.add(res.timings.duration);
|
|
88
|
-
|
|
89
|
-
sleep(1);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export function handleSummary(data) {
|
|
93
|
-
return {
|
|
94
|
-
'summary.json': JSON.stringify(data),
|
|
95
|
-
stdout: textSummary(data, { indent: ' ', enableColors: true }),
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
### Test Scenarios
|
|
101
|
-
| Type | Purpose | Pattern |
|
|
102
|
-
|------|---------|---------|
|
|
103
|
-
| Load Test | Normal operation | Steady load at expected peak |
|
|
104
|
-
| Stress Test | Breaking point | Increase until failure |
|
|
105
|
-
| Spike Test | Traffic bursts | Sudden large increase |
|
|
106
|
-
| Soak Test | Memory leaks | Extended steady load |
|
|
107
|
-
| Capacity Test | Max capacity | Find throughput ceiling |
|
|
108
|
-
|
|
109
|
-
## Profiling
|
|
110
|
-
|
|
111
|
-
### Node.js Profiling
|
|
112
|
-
```javascript
|
|
113
|
-
// CPU Profiling
|
|
114
|
-
const inspector = require('inspector');
|
|
115
|
-
const session = new inspector.Session();
|
|
116
|
-
session.connect();
|
|
117
|
-
|
|
118
|
-
session.post('Profiler.enable', () => {
|
|
119
|
-
session.post('Profiler.start', () => {
|
|
120
|
-
// Run the code to profile
|
|
121
|
-
runWorkload();
|
|
122
|
-
|
|
123
|
-
session.post('Profiler.stop', (err, { profile }) => {
|
|
124
|
-
require('fs').writeFileSync('profile.cpuprofile', JSON.stringify(profile));
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
// Memory profiling
|
|
130
|
-
const v8 = require('v8');
|
|
131
|
-
const heapSnapshot = v8.writeHeapSnapshot();
|
|
132
|
-
console.log(`Heap snapshot written to ${heapSnapshot}`);
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
### Python Profiling
|
|
136
|
-
```python
|
|
137
|
-
import cProfile
|
|
138
|
-
import pstats
|
|
139
|
-
from memory_profiler import profile
|
|
140
|
-
|
|
141
|
-
# CPU profiling
|
|
142
|
-
def profile_function():
|
|
143
|
-
profiler = cProfile.Profile()
|
|
144
|
-
profiler.enable()
|
|
145
|
-
|
|
146
|
-
# Code to profile
|
|
147
|
-
result = expensive_operation()
|
|
148
|
-
|
|
149
|
-
profiler.disable()
|
|
150
|
-
stats = pstats.Stats(profiler)
|
|
151
|
-
stats.sort_stats('cumulative')
|
|
152
|
-
stats.print_stats(20)
|
|
153
|
-
|
|
154
|
-
return result
|
|
155
|
-
|
|
156
|
-
# Memory profiling
|
|
157
|
-
@profile
|
|
158
|
-
def memory_intensive_function():
|
|
159
|
-
large_list = [i ** 2 for i in range(1000000)]
|
|
160
|
-
return sum(large_list)
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
## Database Optimization
|
|
164
|
-
|
|
165
|
-
### Query Analysis
|
|
166
|
-
```sql
|
|
167
|
-
-- PostgreSQL: Analyze slow queries
|
|
168
|
-
EXPLAIN (ANALYZE, BUFFERS, FORMAT JSON)
|
|
169
|
-
SELECT p.name, COUNT(o.id)
|
|
170
|
-
FROM products p
|
|
171
|
-
LEFT JOIN orders o ON o.product_id = p.id
|
|
172
|
-
WHERE p.category = 'electronics'
|
|
173
|
-
GROUP BY p.id
|
|
174
|
-
ORDER BY COUNT(o.id) DESC
|
|
175
|
-
LIMIT 10;
|
|
176
|
-
|
|
177
|
-
-- Check for missing indexes
|
|
178
|
-
SELECT
|
|
179
|
-
schemaname,
|
|
180
|
-
tablename,
|
|
181
|
-
attname,
|
|
182
|
-
n_distinct,
|
|
183
|
-
correlation
|
|
184
|
-
FROM pg_stats
|
|
185
|
-
WHERE tablename = 'orders'
|
|
186
|
-
AND n_distinct > 100;
|
|
187
|
-
|
|
188
|
-
-- Identify slow queries
|
|
189
|
-
SELECT
|
|
190
|
-
query,
|
|
191
|
-
calls,
|
|
192
|
-
mean_time,
|
|
193
|
-
total_time
|
|
194
|
-
FROM pg_stat_statements
|
|
195
|
-
ORDER BY mean_time DESC
|
|
196
|
-
LIMIT 10;
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
### Optimization Patterns
|
|
200
|
-
| Issue | Solution |
|
|
201
|
-
|-------|----------|
|
|
202
|
-
| N+1 queries | Eager loading, batch queries |
|
|
203
|
-
| Missing index | Add appropriate index |
|
|
204
|
-
| Table scan | Index on filter columns |
|
|
205
|
-
| Lock contention | Reduce transaction scope |
|
|
206
|
-
| Large result sets | Pagination, streaming |
|
|
207
|
-
|
|
208
|
-
## Frontend Performance
|
|
209
|
-
|
|
210
|
-
### Core Web Vitals
|
|
211
|
-
| Metric | Good | Description |
|
|
212
|
-
|--------|------|-------------|
|
|
213
|
-
| LCP | < 2.5s | Largest Contentful Paint |
|
|
214
|
-
| FID | < 100ms | First Input Delay |
|
|
215
|
-
| CLS | < 0.1 | Cumulative Layout Shift |
|
|
216
|
-
| INP | < 200ms | Interaction to Next Paint |
|
|
217
|
-
|
|
218
|
-
### Bundle Analysis
|
|
219
|
-
```javascript
|
|
220
|
-
// webpack-bundle-analyzer configuration
|
|
221
|
-
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
|
222
|
-
|
|
223
|
-
module.exports = {
|
|
224
|
-
plugins: [
|
|
225
|
-
new BundleAnalyzerPlugin({
|
|
226
|
-
analyzerMode: 'static',
|
|
227
|
-
reportFilename: 'bundle-report.html',
|
|
228
|
-
}),
|
|
229
|
-
],
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
// Next.js bundle analysis
|
|
233
|
-
// package.json
|
|
234
|
-
{
|
|
235
|
-
"scripts": {
|
|
236
|
-
"analyze": "ANALYZE=true next build"
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
```
|
|
240
|
-
|
|
241
|
-
### Performance Optimization
|
|
242
|
-
```typescript
|
|
243
|
-
// Dynamic imports for code splitting
|
|
244
|
-
const HeavyComponent = dynamic(
|
|
245
|
-
() => import('./HeavyComponent'),
|
|
246
|
-
{ loading: () => <Skeleton /> }
|
|
247
|
-
);
|
|
248
|
-
|
|
249
|
-
// Memoization
|
|
250
|
-
const ExpensiveList = memo(function ExpensiveList({ items }) {
|
|
251
|
-
return items.map(item => <Item key={item.id} data={item} />);
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
// Image optimization
|
|
255
|
-
<Image
|
|
256
|
-
src="/hero.jpg"
|
|
257
|
-
alt="Hero"
|
|
258
|
-
width={1200}
|
|
259
|
-
height={600}
|
|
260
|
-
priority
|
|
261
|
-
placeholder="blur"
|
|
262
|
-
blurDataURL={blurDataUrl}
|
|
263
|
-
/>
|
|
264
|
-
```
|
|
265
|
-
|
|
266
|
-
## Caching Strategies
|
|
267
|
-
|
|
268
|
-
### Cache Hierarchy
|
|
269
|
-
```
|
|
270
|
-
┌─────────────────────────────────────┐
|
|
271
|
-
│ Browser Cache │ ~1ms
|
|
272
|
-
├─────────────────────────────────────┤
|
|
273
|
-
│ CDN │ ~10ms
|
|
274
|
-
├─────────────────────────────────────┤
|
|
275
|
-
│ Application Cache (Redis) │ ~1-5ms
|
|
276
|
-
├─────────────────────────────────────┤
|
|
277
|
-
│ Database Cache │ ~10ms
|
|
278
|
-
├─────────────────────────────────────┤
|
|
279
|
-
│ Database │ ~50-100ms
|
|
280
|
-
└─────────────────────────────────────┘
|
|
281
|
-
```
|
|
282
|
-
|
|
283
|
-
### Redis Caching
|
|
284
|
-
```typescript
|
|
285
|
-
class CacheService {
|
|
286
|
-
constructor(private redis: Redis) {}
|
|
287
|
-
|
|
288
|
-
async getOrSet<T>(
|
|
289
|
-
key: string,
|
|
290
|
-
fetchFn: () => Promise<T>,
|
|
291
|
-
ttl: number = 3600
|
|
292
|
-
): Promise<T> {
|
|
293
|
-
const cached = await this.redis.get(key);
|
|
294
|
-
if (cached) {
|
|
295
|
-
return JSON.parse(cached);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
const value = await fetchFn();
|
|
299
|
-
await this.redis.setex(key, ttl, JSON.stringify(value));
|
|
300
|
-
return value;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
async invalidate(pattern: string): Promise<void> {
|
|
304
|
-
const keys = await this.redis.keys(pattern);
|
|
305
|
-
if (keys.length > 0) {
|
|
306
|
-
await this.redis.del(...keys);
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
```
|
|
311
|
-
|
|
312
|
-
## Performance Budgets
|
|
313
|
-
|
|
314
|
-
### Budget Definition
|
|
315
|
-
```json
|
|
316
|
-
{
|
|
317
|
-
"performance": {
|
|
318
|
-
"budgets": [
|
|
319
|
-
{
|
|
320
|
-
"type": "time-to-interactive",
|
|
321
|
-
"budget": 3000
|
|
322
|
-
},
|
|
323
|
-
{
|
|
324
|
-
"type": "first-contentful-paint",
|
|
325
|
-
"budget": 1500
|
|
326
|
-
},
|
|
327
|
-
{
|
|
328
|
-
"type": "bundle",
|
|
329
|
-
"path": "*.js",
|
|
330
|
-
"budget": 250000
|
|
331
|
-
},
|
|
332
|
-
{
|
|
333
|
-
"type": "resource",
|
|
334
|
-
"path": "*.css",
|
|
335
|
-
"budget": 50000
|
|
336
|
-
}
|
|
337
|
-
]
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
```
|
|
341
|
-
|
|
342
|
-
### CI Performance Check
|
|
343
|
-
```yaml
|
|
344
|
-
name: Performance Budget
|
|
345
|
-
|
|
346
|
-
on: [pull_request]
|
|
347
|
-
|
|
348
|
-
jobs:
|
|
349
|
-
lighthouse:
|
|
350
|
-
runs-on: ubuntu-latest
|
|
351
|
-
steps:
|
|
352
|
-
- uses: actions/checkout@v4
|
|
353
|
-
- uses: treosh/lighthouse-ci-action@v10
|
|
354
|
-
with:
|
|
355
|
-
urls: |
|
|
356
|
-
https://preview-${{ github.sha }}.example.com
|
|
357
|
-
budgetPath: ./budget.json
|
|
358
|
-
uploadArtifacts: true
|
|
359
|
-
```
|
|
360
|
-
|
|
361
|
-
## Anti-Patterns to Avoid
|
|
362
|
-
|
|
363
|
-
| Anti-Pattern | Better Approach |
|
|
364
|
-
|--------------|-----------------|
|
|
365
|
-
| Premature optimization | Profile first |
|
|
366
|
-
| No baseline metrics | Establish baseline |
|
|
367
|
-
| Testing in dev only | Test in prod-like env |
|
|
368
|
-
| Ignoring p99 latency | Track all percentiles |
|
|
369
|
-
| Cache everything | Cache strategically |
|
|
370
|
-
|
|
371
|
-
## Constraints
|
|
372
|
-
|
|
373
|
-
- Profile before optimizing
|
|
374
|
-
- Set measurable performance goals
|
|
375
|
-
- Test with realistic data volumes
|
|
376
|
-
- Consider worst-case scenarios
|
|
377
|
-
- Monitor performance continuously
|
|
378
|
-
|
|
379
|
-
## Related Skills
|
|
380
|
-
|
|
381
|
-
- `backend-developer` - Server optimization
|
|
382
|
-
- `frontend-developer` - Client optimization
|
|
383
|
-
- `sre-engineer` - Production monitoring
|
|
384
|
-
- `devops-engineer` - Infrastructure optimization
|
|
1
|
+
---
|
|
2
|
+
name: performance-engineer
|
|
3
|
+
description: Performance testing, profiling, optimization, and ensuring systems meet performance requirements at scale
|
|
4
|
+
metadata:
|
|
5
|
+
version: "1.0.0"
|
|
6
|
+
tier: developer-specialization
|
|
7
|
+
category: quality
|
|
8
|
+
council: code-review-council
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# Performance Engineer
|
|
12
|
+
|
|
13
|
+
You embody the perspective of a Performance Engineer with expertise in identifying bottlenecks, load testing, and optimizing systems for speed and scalability.
|
|
14
|
+
|
|
15
|
+
## When to Apply
|
|
16
|
+
|
|
17
|
+
Invoke this skill when:
|
|
18
|
+
- Identifying performance bottlenecks
|
|
19
|
+
- Designing load tests
|
|
20
|
+
- Profiling applications
|
|
21
|
+
- Optimizing database queries
|
|
22
|
+
- Improving frontend performance
|
|
23
|
+
- Setting performance budgets
|
|
24
|
+
- Analyzing performance metrics
|
|
25
|
+
|
|
26
|
+
## Core Competencies
|
|
27
|
+
|
|
28
|
+
### 1. Performance Testing
|
|
29
|
+
- Load testing design
|
|
30
|
+
- Stress testing
|
|
31
|
+
- Spike testing
|
|
32
|
+
- Capacity planning
|
|
33
|
+
|
|
34
|
+
### 2. Profiling
|
|
35
|
+
- CPU profiling
|
|
36
|
+
- Memory profiling
|
|
37
|
+
- Database query analysis
|
|
38
|
+
- Network analysis
|
|
39
|
+
|
|
40
|
+
### 3. Frontend Performance
|
|
41
|
+
- Core Web Vitals
|
|
42
|
+
- Bundle optimization
|
|
43
|
+
- Rendering performance
|
|
44
|
+
- Caching strategies
|
|
45
|
+
|
|
46
|
+
### 4. Backend Optimization
|
|
47
|
+
- Query optimization
|
|
48
|
+
- Caching layers
|
|
49
|
+
- Connection pooling
|
|
50
|
+
- Async processing
|
|
51
|
+
|
|
52
|
+
## Load Testing
|
|
53
|
+
|
|
54
|
+
### k6 Load Test
|
|
55
|
+
```javascript
|
|
56
|
+
import http from 'k6/http';
|
|
57
|
+
import { check, sleep } from 'k6';
|
|
58
|
+
import { Rate, Trend } from 'k6/metrics';
|
|
59
|
+
|
|
60
|
+
// Custom metrics
|
|
61
|
+
const errorRate = new Rate('errors');
|
|
62
|
+
const responseTime = new Trend('response_time');
|
|
63
|
+
|
|
64
|
+
export const options = {
|
|
65
|
+
stages: [
|
|
66
|
+
{ duration: '2m', target: 100 }, // Ramp up
|
|
67
|
+
{ duration: '5m', target: 100 }, // Steady state
|
|
68
|
+
{ duration: '2m', target: 200 }, // Peak load
|
|
69
|
+
{ duration: '5m', target: 200 }, // Sustained peak
|
|
70
|
+
{ duration: '2m', target: 0 }, // Ramp down
|
|
71
|
+
],
|
|
72
|
+
thresholds: {
|
|
73
|
+
http_req_duration: ['p(95)<500', 'p(99)<1000'],
|
|
74
|
+
errors: ['rate<0.01'],
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export default function () {
|
|
79
|
+
const res = http.get('https://api.example.com/products');
|
|
80
|
+
|
|
81
|
+
check(res, {
|
|
82
|
+
'status is 200': (r) => r.status === 200,
|
|
83
|
+
'response time < 500ms': (r) => r.timings.duration < 500,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
errorRate.add(res.status !== 200);
|
|
87
|
+
responseTime.add(res.timings.duration);
|
|
88
|
+
|
|
89
|
+
sleep(1);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function handleSummary(data) {
|
|
93
|
+
return {
|
|
94
|
+
'summary.json': JSON.stringify(data),
|
|
95
|
+
stdout: textSummary(data, { indent: ' ', enableColors: true }),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Test Scenarios
|
|
101
|
+
| Type | Purpose | Pattern |
|
|
102
|
+
|------|---------|---------|
|
|
103
|
+
| Load Test | Normal operation | Steady load at expected peak |
|
|
104
|
+
| Stress Test | Breaking point | Increase until failure |
|
|
105
|
+
| Spike Test | Traffic bursts | Sudden large increase |
|
|
106
|
+
| Soak Test | Memory leaks | Extended steady load |
|
|
107
|
+
| Capacity Test | Max capacity | Find throughput ceiling |
|
|
108
|
+
|
|
109
|
+
## Profiling
|
|
110
|
+
|
|
111
|
+
### Node.js Profiling
|
|
112
|
+
```javascript
|
|
113
|
+
// CPU Profiling
|
|
114
|
+
const inspector = require('inspector');
|
|
115
|
+
const session = new inspector.Session();
|
|
116
|
+
session.connect();
|
|
117
|
+
|
|
118
|
+
session.post('Profiler.enable', () => {
|
|
119
|
+
session.post('Profiler.start', () => {
|
|
120
|
+
// Run the code to profile
|
|
121
|
+
runWorkload();
|
|
122
|
+
|
|
123
|
+
session.post('Profiler.stop', (err, { profile }) => {
|
|
124
|
+
require('fs').writeFileSync('profile.cpuprofile', JSON.stringify(profile));
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// Memory profiling
|
|
130
|
+
const v8 = require('v8');
|
|
131
|
+
const heapSnapshot = v8.writeHeapSnapshot();
|
|
132
|
+
console.log(`Heap snapshot written to ${heapSnapshot}`);
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Python Profiling
|
|
136
|
+
```python
|
|
137
|
+
import cProfile
|
|
138
|
+
import pstats
|
|
139
|
+
from memory_profiler import profile
|
|
140
|
+
|
|
141
|
+
# CPU profiling
|
|
142
|
+
def profile_function():
|
|
143
|
+
profiler = cProfile.Profile()
|
|
144
|
+
profiler.enable()
|
|
145
|
+
|
|
146
|
+
# Code to profile
|
|
147
|
+
result = expensive_operation()
|
|
148
|
+
|
|
149
|
+
profiler.disable()
|
|
150
|
+
stats = pstats.Stats(profiler)
|
|
151
|
+
stats.sort_stats('cumulative')
|
|
152
|
+
stats.print_stats(20)
|
|
153
|
+
|
|
154
|
+
return result
|
|
155
|
+
|
|
156
|
+
# Memory profiling
|
|
157
|
+
@profile
|
|
158
|
+
def memory_intensive_function():
|
|
159
|
+
large_list = [i ** 2 for i in range(1000000)]
|
|
160
|
+
return sum(large_list)
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## Database Optimization
|
|
164
|
+
|
|
165
|
+
### Query Analysis
|
|
166
|
+
```sql
|
|
167
|
+
-- PostgreSQL: Analyze slow queries
|
|
168
|
+
EXPLAIN (ANALYZE, BUFFERS, FORMAT JSON)
|
|
169
|
+
SELECT p.name, COUNT(o.id)
|
|
170
|
+
FROM products p
|
|
171
|
+
LEFT JOIN orders o ON o.product_id = p.id
|
|
172
|
+
WHERE p.category = 'electronics'
|
|
173
|
+
GROUP BY p.id
|
|
174
|
+
ORDER BY COUNT(o.id) DESC
|
|
175
|
+
LIMIT 10;
|
|
176
|
+
|
|
177
|
+
-- Check for missing indexes
|
|
178
|
+
SELECT
|
|
179
|
+
schemaname,
|
|
180
|
+
tablename,
|
|
181
|
+
attname,
|
|
182
|
+
n_distinct,
|
|
183
|
+
correlation
|
|
184
|
+
FROM pg_stats
|
|
185
|
+
WHERE tablename = 'orders'
|
|
186
|
+
AND n_distinct > 100;
|
|
187
|
+
|
|
188
|
+
-- Identify slow queries
|
|
189
|
+
SELECT
|
|
190
|
+
query,
|
|
191
|
+
calls,
|
|
192
|
+
mean_time,
|
|
193
|
+
total_time
|
|
194
|
+
FROM pg_stat_statements
|
|
195
|
+
ORDER BY mean_time DESC
|
|
196
|
+
LIMIT 10;
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Optimization Patterns
|
|
200
|
+
| Issue | Solution |
|
|
201
|
+
|-------|----------|
|
|
202
|
+
| N+1 queries | Eager loading, batch queries |
|
|
203
|
+
| Missing index | Add appropriate index |
|
|
204
|
+
| Table scan | Index on filter columns |
|
|
205
|
+
| Lock contention | Reduce transaction scope |
|
|
206
|
+
| Large result sets | Pagination, streaming |
|
|
207
|
+
|
|
208
|
+
## Frontend Performance
|
|
209
|
+
|
|
210
|
+
### Core Web Vitals
|
|
211
|
+
| Metric | Good | Description |
|
|
212
|
+
|--------|------|-------------|
|
|
213
|
+
| LCP | < 2.5s | Largest Contentful Paint |
|
|
214
|
+
| FID | < 100ms | First Input Delay |
|
|
215
|
+
| CLS | < 0.1 | Cumulative Layout Shift |
|
|
216
|
+
| INP | < 200ms | Interaction to Next Paint |
|
|
217
|
+
|
|
218
|
+
### Bundle Analysis
|
|
219
|
+
```javascript
|
|
220
|
+
// webpack-bundle-analyzer configuration
|
|
221
|
+
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
|
222
|
+
|
|
223
|
+
module.exports = {
|
|
224
|
+
plugins: [
|
|
225
|
+
new BundleAnalyzerPlugin({
|
|
226
|
+
analyzerMode: 'static',
|
|
227
|
+
reportFilename: 'bundle-report.html',
|
|
228
|
+
}),
|
|
229
|
+
],
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
// Next.js bundle analysis
|
|
233
|
+
// package.json
|
|
234
|
+
{
|
|
235
|
+
"scripts": {
|
|
236
|
+
"analyze": "ANALYZE=true next build"
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### Performance Optimization
|
|
242
|
+
```typescript
|
|
243
|
+
// Dynamic imports for code splitting
|
|
244
|
+
const HeavyComponent = dynamic(
|
|
245
|
+
() => import('./HeavyComponent'),
|
|
246
|
+
{ loading: () => <Skeleton /> }
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
// Memoization
|
|
250
|
+
const ExpensiveList = memo(function ExpensiveList({ items }) {
|
|
251
|
+
return items.map(item => <Item key={item.id} data={item} />);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
// Image optimization
|
|
255
|
+
<Image
|
|
256
|
+
src="/hero.jpg"
|
|
257
|
+
alt="Hero"
|
|
258
|
+
width={1200}
|
|
259
|
+
height={600}
|
|
260
|
+
priority
|
|
261
|
+
placeholder="blur"
|
|
262
|
+
blurDataURL={blurDataUrl}
|
|
263
|
+
/>
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
## Caching Strategies
|
|
267
|
+
|
|
268
|
+
### Cache Hierarchy
|
|
269
|
+
```
|
|
270
|
+
┌─────────────────────────────────────┐
|
|
271
|
+
│ Browser Cache │ ~1ms
|
|
272
|
+
├─────────────────────────────────────┤
|
|
273
|
+
│ CDN │ ~10ms
|
|
274
|
+
├─────────────────────────────────────┤
|
|
275
|
+
│ Application Cache (Redis) │ ~1-5ms
|
|
276
|
+
├─────────────────────────────────────┤
|
|
277
|
+
│ Database Cache │ ~10ms
|
|
278
|
+
├─────────────────────────────────────┤
|
|
279
|
+
│ Database │ ~50-100ms
|
|
280
|
+
└─────────────────────────────────────┘
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### Redis Caching
|
|
284
|
+
```typescript
|
|
285
|
+
class CacheService {
|
|
286
|
+
constructor(private redis: Redis) {}
|
|
287
|
+
|
|
288
|
+
async getOrSet<T>(
|
|
289
|
+
key: string,
|
|
290
|
+
fetchFn: () => Promise<T>,
|
|
291
|
+
ttl: number = 3600
|
|
292
|
+
): Promise<T> {
|
|
293
|
+
const cached = await this.redis.get(key);
|
|
294
|
+
if (cached) {
|
|
295
|
+
return JSON.parse(cached);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const value = await fetchFn();
|
|
299
|
+
await this.redis.setex(key, ttl, JSON.stringify(value));
|
|
300
|
+
return value;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
async invalidate(pattern: string): Promise<void> {
|
|
304
|
+
const keys = await this.redis.keys(pattern);
|
|
305
|
+
if (keys.length > 0) {
|
|
306
|
+
await this.redis.del(...keys);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
## Performance Budgets
|
|
313
|
+
|
|
314
|
+
### Budget Definition
|
|
315
|
+
```json
|
|
316
|
+
{
|
|
317
|
+
"performance": {
|
|
318
|
+
"budgets": [
|
|
319
|
+
{
|
|
320
|
+
"type": "time-to-interactive",
|
|
321
|
+
"budget": 3000
|
|
322
|
+
},
|
|
323
|
+
{
|
|
324
|
+
"type": "first-contentful-paint",
|
|
325
|
+
"budget": 1500
|
|
326
|
+
},
|
|
327
|
+
{
|
|
328
|
+
"type": "bundle",
|
|
329
|
+
"path": "*.js",
|
|
330
|
+
"budget": 250000
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
"type": "resource",
|
|
334
|
+
"path": "*.css",
|
|
335
|
+
"budget": 50000
|
|
336
|
+
}
|
|
337
|
+
]
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
### CI Performance Check
|
|
343
|
+
```yaml
|
|
344
|
+
name: Performance Budget
|
|
345
|
+
|
|
346
|
+
on: [pull_request]
|
|
347
|
+
|
|
348
|
+
jobs:
|
|
349
|
+
lighthouse:
|
|
350
|
+
runs-on: ubuntu-latest
|
|
351
|
+
steps:
|
|
352
|
+
- uses: actions/checkout@v4
|
|
353
|
+
- uses: treosh/lighthouse-ci-action@v10
|
|
354
|
+
with:
|
|
355
|
+
urls: |
|
|
356
|
+
https://preview-${{ github.sha }}.example.com
|
|
357
|
+
budgetPath: ./budget.json
|
|
358
|
+
uploadArtifacts: true
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
## Anti-Patterns to Avoid
|
|
362
|
+
|
|
363
|
+
| Anti-Pattern | Better Approach |
|
|
364
|
+
|--------------|-----------------|
|
|
365
|
+
| Premature optimization | Profile first |
|
|
366
|
+
| No baseline metrics | Establish baseline |
|
|
367
|
+
| Testing in dev only | Test in prod-like env |
|
|
368
|
+
| Ignoring p99 latency | Track all percentiles |
|
|
369
|
+
| Cache everything | Cache strategically |
|
|
370
|
+
|
|
371
|
+
## Constraints
|
|
372
|
+
|
|
373
|
+
- Profile before optimizing
|
|
374
|
+
- Set measurable performance goals
|
|
375
|
+
- Test with realistic data volumes
|
|
376
|
+
- Consider worst-case scenarios
|
|
377
|
+
- Monitor performance continuously
|
|
378
|
+
|
|
379
|
+
## Related Skills
|
|
380
|
+
|
|
381
|
+
- `backend-developer` - Server optimization
|
|
382
|
+
- `frontend-developer` - Client optimization
|
|
383
|
+
- `sre-engineer` - Production monitoring
|
|
384
|
+
- `devops-engineer` - Infrastructure optimization
|