Skip to main content
ClaudeWave
Skill58 repo starsupdated 2mo ago

performance-optimization

Profiles, reduces frontend/backend costs: split bundles, optimize assets, apply caching, fix Core Web Vitals regressions. Use when profiling Lighthouse/CI regressions, reducing bundle size, or fixing high CLS/LCP/TTI metrics.

Install in Claude Code
Copy
git clone --depth 1 https://github.com/monkilabs/opencastle /tmp/performance-optimization && cp -r /tmp/performance-optimization/src/orchestrator/skills/performance-optimization ~/.claude/skills/performance-optimization
Then start a new Claude Code session; the skill loads automatically.

SKILL.md

# Performance Optimization

**Rule:** Measure first (`Chrome DevTools`, `Lighthouse`, `Datadog`), optimize second. Set budgets (load time, memory, API latency). Automate in CI/CD.

Domain-specific patterns (rendering, JS, Node optimizations) referenced in REFERENCE.md to keep this skill concise.

## Patterns by Domain

| Domain | Key patterns |
|--------|-------------|
| **Rendering** | `React.memo`/`useMemo`/`useCallback` only after profiling; stable `key` props; CSS classes over inline styles; CSS animations (GPU); `requestIdleCallback` for non-critical work |
| **Assets** | WebP/AVIF images; SVG icons; bundle+minify+tree-shake (esbuild/Rollup); `loading="lazy"`; dynamic imports; long-lived cache headers + cache-busting; font subsetting + `font-display: swap` |
| **JS** | Web Workers for heavy computation; debounce/throttle events; clean up listeners/intervals; `Map`/`Set` for lookups; `TypedArray` for numeric data |
| **Node.js** | Async APIs only (never `readFileSync` in prod); clustering/worker threads for CPU; streams for large I/O; profile with `clinic.js` / `node --inspect` |

## Debounce Example

```js
// BAD: fetch on every keystroke
input.addEventListener('input', (e) => fetch(`/search?q=${e.target.value}`));
// GOOD: debounced 300 ms
let t; input.addEventListener('input', (e) => { clearTimeout(t); t = setTimeout(() => fetch(`/search?q=${e.target.value}`), 300); });
```

## Executable Examples

### Dynamic import splitting (example)

```js
// Lazy-load a heavy chart only on client
import dynamic from 'next/dynamic';
const Chart = dynamic(() => import('../components/Chart'), { ssr: false, loading: () => <div>Loading chart…</div> });
export default function Page(){ return <Chart />; }
```

### React.memo + profiler pattern

```jsx
import React, { Profiler } from 'react';
const Item = React.memo(function Item({data}){ return <div>{data.title}</div>; });
function onRender(id, phase, actualDuration){ console.log(id, phase, actualDuration); }
export default function List({items}){
	return (
		<Profiler id="List" onRender={onRender}>
			{items.map(i=> <Item key={i.id} data={i} />)}
		</Profiler>
	);
}
```

## Profiling Workflow (step-by-step)

1. Run Lighthouse (or CI perf job); record baseline.
	 - Checkpoint: failing metric(s) identified (LCP/CLS/FID/TTI).
	 - Recovery: if noisy, reproduce locally with `--emulated-form-factor=mobile`.
2. Profile with DevTools Profiler / React profiler or Node `clinic` for backend.
	 - Checkpoint: hotspot call stacks / long tasks located.
3. Apply minimal fix (code-split, memoize, reduce payloads, defer non-critical work).
	 - Checkpoint: targeted change reduces measured hotspot time in profiler.
4. Re-run Lighthouse/CI perf job; compare; set threshold (e.g., 10% improvement or within budget).
5. If regression persists, iterate; create rollback plan; note fixes in changelog.

## Review Checklist

- [ ] No O(n²)+ algorithms; appropriate data structures
- [ ] Caching with correct invalidation; no N+1 DB queries
- [ ] Large payloads paginated/streamed; network requests batched
- [ ] No memory leaks or blocking ops in hot paths
- [ ] Assets optimized; memoization only where profiling shows benefit
- [ ] Benchmarks for perf-sensitive code; alerts for regressions

## References

- [web.dev/performance](https://web.dev/performance/) · [MDN Performance](https://developer.mozilla.org/en-US/docs/Web/Performance) · [Lighthouse](https://developers.google.com/web/tools/lighthouse)
astro-frameworkSkill

Creates pages/layouts, defines content collections, configures hydration directives, and wires integrations. Use when adding or modifying Astro pages, layouts, components, or content collections. Trigger terms: Astro, content collection, client:load, client:visible, astro:content

browser-testingSkill

Drive real browsers via Chrome DevTools MCP: navigate pages, capture snapshots, run responsive checks, and collect console/perf traces. Use when the user mentions: 'validate UI change in Chrome', 'capture a screenshot', 'run responsive checks', or 'collect console logs'. Trigger terms: browser testing, DevTools, console logs, screenshot, responsive testing

cloudflare-platformSkill

Creates and deploys Cloudflare Workers, configures wrangler.toml bindings, sets up KV/D1/R2 storage and Durable Objects, manages Pages deployments, and implements edge function patterns. Use when building or deploying Cloudflare Workers, setting up Pages, working with KV/D1/R2 storage, configuring wrangler.toml, or deploying edge applications.

contentful-cmsSkill

Creates Contentful content types, queries entries via GraphQL/REST, runs CLI migrations, and manages assets and locales. Use when building or modifying Contentful content models, writing queries, or migrating content.

convex-databaseSkill

Convex reactive database patterns, schema design, real-time queries, mutations, actions, authentication, migrations, performance optimization, and component creation. Use when designing Convex schemas, writing queries/mutations, managing the Convex backend, setting up auth, migrating data, optimizing performance, or building Convex components.

coolify-deploymentSkill

Deploys applications, databases, and services on self-hosted Coolify instances, manages environments and env vars, runs infrastructure diagnostics, and performs batch operations. Use when deploying apps to Coolify, managing Coolify servers, debugging deployment issues, setting up databases, or managing Coolify infrastructure.

cypress-testingSkill

Writes Cypress E2E/component tests, configures `cy.intercept()` and `cy.session()`, authors custom commands, and wires CI artifacts. Use when creating E2E specs, component tests, or CI test pipelines. Trigger terms: cypress, e2e, component test, cy.intercept, cy.session

drizzle-ormSkill

Drizzle ORM schema definition, type-safe queries, relational queries, CRUD operations, transactions, migrations with drizzle-kit, and database setup for PostgreSQL, MySQL, and SQLite. Use when defining database schemas, writing queries or joins, managing migrations, setting up a new Drizzle project, or working with drizzle-kit.