본문으로 건너뛰기
Skillpedia
일반 코딩48k · #4223

complexity-cuts

하는 일

‘complexity-cuts’는 코드를 더 빠르고 효율적으로 만들도록 돕습니다. 느리거나 메모리를 너무 많이 쓰는 코드 부분을 찾아내고, 한 번에 하나씩 개선을 제안하며, 모든 것이 이전처럼 동작하는지 확인합니다.

사용하는 경우

  • ✓데이터가 많을 때 코드가 느릴 때.
  • ✓프로그램이 충돌하거나 메모리를 너무 많이 쓸 때.
  • ✓기존 코드를 최적화해야 하는 경우.

스킬 링크

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/complexity-cuts/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/complexity-cuts/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“이 코드를 더 빠르게 만들려면 어떻게 해야 할까요? 큰 리스트를 처리하는 데 너무 오래 걸려요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

도구는 코드를 분석해 병목(느린 지점)을 찾고 구체적인 변경을 제안합니다. 각 변경은 코드가 깨지지 않는지 테스트합니다. 변경이 실패하면 자동으로 되돌립니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

complexity-cuts — Lower Big-O on Existing Code

lemmaly prevents bad complexity before code is written. complexity-cuts fixes it after the fact: code already exists, it works, but its time or space complexity is worse than necessary.

Violating the letter of these rules is violating the spirit of the skill. Adapting "just a little" is how a faster-but-wrong rewrite ships.

When to Use This Skill

Use complexity-cuts when refactoring existing code that has poor Big-O:

  • Nested loops, O(n²) or worse scans, repeated work, redundant allocations, blown memory.
  • Stated symptoms: "this is slow on large inputs", "times out", "OOM", "too much memory", "reduce complexity", "optimize this algorithm".
  • N+1 query patterns in ORMs (Prisma, Drizzle, SQLAlchemy, Django, ActiveRecord).
  • await inside for over independent items causing serial latency.

For preventing bad complexity before code is written, use lemmaly. For math-level optimizations (Bloom, HLL, FFT, JL projection), escalate to mathguard.

The Iron Law

NO TRANSFORMATION WITHOUT EXISTING TESTS GREEN BEFORE AND AFTER

If the code has no tests, you write a characterization test first (golden input → current output). Then transform. Then verify the test still passes. If you skip this, the optimization can silently break callers — and faster-but-wrong is worse than slow-and-right.

Non-negotiable rules

  1. State current and target Big-O before touching code. In one line:

    • Current: time = O(?), space = O(?)
    • Target: time = O(?), space = O(?)
    • Dominant input dimension (n = what, how large in practice)

    If you cannot state current Big-O, you do not yet understand the code. Read more.

  2. Identify the bottleneck, do not guess. Point to the exact line(s) responsible for the dominant term. Nested loop? Repeated linear scan? Recomputation? Allocation inside a hot loop? The fix lives there, not elsewhere.

  3. One transformation at a time, with a verify-revert-stop loop. The loop is:

    1. Apply exactly one transformation from the playbook.
    2. Run the existing test suite (or the characterization test you wrote per the Iron Law).
    3. If any test breaks: revert immediately. Do not patch the test. Do not patch around the failure. Revert.
    4. Count reverts on this piece of code. If 3 reverts in a row, STOP optimizing. The bottleneck is wrong, the transformation is wrong, or the code has invariants you have not modeled. Escalate to invariant-guard and write the missing contract — do not try a fourth transformation.
    5. Only after a transformation lands green: pick the next one.

    Stacked changes hide regressions. Patched tests hide regressions louder.

  4. Preserve semantics exactly. Lower complexity must not change outputs, ordering guarantees, stability, or error behavior. If the optimization requires a semantic change (e.g. unordered output), call it out explicitly and confirm it is acceptable.

  5. No invented numbers. Never write "10x faster" or "saves 200MB" without measuring. Write <measured: TBD> and move on, or actually measure with a representative input.

  6. Always report the measured speedup ratio after a transformation lands. Once the new code is green, run a representative benchmark (same input, same machine, warm cache) and report before → after plus the ratio as N× faster (or N× less memory). One line, attached to the diff:

    p50:  186 ms → 1.1 ms   (169× faster, n=20,000, 200 samples)
    

    If you cannot measure (e.g. the win is purely asymptotic on inputs you don't have), say so explicitly: asymptotic only, no measurement — O(n²) → O(n). Never silently skip this step.

The transformation playbook

The vast majority of real-world Big-O wins come from a small set of moves. Try them in this order:

Time-complexity reductions

Smell Fix Typical win
for x in A: if x in B where B is list/array Convert B to Set/Map once O(n·m) → O(n+m)
Nested loop computing pairs/joins Hash-join on the key; index by lookup field O(n·m) → O(n+m)
Repeated .find / .indexOf / .includes inside a loop Precompute index Map<key, item> outside loop O(n^2) → O(n)
Repeated recomputation of same value Memoize / cache by input key O(n·f(n)) → O(n + f(n))
Sort inside a loop Sort once outside O(n^2 log n) → O(n log n)

…

자주 묻는 질문

‘Big-O’란 무엇인가요?

데이터가 늘어날 때 코드가 얼마나 빨리 느려지는지 설명하는 방식입니다. 예를 들어 ‘O(n²)’은 데이터를 두 배로 늘리면 시간이 네 배가 될 수 있다는 뜻입니다.

코드에 테스트가 없으면 어떻게 하나요?

어떤 변경이든 하기 전에, 현재 코드가 어떻게 동작하는지 보여 주는 간단한 테스트를 먼저 만들어야 합니다. 그 다음에 최적화를 시도하고 테스트가 여전히 통과하는지 확인합니다.

여러 변경을 한 번에 할 수 있나요?

아니요. ‘complexity-cuts’는 변경을 한 번에 하나씩 하도록 요구합니다. 이렇게 해야 어떤 변경이 개선을 가져왔는지 알 수 있고, 이유를 모른 채 코드가 깨지는 것을 막을 수 있습니다.

상세 정보

작성자의 원본 설명

Lower Big-O on existing code via a one-transformation-at-a-time playbook with verify-revert-stop. For new code use lemmaly; for math-level wins escalate to mathguard.

repo: sickn33/agentic-awesome-skills

인기도

GitHub 스타
48k
순위
#4223
라이선스
MIT
업데이트
2026. 10. 15.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬