mcpField
A
algorithmic-complexity-review

algorithmic-complexity-review

github.com/pproencaTesting & quality218158 installsUpdated 11w ago
Repository

About algorithmic-complexity-review

A language-agnostic Big-O review skill for finding and addressing common performance pitfalls in code. Its find-classify-fix workflow covers nested iteration, I/O, data structures, recursion, and space complexity.

Key features

  1. 01Eight categories of complexity issues
  2. 02Derive Big-O from code structure
  3. 03Signals for locating likely problems
  4. 04Minimal-diff examples for fixes
  5. 05Runtime and space complexity traps

Use cases

  1. 01Checking pull requests for performance regressions
  2. 02Investigating functions that slow as inputs grow
  3. 03Refactoring hot paths with loops, recursion, or I/O

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/pproenca/dot-skills --skill algorithmic-complexity-review

After installing, type/algorithmic-complexity-reviewin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

AGENTS.md
metadata.json
README.md
assets/templates/
_template.md
references/
_sections.md
build-avoid-immutable-object-spread.md
build-avoid-quadratic-string-concat.md
build-avoid-spread-in-reducer.md
build-presize-when-length-known.md
compute-cache-expensive-pure-results.md
compute-cache-property-lookup.md
compute-defer-or-short-circuit.md
compute-hoist-loop-invariants.md
compute-precompile-regex.md
ds-counter-for-histograms.md
ds-deque-for-front-operations.md
ds-hashmap-for-keyed-access.md
ds-heap-for-top-k.md
ds-sorted-structure-for-range-queries.md
ds-trie-for-prefix-search.md
io-batch-instead-of-per-item.md
io-file-read-in-loop.md
io-missing-eager-load.md
io-n-plus-one-query.md
io-sequential-await-in-loop.md
nested-cartesian-comparison.md
nested-explicit-quadratic-loops.md
nested-find-in-loop.md
nested-includes-in-loop.md
nested-set-operations-on-arrays.md

Details

From the project README

dot-skills Algorithmic Complexity (Big-O) Best Practices

Find, classify, and fix algorithmic complexity (Big-O) problems in code — language-agnostic. The 39 rules across 8 categories cover the patterns responsible for the vast majority of accidental quadratic, exponential, and N+1 blowups in production code: nested iteration, loop-invariant I/O, data-structure mismatch, recursion explosions, redundant computation, collection-building anti-patterns, search/sort selection, and space traps.

When to Apply

Use this skill when:

  • Reviewing a pull request or function for performance regressions
  • Asked "why is this slow?" or "can we make this faster?"
  • Refactoring a hot path or a function that handles user-scaled input
  • Reading code that contains: nested loops, .includes/.find/x in list inside iteration, ORM access in a loop, recursion without memoization, string/array building via += or spread, file/database I/O inside iteration
  • Reviewing code that processes lists, trees, or streams whose size will grow

Workflow: Find, Classify, Fix

The skill is structured for a three-step workflow on any code under review:

1. Find — Scan for the Suspicion Patterns

Look for these structural signals first (highest hit rate):

SignalLikely CategoryFirst Rule to Check
Two nested for loopsnested-nested-explicit-quadratic-loops
.includes / .find / x in list inside a loopnested-nested-includes-in-loop
ORM access inside a loop (for o in orders: o.customer.x)io-io-n-plus-one-query
await fetch in for-ofio-io-sequential-await-in-loop
array.find to "join" two arraysds-ds-hashmap-for-keyed-access
Recursive function with overlapping argumentsrec-rec-memoize-overlapping-subproblems
s = s + part or [...acc, x] in a loopbuild-build-avoid-quadratic-string-concat, build-avoid-spread-in-reducer
sorted(...) called inside a loopsearch-search-sort-once-outside-loop
readlines() / loading whole filesspace-space-stream-dont-load
2. Classify — Derive the Big-O

Compute complexity from the code structure:

StructureComplexity
Single loop over n items, O(1) bodyO(n)
Two nested loops over n / m itemsO(n*m)
Loop calling an O(n) operation (.includes, .find, x in list)O(n*m), often misread as O(n)
Recursive f(n) = f(n-1) + f(n-2) without memoizationO(2ⁿ)
Recursive f(n) = 2*f(n/2) + O(n)O(n log n)
Recursive f(n) = 2*f(n/2) + O(1)O(n) (full tree traversal)
Recursive f(n) = f(n/2) + O(1)O(log n)
s = s + part in a loopO(n²) (string immutability)
[...acc, x] in a reduceO(n²) (copy-on-spread)
Query/RPC inside loop over n itemsO(n) round trips

When in doubt, ask: "As input doubles, does runtime roughly double (linear), quadruple (quadratic), or do something worse (exponential)?" That's the practical complexity class.

3. Fix — Apply the Pattern From the Matching Rule

Each reference file in references/ is a {category}-{slug}.md containing:

  • WHY the pattern matters (the cascade effect)
  • An Incorrect code example with the cost annotated
  • A Correct example with the minimal diff
  • When NOT to apply the fix (the rule has exceptions)

The minimal diff philosophy is intentional: the goal is for the agent to see exactly how few lines need to change to flip the complexity class.

Rule Categories by Priority

#CategoryPrefixImpactRules
1Nested Iteration Patternsnested-CRITICAL6
2Loop-Invariant I/O and N+1io-CRITICAL5
3Data Structure Mismatchds-HIGH6
4Recursion Complexityrec-HIGH5
5Redundant Computationcompute-MEDIUM-HIGH5
6Collection Buildingbuild-MEDIUM4
7Search & Sort Selectionsearch-MEDIUM4
8Space Complexity Trapsspace-LOW-MEDIUM4

See references/_sections.md for the full ordering rationale.

Quick Reference

1. Nested Iteration Patterns (CRITICAL)
2. Loop-Invariant I/O and N+1 Queries (CRITICAL)
3. Data Structure Mismatch (HIGH)
4. Recursion Complexity (HIGH)
5. Redundant Computation (MEDIUM-HIGH)
6. Collection Building (MEDIUM)
7. Search & Sort Selection (MEDIUM)
8. Space Complexity Traps (LOW-MEDIUM)

How to Use

  1. Start with the Find signal table above to locate the most likely pattern.
  2. Open the matching reference file for the WHY and the minimal-diff fix.
  3. If you're classifying complexity from scratch, use the Classify table to derive Big-O from code structure.
  4. When proposing a fix, quote the rule by file path so reviewers can verify the reasoning.
  5. See references/_sections.md for category ordering rationale, and assets/templates/_template.md when adding new rules.

Reference Files

FileDescription
references/_sections.mdCategory definitions, impact levels, and ordering rationale
assets/templates/_template.mdTemplate for adding new rules
metadata.jsonDiscipline, type, and source references

Related Skills

  • bug-review — Multi-pass PR bug review (this skill is a focused complement for performance issues specifically)
  • A language-specific best-practices skill (React, Python, Go) — covers idioms beyond Big-O; pair with this skill for performance-critical reviews

Comments

Markdown supported