complexity-cuts
Helps your agent optimize code to be faster. It makes small changes and checks if everything still works. Useful for improving program performance.
What it does
'complexity-cuts' helps make your code faster and more efficient. It finds parts of the code that are slow or use too much memory and suggests improvements, one at a time, ensuring everything still works as before.
When to use it
- ✓Your code is slow with large amounts of data.
- ✓Your program crashes or uses too much memory.
- ✓You need to optimize existing code.
Example of what to ask your AI
“How can I make this code faster? It's taking too long to process large lists.”
Want more? Open the sections below.
How to use
The easiest way: copy the message below and paste it into Claude, ChatGPT, Cursor or any AI. It reads the skill and follows the instructions.
Skill link
Ready-to-paste message
How it works
It analyzes your code to find bottlenecks (slow points) and suggests specific changes. Each change is tested to ensure the code doesn't break. If a change fails, it's automatically undone.
Installation
Easiest way: copy the skill link and paste it into Claude, ChatGPT or Cursor asking it to follow the instructions.
In the terminal (Claude Code, Codex, Cursor), in your project folder:
npx skills add sickn33/agentic-awesome-skills --skill complexity-cutsOr download just the file:
curl -L https://raw.githubusercontent.com/sickn33/agentic-awesome-skills/main/plugins/agentic-awesome-skills-claude/skills/complexity-cuts/SKILL.md -o SKILL.mdTechnical content (original SKILL.md)
Original text by the author, straight from 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).
awaitinsideforover 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
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.
- Current:
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.
One transformation at a time, with a verify-revert-stop loop. The loop is:
- Apply exactly one transformation from the playbook.
- Run the existing test suite (or the characterization test you wrote per the Iron Law).
- If any test breaks: revert immediately. Do not patch the test. Do not patch around the failure. Revert.
- 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-guardand write the missing contract — do not try a fourth transformation. - Only after a transformation lands green: pick the next one.
Stacked changes hide regressions. Patched tests hide regressions louder.
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.
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.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 → afterplus the ratio asN× faster(orN× 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) |
…
FAQ
What is 'Big-O'?
It's a way to describe how quickly code slows down as the amount of data increases. For example, 'O(n²)' means if you double the data, the time might quadruple.
What if the code has no tests?
Before making any changes, you need to create a simple test that shows how the code works now. Only then do you attempt the optimization and check if the test still passes.
Can I make multiple changes at once?
No. 'complexity-cuts' requires changes to be made one at a time. This helps identify which change brought the improvement and prevents the code from breaking without knowing why.
Details
Original description by the author
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.
Popularity
- GitHub stars
- 48k
- Ranking position
- #2609
- License
- MIT
- Updated
- 10/15/2026
Comments
- …
More skills from this repository
00-andruia-consultant
Helps your agent start or improve AI projects. It analyzes code, suggests tools, and creates action plans in Spanish.
sickn33/agentic-awesome-skills
007
Lets your agent perform security audits and threat modeling. It's useful for protecting projects against attacks and vulnerabilities.
sickn33/agentic-awesome-skills
10-andruia-skill-smith
Helps your agent create or improve AI tools. It defines how tools work, writes documentation, and validates the structure.
sickn33/agentic-awesome-skills
20-andruia-niche-intelligence
Lets your agent create a summary about a specific industry. It's useful for understanding the context, rules, usage patterns, and risks of a project, using reliable sources.
sickn33/agentic-awesome-skills
Similar skills
benchmark-optimization-loop
Has your agent improve something's speed in a measured way. It tests multiple versions and chooses the fastest one that still works correctly.
affaan-m/ECC
change-impact
Helps your agent analyze the impact of code changes before making them. It compares the planned vs. actual results afterward, covering paths, data, tests, and documentation. Useful for risky or system-wide changes.
affaan-m/ECC
click-path-audit
Lets your agent trace all user buttons and interactions to find bugs. It finds issues where functions seem to work alone but fail together. Useful when bugs persist even after debugging.
affaan-m/ECC