@kl-c/matrixos 0.3.40 → 0.3.41

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 (49) hide show
  1. package/dist/cli/index.js +1 -1
  2. package/dist/cli/skills/api-and-interface-design/SKILL.md +298 -0
  3. package/dist/cli/skills/browser-testing-with-devtools/SKILL.md +321 -0
  4. package/dist/cli/skills/ci-cd-and-automation/SKILL.md +394 -0
  5. package/dist/cli/skills/context-engineering/SKILL.md +293 -0
  6. package/dist/cli/skills/deprecation-and-migration/SKILL.md +251 -0
  7. package/dist/cli/skills/documentation-and-adrs/SKILL.md +292 -0
  8. package/dist/cli/skills/doubt-driven-development/SKILL.md +247 -0
  9. package/dist/cli/skills/incremental-implementation/SKILL.md +253 -0
  10. package/dist/cli/skills/interview-me/SKILL.md +229 -0
  11. package/dist/cli/skills/observability-and-instrumentation/SKILL.md +207 -0
  12. package/dist/cli/skills/performance-optimization/SKILL.md +354 -0
  13. package/dist/cli/skills/security-and-hardening/SKILL.md +471 -0
  14. package/dist/cli/skills/shipping-and-launch/SKILL.md +314 -0
  15. package/dist/cli/skills/source-driven-development/SKILL.md +198 -0
  16. package/dist/cli/skills/test-driven-development/SKILL.md +402 -0
  17. package/dist/cli-node/index.js +1 -1
  18. package/dist/index.js +1 -1
  19. package/dist/skills/api-and-interface-design/SKILL.md +298 -0
  20. package/dist/skills/browser-testing-with-devtools/SKILL.md +321 -0
  21. package/dist/skills/ci-cd-and-automation/SKILL.md +394 -0
  22. package/dist/skills/context-engineering/SKILL.md +293 -0
  23. package/dist/skills/deprecation-and-migration/SKILL.md +251 -0
  24. package/dist/skills/documentation-and-adrs/SKILL.md +292 -0
  25. package/dist/skills/doubt-driven-development/SKILL.md +247 -0
  26. package/dist/skills/incremental-implementation/SKILL.md +253 -0
  27. package/dist/skills/interview-me/SKILL.md +229 -0
  28. package/dist/skills/observability-and-instrumentation/SKILL.md +207 -0
  29. package/dist/skills/performance-optimization/SKILL.md +354 -0
  30. package/dist/skills/security-and-hardening/SKILL.md +471 -0
  31. package/dist/skills/shipping-and-launch/SKILL.md +314 -0
  32. package/dist/skills/source-driven-development/SKILL.md +198 -0
  33. package/dist/skills/test-driven-development/SKILL.md +402 -0
  34. package/package.json +1 -1
  35. package/packages/shared-skills/skills/api-and-interface-design/SKILL.md +298 -0
  36. package/packages/shared-skills/skills/browser-testing-with-devtools/SKILL.md +321 -0
  37. package/packages/shared-skills/skills/ci-cd-and-automation/SKILL.md +394 -0
  38. package/packages/shared-skills/skills/context-engineering/SKILL.md +293 -0
  39. package/packages/shared-skills/skills/deprecation-and-migration/SKILL.md +251 -0
  40. package/packages/shared-skills/skills/documentation-and-adrs/SKILL.md +292 -0
  41. package/packages/shared-skills/skills/doubt-driven-development/SKILL.md +247 -0
  42. package/packages/shared-skills/skills/incremental-implementation/SKILL.md +253 -0
  43. package/packages/shared-skills/skills/interview-me/SKILL.md +229 -0
  44. package/packages/shared-skills/skills/observability-and-instrumentation/SKILL.md +207 -0
  45. package/packages/shared-skills/skills/performance-optimization/SKILL.md +354 -0
  46. package/packages/shared-skills/skills/security-and-hardening/SKILL.md +471 -0
  47. package/packages/shared-skills/skills/shipping-and-launch/SKILL.md +314 -0
  48. package/packages/shared-skills/skills/source-driven-development/SKILL.md +198 -0
  49. package/packages/shared-skills/skills/test-driven-development/SKILL.md +402 -0
@@ -0,0 +1,354 @@
1
+ ---
2
+ name: performance-optimization
3
+ description: Optimizes application performance across frontend, backend, queries, and databases. Use when performance requirements exist, when you suspect performance regressions, when Core Web Vitals or load times need improvement, when N+1 query patterns need fixing, or when profiling reveals bottlenecks.
4
+ source: addyosmani/agent-skills (MIT)
5
+ ---
6
+
7
+ # Performance Optimization
8
+
9
+ ## Overview
10
+
11
+ Measure before optimizing. Performance work without measurement is guessing — and guessing leads to premature optimization that adds complexity without improving what matters. Profile first, identify the actual bottleneck, fix it, measure again. Optimize only what measurements prove matters.
12
+
13
+ ## When to Use
14
+
15
+ - Performance requirements exist in the spec (load time budgets, response time SLAs)
16
+ - Users or monitoring report slow behavior
17
+ - Core Web Vitals scores are below thresholds
18
+ - You suspect a change introduced a regression
19
+ - Building features that handle large datasets or high traffic
20
+
21
+ **When NOT to use:** Don't optimize before you have evidence of a problem. Premature optimization adds complexity that costs more than the performance it gains.
22
+
23
+ ## Core Web Vitals Targets
24
+
25
+ | Metric | Good | Needs Improvement | Poor |
26
+ |--------|------|-------------------|------|
27
+ | **LCP** (Largest Contentful Paint) | ≤ 2.5s | ≤ 4.0s | > 4.0s |
28
+ | **INP** (Interaction to Next Paint) | ≤ 200ms | ≤ 500ms | > 500ms |
29
+ | **CLS** (Cumulative Layout Shift) | ≤ 0.1 | ≤ 0.25 | > 0.25 |
30
+
31
+ ## The Optimization Workflow
32
+
33
+ ```
34
+ 1. MEASURE → Establish baseline with real data
35
+ 2. IDENTIFY → Find the actual bottleneck (not assumed)
36
+ 3. FIX → Address the specific bottleneck
37
+ 4. VERIFY → Measure again, confirm improvement
38
+ 5. GUARD → Add monitoring or tests to prevent regression
39
+ ```
40
+
41
+ ### Step 1: Measure
42
+
43
+ Two complementary approaches — use both:
44
+
45
+ - **Synthetic (Lighthouse, DevTools Performance tab):** Controlled conditions, reproducible. Best for CI regression detection and isolating specific issues.
46
+ - **RUM (web-vitals library, CrUX):** Real user data in real conditions. Required to validate that a fix actually improved user experience.
47
+
48
+ **Frontend:**
49
+ ```bash
50
+ # Synthetic: Lighthouse in Chrome DevTools (or CI)
51
+ # Chrome DevTools → Performance tab → Record
52
+ # Chrome DevTools MCP → Performance trace
53
+
54
+ # RUM: Web Vitals library in code
55
+ import { onLCP, onINP, onCLS } from 'web-vitals';
56
+
57
+ onLCP(console.log);
58
+ onINP(console.log);
59
+ onCLS(console.log);
60
+ ```
61
+
62
+ **Backend:**
63
+ ```bash
64
+ # Response time logging
65
+ # Application Performance Monitoring (APM)
66
+ # Database query logging with timing
67
+
68
+ # Simple timing
69
+ console.time('db-query');
70
+ const result = await db.query(...);
71
+ console.timeEnd('db-query');
72
+ ```
73
+
74
+ ### Where to Start Measuring
75
+
76
+ Use the symptom to decide what to measure first:
77
+
78
+ ```
79
+ What is slow?
80
+ ├── First page load
81
+ │ ├── Large bundle? --> Measure bundle size, check code splitting
82
+ │ ├── Slow server response? --> Measure TTFB in DevTools Network waterfall
83
+ │ │ ├── DNS long? --> Add dns-prefetch / preconnect for known origins
84
+ │ │ ├── TCP/TLS long? --> Enable HTTP/2, check edge deployment, keep-alive
85
+ │ │ └── Waiting (server) long? --> Profile backend, check queries and caching
86
+ │ └── Render-blocking resources? --> Check network waterfall for CSS/JS blocking
87
+ ├── Interaction feels sluggish
88
+ │ ├── UI freezes on click? --> Profile main thread, look for long tasks (>50ms)
89
+ │ ├── Form input lag? --> Check re-renders, controlled component overhead
90
+ │ └── Animation jank? --> Check layout thrashing, forced reflows
91
+ ├── Page after navigation
92
+ │ ├── Data loading? --> Measure API response times, check for waterfalls
93
+ │ └── Client rendering? --> Profile component render time, check for N+1 fetches
94
+ └── Backend / API
95
+ ├── Single endpoint slow? --> Profile database queries, check indexes
96
+ ├── All endpoints slow? --> Check connection pool, memory, CPU
97
+ └── Intermittent slowness? --> Check for lock contention, GC pauses, external deps
98
+ ```
99
+
100
+ ### Step 2: Identify the Bottleneck
101
+
102
+ Common bottlenecks by category:
103
+
104
+ **Frontend:**
105
+
106
+ | Symptom | Likely Cause | Investigation |
107
+ |---------|-------------|---------------|
108
+ | Slow LCP | Large images, render-blocking resources, slow server | Check network waterfall, image sizes |
109
+ | High CLS | Images without dimensions, late-loading content, font shifts | Check layout shift attribution |
110
+ | Poor INP | Heavy JavaScript on main thread, large DOM updates | Check long tasks in Performance trace |
111
+ | Slow initial load | Large bundle, many network requests | Check bundle size, code splitting |
112
+
113
+ **Backend:**
114
+
115
+ | Symptom | Likely Cause | Investigation |
116
+ |---------|-------------|---------------|
117
+ | Slow API responses | N+1 queries, missing indexes, unoptimized queries | Check database query log |
118
+ | Memory growth | Leaked references, unbounded caches, large payloads | Heap snapshot analysis |
119
+ | CPU spikes | Synchronous heavy computation, regex backtracking | CPU profiling |
120
+ | High latency | Missing caching, redundant computation, network hops | Trace requests through the stack |
121
+
122
+ ### Step 3: Fix Common Anti-Patterns
123
+
124
+ #### N+1 Queries (Backend)
125
+
126
+ ```typescript
127
+ // BAD: N+1 — one query per task for the owner
128
+ const tasks = await db.tasks.findMany();
129
+ for (const task of tasks) {
130
+ task.owner = await db.users.findUnique({ where: { id: task.ownerId } });
131
+ }
132
+
133
+ // GOOD: Single query with join/include
134
+ const tasks = await db.tasks.findMany({
135
+ include: { owner: true },
136
+ });
137
+ ```
138
+
139
+ #### Unbounded Data Fetching
140
+
141
+ ```typescript
142
+ // BAD: Fetching all records
143
+ const allTasks = await db.tasks.findMany();
144
+
145
+ // GOOD: Paginated with limits
146
+ const tasks = await db.tasks.findMany({
147
+ take: 20,
148
+ skip: (page - 1) * 20,
149
+ orderBy: { createdAt: 'desc' },
150
+ });
151
+ ```
152
+
153
+ #### Missing Image Optimization (Frontend)
154
+
155
+ ```html
156
+ <!-- BAD: No dimensions, no format optimization -->
157
+ <img src="/hero.jpg" />
158
+
159
+ <!-- GOOD: Hero / LCP image — art direction + resolution switching, high priority -->
160
+ <!--
161
+ Two techniques combined:
162
+ - Art direction (media): different crop/composition per breakpoint
163
+ - Resolution switching (srcset + sizes): right file size per screen density
164
+ -->
165
+ <picture>
166
+ <!-- Mobile: portrait crop (8:10) -->
167
+ <source
168
+ media="(max-width: 767px)"
169
+ srcset="/hero-mobile-400.avif 400w, /hero-mobile-800.avif 800w"
170
+ sizes="100vw"
171
+ width="800"
172
+ height="1000"
173
+ type="image/avif"
174
+ />
175
+ <source
176
+ media="(max-width: 767px)"
177
+ srcset="/hero-mobile-400.webp 400w, /hero-mobile-800.webp 800w"
178
+ sizes="100vw"
179
+ width="800"
180
+ height="1000"
181
+ type="image/webp"
182
+ />
183
+ <!-- Desktop: landscape crop (2:1) -->
184
+ <source
185
+ srcset="/hero-800.avif 800w, /hero-1200.avif 1200w, /hero-1600.avif 1600w"
186
+ sizes="(max-width: 1200px) 100vw, 1200px"
187
+ width="1200"
188
+ height="600"
189
+ type="image/avif"
190
+ />
191
+ <source
192
+ srcset="/hero-800.webp 800w, /hero-1200.webp 1200w, /hero-1600.webp 1600w"
193
+ sizes="(max-width: 1200px) 100vw, 1200px"
194
+ width="1200"
195
+ height="600"
196
+ type="image/webp"
197
+ />
198
+ <img
199
+ src="/hero-desktop.jpg"
200
+ width="1200"
201
+ height="600"
202
+ fetchpriority="high"
203
+ alt="Hero image description"
204
+ />
205
+ </picture>
206
+
207
+ <!-- GOOD: Below-the-fold image — lazy loaded + async decoding -->
208
+ <img
209
+ src="/content.webp"
210
+ width="800"
211
+ height="400"
212
+ loading="lazy"
213
+ decoding="async"
214
+ alt="Content image description"
215
+ />
216
+ ```
217
+
218
+ #### Unnecessary Re-renders (React)
219
+
220
+ ```tsx
221
+ // BAD: Creates new object on every render, causing children to re-render
222
+ function TaskList() {
223
+ return <TaskFilters options={{ sortBy: 'date', order: 'desc' }} />;
224
+ }
225
+
226
+ // GOOD: Stable reference
227
+ const DEFAULT_OPTIONS = { sortBy: 'date', order: 'desc' } as const;
228
+ function TaskList() {
229
+ return <TaskFilters options={DEFAULT_OPTIONS} />;
230
+ }
231
+
232
+ // Use React.memo for expensive components
233
+ const TaskItem = React.memo(function TaskItem({ task }: Props) {
234
+ return <div>{/* expensive render */}</div>;
235
+ });
236
+
237
+ // Use useMemo for expensive computations
238
+ function TaskStats({ tasks }: Props) {
239
+ const stats = useMemo(() => calculateStats(tasks), [tasks]);
240
+ return <div>{stats.completed} / {stats.total}</div>;
241
+ }
242
+ ```
243
+
244
+ #### Large Bundle Size
245
+
246
+ ```typescript
247
+ // Modern bundlers (Vite, webpack 5+) handle named imports with tree-shaking automatically,
248
+ // provided the dependency ships ESM and is marked `sideEffects: false` in package.json.
249
+ // Profile before changing import styles — the real gains come from splitting and lazy loading.
250
+
251
+ // GOOD: Dynamic import for heavy, rarely-used features
252
+ const ChartLibrary = lazy(() => import('./ChartLibrary'));
253
+
254
+ // GOOD: Route-level code splitting wrapped in Suspense
255
+ const SettingsPage = lazy(() => import('./pages/Settings'));
256
+
257
+ function App() {
258
+ return (
259
+ <Suspense fallback={<Spinner />}>
260
+ <SettingsPage />
261
+ </Suspense>
262
+ );
263
+ }
264
+ ```
265
+
266
+ #### Missing Caching (Backend)
267
+
268
+ ```typescript
269
+ // Cache frequently-read, rarely-changed data
270
+ const CACHE_TTL = 5 * 60 * 1000; // 5 minutes
271
+ let cachedConfig: AppConfig | null = null;
272
+ let cacheExpiry = 0;
273
+
274
+ async function getAppConfig(): Promise<AppConfig> {
275
+ if (cachedConfig && Date.now() < cacheExpiry) {
276
+ return cachedConfig;
277
+ }
278
+ cachedConfig = await db.config.findFirst();
279
+ cacheExpiry = Date.now() + CACHE_TTL;
280
+ return cachedConfig;
281
+ }
282
+
283
+ // HTTP caching headers for static assets
284
+ app.use('/static', express.static('public', {
285
+ maxAge: '1y', // Cache for 1 year
286
+ immutable: true, // Never revalidate (use content hashing in filenames)
287
+ }));
288
+
289
+ // Cache-Control for API responses
290
+ res.set('Cache-Control', 'public, max-age=300'); // 5 minutes
291
+ ```
292
+
293
+ ## Performance Budget
294
+
295
+ Set budgets and enforce them:
296
+
297
+ ```
298
+ JavaScript bundle: < 200KB gzipped (initial load)
299
+ CSS: < 50KB gzipped
300
+ Images: < 200KB per image (above the fold)
301
+ Fonts: < 100KB total
302
+ API response time: < 200ms (p95)
303
+ Time to Interactive: < 3.5s on 4G
304
+ Lighthouse Performance score: ≥ 90
305
+ ```
306
+
307
+ **Enforce in CI:**
308
+ ```bash
309
+ # Bundle size check
310
+ npx bundlesize --config bundlesize.config.json
311
+
312
+ # Lighthouse CI
313
+ npx lhci autorun
314
+ ```
315
+
316
+ ## See Also
317
+
318
+ For detailed performance checklists, optimization commands, and anti-pattern reference, see `references/performance-checklist.md`.
319
+
320
+
321
+ ## Common Rationalizations
322
+
323
+ | Rationalization | Reality |
324
+ |---|---|
325
+ | "We'll optimize later" | Performance debt compounds. Fix obvious anti-patterns now, defer micro-optimizations. |
326
+ | "It's fast on my machine" | Your machine isn't the user's. Profile on representative hardware and networks. |
327
+ | "This optimization is obvious" | If you didn't measure, you don't know. Profile first. |
328
+ | "Users won't notice 100ms" | Research shows 100ms delays impact conversion rates. Users notice more than you think. |
329
+ | "The framework handles performance" | Frameworks prevent some issues but can't fix N+1 queries or oversized bundles. |
330
+
331
+ ## Red Flags
332
+
333
+ - Optimization without profiling data to justify it
334
+ - N+1 query patterns in data fetching
335
+ - List endpoints without pagination
336
+ - Images without dimensions, lazy loading, or responsive sizes
337
+ - Bundle size growing without review
338
+ - No performance monitoring in production
339
+ - `React.memo` and `useMemo` everywhere (overusing is as bad as underusing)
340
+
341
+ ## Verification
342
+
343
+ After any performance-related change:
344
+
345
+ - [ ] Before and after measurements exist (specific numbers)
346
+ - [ ] The specific bottleneck is identified and addressed
347
+ - [ ] Core Web Vitals are within "Good" thresholds
348
+ - [ ] Bundle size hasn't increased significantly
349
+ - [ ] No N+1 queries in new data fetching code
350
+ - [ ] Performance budget passes in CI (if configured)
351
+ - [ ] Existing tests still pass (optimization didn't break behavior)
352
+
353
+ ---
354
+ *Source: addyosmani/agent-skills (MIT). Ported into MaTrixOS shared-skills bundle.*