Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

algorithmic-complexity-review

БесплатноБез исполняемых скриптовНе проверен

Algorithmic complexity (Big-O) review — finding nested loops, N+1 queries, exponential recursion, quadratic string builds, and other accidental complexity…

pproencaот pproenca★ 231 звезда на GitHub

Об этом скилле

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):

Signal Likely Category First Rule to Check
Two nested for loops nested- nested-explicit-quadratic-loops
.includes / .find / x in list inside a loop nested- 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-of io- io-sequential-await-in-loop
array.find to "join" two arrays ds- ds-hashmap-for-keyed-access
Recursive function with overlapping arguments rec- rec-memoize-overlapping-subproblems
s = s + part or [...acc, x] in a loop build- build-avoid-quadratic-string-concat, build-avoid-spread-in-reducer
sorted(...) called inside a loop search- search-sort-once-outside-loop
readlines() / loading whole files space- space-stream-dont-load

2. Classify — Derive the Big-O

Compute complexity from the code structure:

Structure Complexity
Single loop over n items, O(1) body O(n)
Two nested loops over n / m items O(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 memoization O(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 loop O(n²) (string immutability)
[...acc, x] in a reduce O(n²) (copy-on-spread)
Query/RPC inside loop over n items O(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

# Category Prefix Impact Rules
1 Nested Iteration Patterns nested- CRITICAL 6
2 Loop-Invariant I/O and N+1 io- CRITICAL 5
3 Data Structure Mismatch ds- HIGH 6
4 Recursion Complexity rec- HIGH 5
5 Redundant Computation compute- MEDIUM-HIGH 5
6 Collection Building build- MEDIUM 4
7 Search & Sort Selection search- MEDIUM 4
8 Space Complexity Traps space- LOW-MEDIUM 4

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

Quick Reference

1. Nested Iteration Patterns (CRITICAL)

Полный SKILL.md на GitHub

Установить algorithmic-complexity-review в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

AGENTS.mdREADME.mdassets/templates/_template.mdmetadata.jsonreferences/_sections.mdreferences/build-avoid-immutable-object-spread.mdreferences/build-avoid-quadratic-string-concat.mdreferences/build-avoid-spread-in-reducer.mdreferences/build-presize-when-length-known.mdreferences/compute-cache-expensive-pure-results.mdreferences/compute-cache-property-lookup.mdreferences/compute-defer-or-short-circuit.mdreferences/compute-hoist-loop-invariants.mdreferences/compute-precompile-regex.mdreferences/ds-counter-for-histograms.mdreferences/ds-deque-for-front-operations.mdreferences/ds-hashmap-for-keyed-access.mdreferences/ds-heap-for-top-k.mdreferences/ds-sorted-structure-for-range-queries.mdreferences/ds-trie-for-prefix-search.mdreferences/io-batch-instead-of-per-item.mdreferences/io-file-read-in-loop.mdreferences/io-missing-eager-load.mdreferences/io-n-plus-one-query.mdreferences/io-sequential-await-in-loop.mdreferences/nested-cartesian-comparison.mdreferences/nested-explicit-quadratic-loops.mdreferences/nested-find-in-loop.mdreferences/nested-includes-in-loop.mdreferences/nested-set-operations-on-arrays.mdreferences/nested-substring-search-in-loop.mdreferences/rec-iterative-for-deep-recursion.mdreferences/rec-memoize-overlapping-subproblems.mdreferences/rec-prune-with-bounds.mdreferences/rec-share-memo-across-top-level-calls.mdreferences/rec-tabulate-bottom-up.mdreferences/search-binary-search-on-sorted.mdreferences/search-build-index-once-amortize.mdreferences/search-quickselect-not-full-sort.mdreferences/search-sort-once-outside-loop.md

FAQ

Что делает скилл algorithmic-complexity-review?

Algorithmic complexity (Big-O) review — finding nested loops, N+1 queries, exponential recursion, quadratic string builds, and other accidental complexity blowups. Covers Python, JavaScript/TypeScript, Java, Go, and similar languages. Use whenever writing, reviewing, or refactoring code where Big-O matters. Trigger even when the user doesn't mention "Big-O" explicitly — if they're reviewing code for performance, refactoring a hot path, asking "why is this slow," or working with data that scales (loops, recursions, collections, ORM access), apply this skill to classify the time/space complexity and suggest the fix. Especially trigger on tasks like "review for performance," "find slow code," "make this faster," "this code is O(n²)," or when reading code that processes collections.

Как установить скилл algorithmic-complexity-review?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл algorithmic-complexity-review запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить algorithmic-complexity-review с