Skip to content
Back to skills

Optimize

ASecurity

Analyze and suggest performance improvements for code, queries, or systems

  • 6,113 stars
  • 0 votes
  • 0 copies
  • 5 views
  • Added May 27, 2026
developmenttypescriptgobashsqlreactnodeapidatabasefrontendperformance

Works with

  • api

Security analysis

A100/100

Scanned October 1, 2026

npx -y skills add FlorianBruniaux/claude-code-ultimate-guide --skill optimize --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Optimize?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Optimize
[![Security: A β€” Skills Directory](https://www.skillsdirectory.com/api/skills/florianbruniaux-optimize/badge)](https://www.skillsdirectory.com/skills/florianbruniaux-optimize)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: optimize
description: Analyze and suggest performance improvements for code, queries, or systems
argument-hint: "<file_or_module> [--focus speed|memory|bundle]"
effort: medium
when_to_use: "Use when a function or module needs performance analysis or improvements."
disable-model-invocation: true
---

# Performance optimizer

Analyze and suggest performance improvements for code, queries, or systems.

## Purpose

Identify optimization opportunities:
- Runtime performance bottlenecks
- Memory usage issues
- Database query inefficiencies
- Bundle size problems
- Algorithm complexity

## Instructions

### Step 1: Scope identification

Determine optimization target:
- **Function**: Single function performance
- **Module**: Related functions/classes
- **Query**: Database query optimization
- **Bundle**: Frontend bundle analysis
- **System**: Architecture-level optimization

### Step 2: Performance analysis

#### Runtime analysis

```bash
# Find potentially slow patterns
grep -rn "forEach\|\.map\|\.filter\|\.reduce" --include="*.{ts,js}" . | head -20

# Find nested loops (O(nΒ²) potential)
grep -rn "for.*for\|\.forEach.*\.forEach\|\.map.*\.map" --include="*.{ts,js}" . | head -10

# Find sync operations that could be async
grep -rn "readFileSync\|writeFileSync\|execSync" --include="*.{ts,js}" . | head -10
```

#### Memory analysis

```bash
# Large array operations
grep -rn "new Array\|Array\.from\|\.concat\|spread" --include="*.{ts,js}" . | head -10

# Potential memory leaks (event listeners, intervals)
grep -rn "addEventListener\|setInterval\|setTimeout" --include="*.{ts,js}" . | head -10
```

#### Database query analysis

```bash
# N+1 query patterns
grep -rn "await.*find\|await.*query" --include="*.{ts,js}" . | head -15

# Missing indexes hints
grep -rn "WHERE\|ORDER BY\|GROUP BY" --include="*.{ts,js,sql}" . | head -15
```

#### Bundle analysis

```bash
# Check bundle size (if applicable)
[ -f "package.json" ] && npm run build 2>/dev/null && ls -lh dist/*.js 2>/dev/null

# Large dependencies
[ -f "package.json" ] && cat package.json | jq '.dependencies | keys[]' | head -20
```

### Step 3: Prioritization

Rank findings by:
1. **Impact**: How much will this improve performance?
2. **Effort**: How hard is the fix?
3. **Risk**: What could break?

## Output format

---

### ⚑ Performance analysis

**Target**: [file/module/system]
**Analysis Date**: [timestamp]

### πŸ“Š Current Metrics (if measurable)

| Metric | Current | Target | Gap |
|--------|---------|--------|-----|
| Response time | Xms | <Yms | -Z% needed |
| Memory usage | XMB | <YMB | -Z% needed |
| Bundle size | XKB | <YKB | -Z% needed |

### πŸ”΄ Critical issues

#### 1. [Issue title] - [location]

**Problem**: [What's slow and why]

**Current**:
```typescript
// O(nΒ²) - nested loops
users.forEach(user => {
  permissions.forEach(perm => {
    if (user.id === perm.userId) { ... }
  });
});
```

**Optimized**:
```typescript
// O(n) - Map lookup
const permMap = new Map(permissions.map(p => [p.userId, p]));
users.forEach(user => {
  const perm = permMap.get(user.id);
  if (perm) { ... }
});
```

**Impact**: ~10x faster for 1000 users
**Effort**: Low (5 min)
**Risk**: Low

### 🟠 High priority

| Issue | Location | Impact | Effort |
|-------|----------|--------|--------|
| [description] | file:line | [estimate] | [time] |

### 🟑 Medium priority

| Issue | Location | Impact | Effort |
|-------|----------|--------|--------|
| [description] | file:line | [estimate] | [time] |

### πŸ’‘ Quick wins

1. [Small change with good impact]
2. [Another quick optimization]
3. [Low-hanging fruit]

### πŸ“ˆ Optimization roadmap

```
Week 1: Critical fixes (items 1-3)
Week 2: High priority (items 4-6)
Week 3: Measure and validate improvements
```

---

## Common patterns

### Array operations

| Pattern | Issue | Fix |
|---------|-------|-----|
| `arr.filter().map()` | Two iterations | Single `reduce()` or `flatMap()` |
| `arr.find()` in loop | O(nΒ²) | Build Map/Set first |
| `[...arr1, ...arr2]` | Memory allocation | `arr1.concat(arr2)` or push |

### Database

| Pattern | Issue | Fix |
|---------|-------|-----|
| Loop with await | N+1 queries | Batch query with `IN` |
| `SELECT *` | Over-fetching | Select only needed columns |
| Missing WHERE index | Full table scan | Add composite index |

### React/frontend

| Pattern | Issue | Fix |
|---------|-------|-----|
| Inline functions in JSX | Re-renders | `useCallback` |
| Large list rendering | DOM thrashing | Virtualization |
| Unoptimized images | Slow LCP | Next/Image, lazy loading |

### Node.js

| Pattern | Issue | Fix |
|---------|-------|-----|
| Sync file operations | Blocks event loop | Async alternatives |
| JSON.parse large files | Memory spike | Streaming parser |
| No connection pooling | Connection overhead | Pool with pg-pool, etc. |

## Usage

**Analyze specific file:**
```
/optimize src/services/user.ts
```

**Focus on specific area:**
```
/optimize --queries src/repositories/
/optimize --bundle
/optimize --memory src/workers/
```

**With target metrics:**
```
/optimize --target=100ms src/api/search.ts
```

**Quick scan:**
```
/optimize --quick
```

## Notes

- Measurements beat assumptions: profile before optimizing
- Premature optimization is the root of all evil (Knuth)
- Focus on hot paths: optimize what runs often
- Consider trade-offs: speed vs readability vs maintainability

$ARGUMENTS

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.