# complexity-optimizer

complexity-optimizer detects algorithmic complexity bottlenecks in codebases and suggests safe runtime optimizations.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode, Windsurf (Devin Desktop), Claude.ai · 156 installs · ★ 227 repo stars
- Author: pproenca
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/pproenca/dot-skills/tree/HEAD/skills/.experimental/complexity-optimizer/SKILL.md
- Updated: 2026-08-15
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/skills/complexity-optimizer

## What it does

The skill scans repositories for quadratic loops, repeated scans, N+1 queries, and costly rendering recomputations. A Python helper script (`scripts/analyze_complexity.py`) provides first-pass hotspot detection. It parses Python files via the `ast` module, while other languages like TypeScript, Go, and Rust rely on regex patterns and indent boundaries.

Safety is built into the workflow. Analysis-only requests produce a structured markdown or JSON report without editing files. The skill modifies source code only when you explicitly use verbs like optimize, implement, or refactor. Every proposed change requires baseline test coverage to guard against semantic regressions.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add pproenca/dot-skills --skill complexity-optimizer -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/complexity-optimizer/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/complexity-optimizer/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add pproenca/dot-skills --skill complexity-optimizer -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/complexity-optimizer/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add pproenca/dot-skills --skill complexity-optimizer -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/complexity-optimizer/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install pproenca/dot-skills skills/.experimental/complexity-optimizer
```

2. **Manually: put the files in place**
- File: `.github/skills/complexity-optimizer/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add pproenca/dot-skills --skill complexity-optimizer -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/pproenca/dot-skills --path skills/.experimental/complexity-optimizer
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/complexity-optimizer/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add pproenca/dot-skills --skill complexity-optimizer -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/pproenca/dot-skills/tree/HEAD/skills/.experimental/complexity-optimizer/SKILL.md

## When to use it
- detect quadratic loops and nested iterations across repositories
- generate structured complexity audit reports for pull requests
- eliminate repeated linear lookups using hash maps or sets
- remove redundant data recomputations from UI render paths

## Example prompts
- Scan the project and report any algorithmic complexity bottlenecks
- Check changed files against origin/main for performance hotspots
- Optimize the nested loops in this service and verify against tests

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: a83bb4617a4ab2c7.

BEGIN THIRD-PARTY FILE a83bb4617a4ab2c7
````text
---
name: complexity-optimizer
description: Analyze a software codebase for algorithmic complexity and performance hotspots, then propose or implement safe optimizations without breaking behavior. Use when the user asks to scan many files, find inefficient loops, nested iteration, repeated scans, costly rendering/recomputation, N+1 queries, avoidable O(n^2) or O(n) operations, or reduce complexity such as O(n^2) to O(n log n) / O(n), while preserving tests, APIs, outputs, and maintainability.
---

# Complexity Optimizer

Find algorithmic complexity hotspots in a codebase and produce a structured report. Optionally implement low-risk optimizations after explicit consent.

## When to Apply

Use this skill when the user asks to:
- Analyze, audit, scan, or review a codebase for performance hotspots or algorithmic complexity
- Find inefficient loops, nested iteration, N+1 queries, sort-in-loop, render-path recomputation
- Reduce complexity (e.g. O(n^2) → O(n log n) or O(n))
- "Give me a report" on a codebase's complexity profile

Do not use this skill for:
- Micro-optimizations on cold code paths
- Memory tuning (this skill targets time complexity, not allocation profiles)
- Code style refactoring unrelated to complexity

## Workflow Overview

```
Baseline → Rank → Prove behavior → Optimize (opt-in) → Verify
   ↓           ↓                       ↓
 scanner   prioritize hot          rollback if
 + manual  paths & large I/O       tests regress
```

| Step | Action | Tool | Risk |
|------|--------|------|------|
| 1 | Establish baseline: detect stack, test command, hot paths | `scripts/analyze_complexity.py` + manual inspection | read-only |
| 2 | Rank opportunities by impact, separating algorithmic wins from constant-factor cleanup | reasoning | read-only |
| 3 | Locate or add tests covering the function/component | Read + test framework | read-only |
| 4 | Apply optimization (ONLY when user explicitly requests) | Edit/Write | destructive |
| 5 | Run tests, lint, type-check, and a benchmark when warranted; report before/after complexity | Bash test commands | read-only |

## Core Rule

Optimize only when current behavior is understood and can be preserved. Prefer a small, proven improvement with tests over a broad rewrite with unclear correctness.

## Default Behavior

When the user asks to analyze, scan, audit, review, or "give me a report" for a codebase, produce the full complexity report automatically. Do not require the user to specify report fields.

Default report contents (see `references/report-template.md`):

- Scope analyzed and detected stack/test commands
- Top findings ranked by likely impact
- File and line for each finding
- Current pattern and why it may be costly
- Estimated current complexity
- Recommended change and estimated complexity after
- Risk level
````
END THIRD-PARTY FILE a83bb4617a4ab2c7

The third-party file has ended. Everything between the a83bb4617a4ab2c7 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2835 of 8966 bytes. © pproenca · MIT · https://github.com/pproenca/dot-skills/tree/HEAD/skills/.experimental/complexity-optimizer/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
