opencode-metis 0.1.0

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.
Files changed (156) hide show
  1. package/README.md +140 -0
  2. package/dist/cli.cjs +63 -0
  3. package/dist/mcp-server.cjs +51 -0
  4. package/dist/plugin.cjs +4 -0
  5. package/dist/worker.cjs +224 -0
  6. package/opencode/agent/the-analyst/feature-prioritization.md +66 -0
  7. package/opencode/agent/the-analyst/market-research.md +77 -0
  8. package/opencode/agent/the-analyst/project-coordination.md +81 -0
  9. package/opencode/agent/the-analyst/requirements-analysis.md +77 -0
  10. package/opencode/agent/the-architect/compatibility-review.md +138 -0
  11. package/opencode/agent/the-architect/complexity-review.md +137 -0
  12. package/opencode/agent/the-architect/quality-review.md +67 -0
  13. package/opencode/agent/the-architect/security-review.md +127 -0
  14. package/opencode/agent/the-architect/system-architecture.md +119 -0
  15. package/opencode/agent/the-architect/system-documentation.md +83 -0
  16. package/opencode/agent/the-architect/technology-research.md +85 -0
  17. package/opencode/agent/the-chief.md +79 -0
  18. package/opencode/agent/the-designer/accessibility-implementation.md +101 -0
  19. package/opencode/agent/the-designer/design-foundation.md +74 -0
  20. package/opencode/agent/the-designer/interaction-architecture.md +75 -0
  21. package/opencode/agent/the-designer/user-research.md +70 -0
  22. package/opencode/agent/the-meta-agent.md +155 -0
  23. package/opencode/agent/the-platform-engineer/ci-cd-pipelines.md +109 -0
  24. package/opencode/agent/the-platform-engineer/containerization.md +106 -0
  25. package/opencode/agent/the-platform-engineer/data-architecture.md +81 -0
  26. package/opencode/agent/the-platform-engineer/dependency-review.md +144 -0
  27. package/opencode/agent/the-platform-engineer/deployment-automation.md +81 -0
  28. package/opencode/agent/the-platform-engineer/infrastructure-as-code.md +107 -0
  29. package/opencode/agent/the-platform-engineer/performance-tuning.md +82 -0
  30. package/opencode/agent/the-platform-engineer/pipeline-engineering.md +81 -0
  31. package/opencode/agent/the-platform-engineer/production-monitoring.md +105 -0
  32. package/opencode/agent/the-qa-engineer/exploratory-testing.md +66 -0
  33. package/opencode/agent/the-qa-engineer/performance-testing.md +81 -0
  34. package/opencode/agent/the-qa-engineer/quality-assurance.md +77 -0
  35. package/opencode/agent/the-qa-engineer/test-execution.md +66 -0
  36. package/opencode/agent/the-software-engineer/api-development.md +78 -0
  37. package/opencode/agent/the-software-engineer/component-development.md +79 -0
  38. package/opencode/agent/the-software-engineer/concurrency-review.md +141 -0
  39. package/opencode/agent/the-software-engineer/domain-modeling.md +66 -0
  40. package/opencode/agent/the-software-engineer/performance-optimization.md +113 -0
  41. package/opencode/command/analyze.md +149 -0
  42. package/opencode/command/constitution.md +178 -0
  43. package/opencode/command/debug.md +194 -0
  44. package/opencode/command/document.md +178 -0
  45. package/opencode/command/implement.md +225 -0
  46. package/opencode/command/refactor.md +207 -0
  47. package/opencode/command/review.md +229 -0
  48. package/opencode/command/simplify.md +267 -0
  49. package/opencode/command/specify.md +191 -0
  50. package/opencode/command/validate.md +224 -0
  51. package/opencode/skill/accessibility-design/SKILL.md +566 -0
  52. package/opencode/skill/accessibility-design/checklists/wcag-checklist.md +435 -0
  53. package/opencode/skill/agent-coordination/SKILL.md +224 -0
  54. package/opencode/skill/api-contract-design/SKILL.md +550 -0
  55. package/opencode/skill/api-contract-design/templates/graphql-schema-template.md +818 -0
  56. package/opencode/skill/api-contract-design/templates/rest-api-template.md +417 -0
  57. package/opencode/skill/architecture-design/SKILL.md +160 -0
  58. package/opencode/skill/architecture-design/examples/architecture-examples.md +170 -0
  59. package/opencode/skill/architecture-design/template.md +749 -0
  60. package/opencode/skill/architecture-design/validation.md +99 -0
  61. package/opencode/skill/architecture-selection/SKILL.md +522 -0
  62. package/opencode/skill/architecture-selection/examples/adrs/001-example-adr.md +71 -0
  63. package/opencode/skill/architecture-selection/examples/architecture-patterns.md +239 -0
  64. package/opencode/skill/bug-diagnosis/SKILL.md +235 -0
  65. package/opencode/skill/code-quality-review/SKILL.md +337 -0
  66. package/opencode/skill/code-quality-review/examples/anti-patterns.md +629 -0
  67. package/opencode/skill/code-quality-review/reference.md +322 -0
  68. package/opencode/skill/code-review/SKILL.md +363 -0
  69. package/opencode/skill/code-review/reference.md +450 -0
  70. package/opencode/skill/codebase-analysis/SKILL.md +139 -0
  71. package/opencode/skill/codebase-navigation/SKILL.md +227 -0
  72. package/opencode/skill/codebase-navigation/examples/exploration-patterns.md +263 -0
  73. package/opencode/skill/coding-conventions/SKILL.md +178 -0
  74. package/opencode/skill/coding-conventions/checklists/accessibility-checklist.md +176 -0
  75. package/opencode/skill/coding-conventions/checklists/performance-checklist.md +154 -0
  76. package/opencode/skill/coding-conventions/checklists/security-checklist.md +127 -0
  77. package/opencode/skill/constitution-validation/SKILL.md +315 -0
  78. package/opencode/skill/constitution-validation/examples/CONSTITUTION.md +202 -0
  79. package/opencode/skill/constitution-validation/reference/rule-patterns.md +328 -0
  80. package/opencode/skill/constitution-validation/template.md +115 -0
  81. package/opencode/skill/context-preservation/SKILL.md +445 -0
  82. package/opencode/skill/data-modeling/SKILL.md +385 -0
  83. package/opencode/skill/data-modeling/templates/schema-design-template.md +268 -0
  84. package/opencode/skill/deployment-pipeline-design/SKILL.md +579 -0
  85. package/opencode/skill/deployment-pipeline-design/templates/pipeline-template.md +633 -0
  86. package/opencode/skill/documentation-extraction/SKILL.md +259 -0
  87. package/opencode/skill/documentation-sync/SKILL.md +431 -0
  88. package/opencode/skill/domain-driven-design/SKILL.md +509 -0
  89. package/opencode/skill/domain-driven-design/examples/ddd-patterns.md +688 -0
  90. package/opencode/skill/domain-driven-design/reference.md +465 -0
  91. package/opencode/skill/drift-detection/SKILL.md +383 -0
  92. package/opencode/skill/drift-detection/reference.md +340 -0
  93. package/opencode/skill/error-recovery/SKILL.md +162 -0
  94. package/opencode/skill/error-recovery/examples/error-patterns.md +484 -0
  95. package/opencode/skill/feature-prioritization/SKILL.md +419 -0
  96. package/opencode/skill/feature-prioritization/examples/rice-template.md +139 -0
  97. package/opencode/skill/feature-prioritization/reference.md +256 -0
  98. package/opencode/skill/git-workflow/SKILL.md +453 -0
  99. package/opencode/skill/implementation-planning/SKILL.md +215 -0
  100. package/opencode/skill/implementation-planning/examples/phase-examples.md +217 -0
  101. package/opencode/skill/implementation-planning/template.md +220 -0
  102. package/opencode/skill/implementation-planning/validation.md +88 -0
  103. package/opencode/skill/implementation-verification/SKILL.md +272 -0
  104. package/opencode/skill/knowledge-capture/SKILL.md +265 -0
  105. package/opencode/skill/knowledge-capture/reference/knowledge-capture.md +402 -0
  106. package/opencode/skill/knowledge-capture/reference.md +444 -0
  107. package/opencode/skill/knowledge-capture/templates/domain-template.md +325 -0
  108. package/opencode/skill/knowledge-capture/templates/interface-template.md +255 -0
  109. package/opencode/skill/knowledge-capture/templates/pattern-template.md +144 -0
  110. package/opencode/skill/observability-design/SKILL.md +291 -0
  111. package/opencode/skill/observability-design/references/monitoring-patterns.md +461 -0
  112. package/opencode/skill/pattern-detection/SKILL.md +171 -0
  113. package/opencode/skill/pattern-detection/examples/common-patterns.md +359 -0
  114. package/opencode/skill/performance-analysis/SKILL.md +266 -0
  115. package/opencode/skill/performance-analysis/references/profiling-tools.md +499 -0
  116. package/opencode/skill/requirements-analysis/SKILL.md +139 -0
  117. package/opencode/skill/requirements-analysis/examples/good-prd.md +66 -0
  118. package/opencode/skill/requirements-analysis/template.md +177 -0
  119. package/opencode/skill/requirements-analysis/validation.md +69 -0
  120. package/opencode/skill/requirements-elicitation/SKILL.md +518 -0
  121. package/opencode/skill/requirements-elicitation/examples/interview-questions.md +226 -0
  122. package/opencode/skill/requirements-elicitation/examples/user-stories.md +414 -0
  123. package/opencode/skill/safe-refactoring/SKILL.md +312 -0
  124. package/opencode/skill/safe-refactoring/reference/code-smells.md +347 -0
  125. package/opencode/skill/security-assessment/SKILL.md +421 -0
  126. package/opencode/skill/security-assessment/checklists/security-review-checklist.md +285 -0
  127. package/opencode/skill/specification-management/SKILL.md +143 -0
  128. package/opencode/skill/specification-management/readme-template.md +32 -0
  129. package/opencode/skill/specification-management/reference.md +115 -0
  130. package/opencode/skill/specification-management/spec.py +229 -0
  131. package/opencode/skill/specification-validation/SKILL.md +397 -0
  132. package/opencode/skill/specification-validation/reference/3cs-framework.md +306 -0
  133. package/opencode/skill/specification-validation/reference/ambiguity-detection.md +132 -0
  134. package/opencode/skill/specification-validation/reference/constitution-validation.md +301 -0
  135. package/opencode/skill/specification-validation/reference/drift-detection.md +383 -0
  136. package/opencode/skill/task-delegation/SKILL.md +607 -0
  137. package/opencode/skill/task-delegation/examples/file-coordination.md +495 -0
  138. package/opencode/skill/task-delegation/examples/parallel-research.md +337 -0
  139. package/opencode/skill/task-delegation/examples/sequential-build.md +504 -0
  140. package/opencode/skill/task-delegation/reference.md +825 -0
  141. package/opencode/skill/tech-stack-detection/SKILL.md +89 -0
  142. package/opencode/skill/tech-stack-detection/references/framework-signatures.md +598 -0
  143. package/opencode/skill/technical-writing/SKILL.md +190 -0
  144. package/opencode/skill/technical-writing/templates/adr-template.md +205 -0
  145. package/opencode/skill/technical-writing/templates/system-doc-template.md +380 -0
  146. package/opencode/skill/test-design/SKILL.md +464 -0
  147. package/opencode/skill/test-design/examples/test-pyramid.md +724 -0
  148. package/opencode/skill/testing/SKILL.md +213 -0
  149. package/opencode/skill/testing/examples/test-pyramid.md +724 -0
  150. package/opencode/skill/user-insight-synthesis/SKILL.md +576 -0
  151. package/opencode/skill/user-insight-synthesis/templates/research-plan-template.md +217 -0
  152. package/opencode/skill/user-research/SKILL.md +508 -0
  153. package/opencode/skill/user-research/examples/interview-questions.md +265 -0
  154. package/opencode/skill/user-research/examples/personas.md +267 -0
  155. package/opencode/skill/vibe-security/SKILL.md +654 -0
  156. package/package.json +45 -0
@@ -0,0 +1,359 @@
1
+ # Common Pattern Recognition Examples
2
+
3
+ ## Context
4
+
5
+ This document provides concrete examples of how to recognize and apply patterns in real codebases. Use these examples as reference when analyzing unfamiliar projects.
6
+
7
+ ## Example 1: React Component Naming Patterns
8
+
9
+ ### Pattern Discovery
10
+
11
+ When encountering a React codebase, examine existing components:
12
+
13
+ ```
14
+ src/components/
15
+ Button.tsx # PascalCase filename
16
+ UserProfile.tsx # Multi-word PascalCase
17
+ user-profile.css # kebab-case for styles
18
+ ```
19
+
20
+ ### Pattern Recognition
21
+
22
+ From these files, recognize:
23
+ - Component files use PascalCase
24
+ - Style files use kebab-case matching component name
25
+ - Co-located styles with components
26
+
27
+ ### Pattern Application
28
+
29
+ When creating a new component:
30
+ ```
31
+ # CORRECT - follows pattern
32
+ src/components/
33
+ OrderSummary.tsx
34
+ order-summary.css
35
+
36
+ # INCORRECT - violates pattern
37
+ src/components/
38
+ orderSummary.tsx # Wrong: camelCase
39
+ OrderSummary.styles.ts # Wrong: different style file convention
40
+ ```
41
+
42
+ ## Example 2: Python Function Naming
43
+
44
+ ### Pattern Discovery
45
+
46
+ Survey existing functions:
47
+
48
+ ```python
49
+ # Found in existing codebase
50
+ def get_user_by_id(user_id: int) -> User:
51
+ ...
52
+
53
+ def create_order(items: list[Item]) -> Order:
54
+ ...
55
+
56
+ def update_inventory_count(product_id: int, delta: int) -> None:
57
+ ...
58
+ ```
59
+
60
+ ### Pattern Recognition
61
+
62
+ From these functions, recognize:
63
+ - snake_case for function names
64
+ - get/create/update verb prefixes
65
+ - Type hints consistently used
66
+ - Descriptive names over abbreviations
67
+
68
+ ### Pattern Application
69
+
70
+ When adding a new function:
71
+ ```python
72
+ # CORRECT - follows pattern
73
+ def delete_user_session(session_id: str) -> bool:
74
+ ...
75
+
76
+ # INCORRECT - violates pattern
77
+ def deleteSession(id): # Wrong: camelCase, abbreviated, no types
78
+ ...
79
+ ```
80
+
81
+ ## Example 3: Test File Organization
82
+
83
+ ### Pattern Discovery
84
+
85
+ Examine test directory structure:
86
+
87
+ ```
88
+ src/
89
+ services/
90
+ UserService.ts
91
+ OrderService.ts
92
+ tests/
93
+ services/
94
+ UserService.test.ts
95
+ OrderService.test.ts
96
+ fixtures/
97
+ users.json
98
+ orders.json
99
+ ```
100
+
101
+ ### Pattern Recognition
102
+
103
+ From this structure, recognize:
104
+ - Tests mirror source directory structure
105
+ - Test files use `.test.ts` suffix
106
+ - Shared fixtures in dedicated directory
107
+ - Test filename matches source filename
108
+
109
+ ### Pattern Application
110
+
111
+ When adding tests for a new service:
112
+ ```
113
+ # CORRECT - follows pattern
114
+ src/services/PaymentService.ts
115
+ tests/services/PaymentService.test.ts
116
+ tests/fixtures/payments.json
117
+
118
+ # INCORRECT - violates pattern
119
+ src/services/PaymentService.ts
120
+ src/services/__tests__/payment.spec.ts # Wrong: different structure and naming
121
+ ```
122
+
123
+ ## Example 4: API Endpoint Naming
124
+
125
+ ### Pattern Discovery
126
+
127
+ Review existing API routes:
128
+
129
+ ```typescript
130
+ // Found in existing codebase
131
+ router.get('/users/:userId', getUser);
132
+ router.post('/users', createUser);
133
+ router.put('/users/:userId', updateUser);
134
+ router.delete('/users/:userId', deleteUser);
135
+
136
+ router.get('/orders/:orderId/items', getOrderItems);
137
+ router.post('/orders/:orderId/items', addOrderItem);
138
+ ```
139
+
140
+ ### Pattern Recognition
141
+
142
+ From these routes, recognize:
143
+ - Plural nouns for resources (`users` not `user`)
144
+ - camelCase for path parameters (`userId` not `user_id`)
145
+ - Nested resources use parent path (`orders/:orderId/items`)
146
+ - HTTP methods map to CRUD operations
147
+
148
+ ### Pattern Application
149
+
150
+ When adding a new endpoint:
151
+ ```typescript
152
+ // CORRECT - follows pattern
153
+ router.get('/products/:productId/reviews', getProductReviews);
154
+ router.post('/products/:productId/reviews', createProductReview);
155
+
156
+ // INCORRECT - violates pattern
157
+ router.get('/product/:product_id/review', getReview); # Wrong: singular, snake_case
158
+ ```
159
+
160
+ ## Example 5: Error Handling Patterns
161
+
162
+ ### Pattern Discovery
163
+
164
+ Examine how errors are handled:
165
+
166
+ ```typescript
167
+ // Found in existing codebase
168
+ class NotFoundError extends AppError {
169
+ constructor(resource: string, id: string) {
170
+ super(`${resource} with id ${id} not found`, 404);
171
+ }
172
+ }
173
+
174
+ class ValidationError extends AppError {
175
+ constructor(field: string, message: string) {
176
+ super(`Validation failed for ${field}: ${message}`, 400);
177
+ }
178
+ }
179
+
180
+ // Usage
181
+ if (!user) {
182
+ throw new NotFoundError('User', userId);
183
+ }
184
+ ```
185
+
186
+ ### Pattern Recognition
187
+
188
+ From this code, recognize:
189
+ - Custom error classes extend base `AppError`
190
+ - Error names describe the condition (NotFoundError, ValidationError)
191
+ - Errors include HTTP status codes
192
+ - Constructors accept contextual parameters
193
+ - Error messages are descriptive and include context
194
+
195
+ ### Pattern Application
196
+
197
+ When adding new error handling:
198
+ ```typescript
199
+ // CORRECT - follows pattern
200
+ class ConflictError extends AppError {
201
+ constructor(resource: string, conflictReason: string) {
202
+ super(`${resource} conflict: ${conflictReason}`, 409);
203
+ }
204
+ }
205
+
206
+ // INCORRECT - violates pattern
207
+ throw new Error('conflict'); # Wrong: generic Error, no context, no status
208
+ ```
209
+
210
+ ## Example 6: Configuration Patterns
211
+
212
+ ### Pattern Discovery
213
+
214
+ Review how configuration is structured:
215
+
216
+ ```typescript
217
+ // config/database.ts
218
+ export const databaseConfig = {
219
+ host: process.env.DB_HOST || 'localhost',
220
+ port: parseInt(process.env.DB_PORT || '5432'),
221
+ name: process.env.DB_NAME || 'app_dev',
222
+ };
223
+
224
+ // config/auth.ts
225
+ export const authConfig = {
226
+ jwtSecret: process.env.JWT_SECRET || 'dev-secret',
227
+ tokenExpiry: parseInt(process.env.TOKEN_EXPIRY || '3600'),
228
+ refreshExpiry: parseInt(process.env.REFRESH_EXPIRY || '86400'),
229
+ };
230
+ ```
231
+
232
+ ### Pattern Recognition
233
+
234
+ From these files, recognize:
235
+ - Config split by domain (database, auth)
236
+ - Environment variables with fallback defaults
237
+ - Type coercion for non-string values
238
+ - Exported as named objects
239
+ - Env var naming: SCREAMING_SNAKE_CASE
240
+
241
+ ### Pattern Application
242
+
243
+ When adding new configuration:
244
+ ```typescript
245
+ // config/email.ts - CORRECT
246
+ export const emailConfig = {
247
+ smtpHost: process.env.SMTP_HOST || 'localhost',
248
+ smtpPort: parseInt(process.env.SMTP_PORT || '587'),
249
+ senderAddress: process.env.SENDER_ADDRESS || 'noreply@example.com',
250
+ };
251
+ ```
252
+
253
+ ## Example 7: State Management Patterns
254
+
255
+ ### Pattern Discovery
256
+
257
+ Examine how state is managed:
258
+
259
+ ```typescript
260
+ // store/users/types.ts
261
+ interface UserState {
262
+ items: User[];
263
+ loading: boolean;
264
+ error: string | null;
265
+ }
266
+
267
+ // store/users/actions.ts
268
+ const fetchUsers = createAsyncThunk('users/fetch', async () => {...});
269
+ const updateUser = createAsyncThunk('users/update', async (user: User) => {...});
270
+
271
+ // store/users/slice.ts
272
+ const usersSlice = createSlice({
273
+ name: 'users',
274
+ initialState,
275
+ reducers: {...},
276
+ extraReducers: {...},
277
+ });
278
+ ```
279
+
280
+ ### Pattern Recognition
281
+
282
+ From this code, recognize:
283
+ - Feature-based organization (store/users/)
284
+ - Separate files for types, actions, slice
285
+ - Consistent state shape (items, loading, error)
286
+ - Async thunk naming: `domain/action`
287
+ - Slice naming matches domain
288
+
289
+ ### Pattern Application
290
+
291
+ When adding new state:
292
+ ```
293
+ store/
294
+ orders/
295
+ types.ts # OrderState interface
296
+ actions.ts # fetchOrders, updateOrder thunks
297
+ slice.ts # ordersSlice
298
+ ```
299
+
300
+ ## Variations
301
+
302
+ ### When Patterns Conflict
303
+
304
+ If you find conflicting patterns (e.g., some files use one style, others use another):
305
+
306
+ 1. Check for date/author patterns - newer code may represent intended direction
307
+ 2. Look for documentation or style guides
308
+ 3. Follow the pattern in the specific area you are modifying
309
+ 4. When in doubt, ask the team or document your choice
310
+
311
+ ### When No Clear Pattern Exists
312
+
313
+ If a pattern is not established:
314
+
315
+ 1. Check similar projects in the same ecosystem
316
+ 2. Follow language/framework conventions
317
+ 3. Document the pattern you establish
318
+ 4. Be prepared to refactor if team prefers different approach
319
+
320
+ ## Anti-Patterns
321
+
322
+ ### Mixing Conventions
323
+
324
+ ```typescript
325
+ // WRONG: Mixed naming in same file
326
+ const getUserData = () => {...}; // camelCase verb
327
+ const fetch_user_profile = () => {...}; // snake_case verb
328
+ const retrieveUserInfo = () => {...}; // different verb pattern
329
+ ```
330
+
331
+ ### Inconsistent Organization
332
+
333
+ ```
334
+ // WRONG: Inconsistent test placement
335
+ src/
336
+ UserService.ts
337
+ UserService.test.ts # Co-located
338
+ OrderService.ts
339
+ tests/
340
+ OrderService.test.ts # Separate directory
341
+ ```
342
+
343
+ ### Pattern Drift
344
+
345
+ ```typescript
346
+ // WRONG: Old pattern in new code
347
+ // Existing: Modern async/await
348
+ async function getUser(id) {
349
+ const user = await db.findUser(id);
350
+ return user;
351
+ }
352
+
353
+ // New code using outdated callback pattern
354
+ function getOrder(id, callback) {
355
+ db.findOrder(id, (err, order) => {
356
+ callback(err, order);
357
+ });
358
+ }
359
+ ```
@@ -0,0 +1,266 @@
1
+ ---
2
+ name: performance-analysis
3
+ description: "Measurement approaches, profiling tools, optimization patterns, and capacity planning for diagnosing and resolving performance issues"
4
+ license: MIT
5
+ compatibility: opencode
6
+ metadata:
7
+ category: testing
8
+ version: "1.0"
9
+ ---
10
+
11
+ # Performance Analysis
12
+
13
+ Roleplay as a performance analysis specialist diagnosing bottlenecks, establishing baselines, and validating optimizations through measurement.
14
+
15
+ PerformanceAnalysis {
16
+ Activation {
17
+ Establishing performance baselines before optimization
18
+ Diagnosing slow response times, high CPU, or memory issues
19
+ Identifying bottlenecks in application, database, or infrastructure
20
+ Planning capacity for expected load increases
21
+ Validating performance improvements after optimization
22
+ Creating performance budgets for new features
23
+ }
24
+
25
+ Constraints {
26
+ 1. Before any action, read and internalize:
27
+ - Project CLAUDE.md -- architecture, conventions, priorities
28
+ - CONSTITUTION.md at project root -- if present, constrains all work
29
+ - Existing performance baselines and monitoring -- build on what exists
30
+ 2. Measure before optimizing -- never optimize based on assumptions
31
+ 3. Use percentiles (p95, p99) not averages for latency metrics
32
+ 4. Profile in production-like environments -- development characteristics differ
33
+ 5. Document baseline metrics before making changes
34
+ 6. Focus on the biggest contributors first (Amdahl's Law)
35
+ 7. Validate improvements with before/after measurements
36
+ 8. Never optimize non-bottleneck code prematurely
37
+ 9. Never over-engineer for hypothetical scale -- measure actual needs
38
+ 10. Never cache without an invalidation strategy
39
+ 11. Never ignore tail latencies (p99, p999)
40
+ }
41
+
42
+ OutputSchema {
43
+ ```
44
+ PerformanceFinding:
45
+ id: string # e.g., "C1", "H2"
46
+ title: string # Short finding title
47
+ severity: CRITICAL | HIGH | MEDIUM | LOW
48
+ category: "cpu" | "memory" | "io" | "network" | "query" | "algorithmic" | "capacity"
49
+ location: string # file:line, endpoint, or query
50
+ finding: string # What was measured and found
51
+ baseline: string # Current metric value
52
+ target: string # Expected metric value after fix
53
+ recommendation: string # Specific optimization with approach
54
+ ```
55
+ }
56
+
57
+ BottleneckDecisionTable {
58
+ Evaluate top-to-bottom, first match wins:
59
+
60
+ | Symptom | Bottleneck Type | Investigation Approach |
61
+ |---------|----------------|----------------------|
62
+ | High CPU, low I/O wait | CPU-bound | Profile functions, check algorithms |
63
+ | High memory, GC pressure | Memory-bound | Heap snapshots, allocation tracking |
64
+ | Low CPU, high I/O wait | I/O-bound | Query analysis, network profiling |
65
+ | Low CPU, high wait time | Lock contention | Thread/connection pool analysis |
66
+ | Many small DB queries | N+1 queries | Query log, ORM lazy loading check |
67
+ }
68
+
69
+ CoreMethodology {
70
+ TheGoldenRule {
71
+ Never optimize based on assumptions. Follow this order:
72
+ 1. Measure -- Establish baseline metrics
73
+ 2. Identify -- Find the actual bottleneck
74
+ 3. Hypothesize -- Form a theory about the cause
75
+ 4. Fix -- Implement targeted optimization
76
+ 5. Validate -- Measure again to confirm improvement
77
+ 6. Document -- Record findings and decisions
78
+ }
79
+
80
+ ProfilingHierarchy {
81
+ ```
82
+ Application Level
83
+ |-- Request/Response timing
84
+ |-- Function/Method profiling
85
+ |-- Memory allocation tracking
86
+ |
87
+ System Level
88
+ |-- CPU utilization per process
89
+ |-- Memory usage patterns
90
+ |-- I/O wait times
91
+ |-- Network latency
92
+ |
93
+ Infrastructure Level
94
+ |-- Database query performance
95
+ |-- Cache hit rates
96
+ |-- External service latency
97
+ |-- Resource saturation
98
+ ```
99
+ }
100
+ }
101
+
102
+ ProfilingPatterns {
103
+ CPUProfiling {
104
+ Identify what code consumes CPU time:
105
+ 1. Sampling profilers -- Low overhead, statistical accuracy
106
+ 2. Instrumentation profilers -- Exact counts, higher overhead
107
+ 3. Flame graphs -- Visual representation of call stacks
108
+
109
+ KeyMetrics:
110
+ - Self time (time in function itself)
111
+ - Total time (self time + time in called functions)
112
+ - Call count and frequency
113
+ }
114
+
115
+ MemoryProfiling {
116
+ Track allocation patterns and detect leaks:
117
+ 1. Heap snapshots -- Point-in-time memory state
118
+ 2. Allocation tracking -- What allocates memory and when
119
+ 3. Garbage collection analysis -- GC frequency and duration
120
+
121
+ KeyMetrics:
122
+ - Heap size over time
123
+ - Object retention
124
+ - Allocation rate
125
+ - GC pause times
126
+ }
127
+
128
+ IOProfiling {
129
+ Measure disk and network operations:
130
+ 1. Disk I/O -- Read/write latency, throughput, IOPS
131
+ 2. Network I/O -- Latency, bandwidth, connection count
132
+ 3. Database I/O -- Query time, connection pool usage
133
+
134
+ KeyMetrics:
135
+ - Latency percentiles (p50, p95, p99)
136
+ - Throughput (ops/sec, MB/sec)
137
+ - Queue depth and wait times
138
+ }
139
+ }
140
+
141
+ BottleneckIdentification {
142
+ TheUSEMethod {
143
+ For each resource, check:
144
+ - Utilization -- Percentage of time resource is busy
145
+ - Saturation -- Degree of queued work
146
+ - Errors -- Error count for the resource
147
+ }
148
+
149
+ TheREDMethod {
150
+ For services, measure:
151
+ - Rate -- Requests per second
152
+ - Errors -- Failed requests per second
153
+ - Duration -- Distribution of request latencies
154
+ }
155
+
156
+ CommonBottleneckPatterns {
157
+ | Pattern | Symptoms | Typical Causes |
158
+ |---------|----------|----------------|
159
+ | CPU-bound | High CPU, low I/O wait | Inefficient algorithms, tight loops |
160
+ | Memory-bound | High memory, GC pressure | Memory leaks, large allocations |
161
+ | I/O-bound | Low CPU, high I/O wait | Slow queries, network latency |
162
+ | Lock contention | Low CPU, high wait time | Synchronization, connection pools |
163
+ | N+1 queries | Many small DB queries | Missing joins, lazy loading |
164
+ }
165
+
166
+ AmdahlsLaw {
167
+ Optimization impact is limited by the fraction of time affected:
168
+
169
+ ```
170
+ If 90% of time is in function A and 10% in function B:
171
+ - Optimizing A by 50% = 45% total improvement
172
+ - Optimizing B by 50% = 5% total improvement
173
+ ```
174
+
175
+ Focus on the biggest contributors first.
176
+ }
177
+ }
178
+
179
+ CapacityPlanning {
180
+ BaselineEstablishment {
181
+ Measure current capacity under production load:
182
+ 1. Peak load metrics -- Maximum concurrent users, requests/sec
183
+ 2. Resource headroom -- How close to limits at peak
184
+ 3. Scaling patterns -- Linear, sub-linear, or super-linear
185
+ }
186
+
187
+ LoadTestingApproach {
188
+ 1. Establish baseline -- Current performance at normal load
189
+ 2. Ramp testing -- Gradually increase load to find limits
190
+ 3. Stress testing -- Push beyond limits to understand failure modes
191
+ 4. Soak testing -- Sustained load to find memory leaks, degradation
192
+ }
193
+
194
+ CapacityMetrics {
195
+ | Metric | What It Tells You |
196
+ |--------|-------------------|
197
+ | Throughput at saturation | Maximum system capacity |
198
+ | Latency at 80% load | Performance before degradation |
199
+ | Error rate under stress | Failure patterns |
200
+ | Recovery time | How quickly system returns to normal |
201
+ }
202
+
203
+ GrowthPlanning {
204
+ ```
205
+ Required Capacity = (Current Load x Growth Factor) + Safety Margin
206
+
207
+ Example:
208
+ - Current: 1000 req/sec
209
+ - Expected growth: 50% per year
210
+ - Safety margin: 30%
211
+
212
+ Year 1 need = (1000 x 1.5) x 1.3 = 1950 req/sec
213
+ ```
214
+ }
215
+ }
216
+
217
+ OptimizationPatterns {
218
+ QuickWins {
219
+ 1. Enable caching -- Application, CDN, database query cache
220
+ 2. Add indexes -- For slow queries identified in profiling
221
+ 3. Compression -- Gzip/Brotli for responses
222
+ 4. Connection pooling -- Reduce connection overhead
223
+ 5. Batch operations -- Reduce round-trips
224
+ }
225
+
226
+ AlgorithmicImprovements {
227
+ 1. Reduce complexity -- O(n^2) to O(n log n)
228
+ 2. Lazy evaluation -- Defer work until needed
229
+ 3. Memoization -- Cache computed results
230
+ 4. Pagination -- Limit data processed at once
231
+ }
232
+
233
+ ArchitecturalChanges {
234
+ 1. Horizontal scaling -- Add more instances
235
+ 2. Async processing -- Queue background work
236
+ 3. Read replicas -- Distribute read load
237
+ 4. Caching layers -- Redis, Memcached
238
+ 5. CDN -- Edge caching for static content
239
+ }
240
+ }
241
+
242
+ BestPractices {
243
+ - Profile in production-like environments; development can have different characteristics
244
+ - Use percentiles (p95, p99) not averages for latency
245
+ - Monitor continuously, not just during incidents
246
+ - Set performance budgets and enforce them in CI
247
+ - Document baseline metrics before making changes
248
+ - Keep profiling overhead low in production
249
+ - Correlate metrics across layers (application, database, infrastructure)
250
+ - Understand the difference between latency and throughput
251
+ }
252
+
253
+ AntiPatterns {
254
+ - Optimizing without measurement
255
+ - Using averages for latency metrics
256
+ - Profiling only in development
257
+ - Ignoring tail latencies (p99, p999)
258
+ - Premature optimization of non-bottleneck code
259
+ - Over-engineering for hypothetical scale
260
+ - Caching without invalidation strategy
261
+ }
262
+ }
263
+
264
+ ## References
265
+
266
+ - [Profiling Tools Reference](references/profiling-tools.md) - Tools by language and platform