Saltar al contenido
Skillpedia
Programación general48 mil · #4223

complexity-cuts

Qué hace

'complexity-cuts' te ayuda a que tu código sea más rápido y eficiente. Busca partes del código que son lentas o que consumen demasiada memoria y sugiere mejoras, una a una, asegurándose de que todo siga funcionando igual que antes.

Cuándo usarla

  • ✓Tu código es lento con grandes cantidades de datos.
  • ✓Tu programa se cae o usa demasiada memoria.
  • ✓Necesitas optimizar código que ya existe.

Link de la skill

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

Cópialo y pégalo en tu IA (Claude, ChatGPT o Cursor) pidiéndole que siga las instrucciones.

Cómo usar

La forma más fácil: copia el mensaje y pégalo en tu IA. Ella lee la skill y sigue las instrucciones.

Mensaje listo para pegar

Usa esta skill para ayudarme: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/complexity-cuts/SKILL.md Lee el archivo SKILL.md de ese link y sigue sus instrucciones en mi tarea.
¿Quieres que tu IA encuentre skills como esta por sí sola?Instala el MCP gratis de Skillpedia: una línea, y busca entre 15.000+ skills antes de cada tarea.Instalar en 1 minuto →

Ejemplo de qué pedirle a la IA

“¿Cómo puedo hacer más rápido este código? Tarda demasiado en procesar listas grandes.”

5 skills nuevas por semana. 1 minuto de lectura.

Cómo funciona

Analiza tu código para encontrar cuellos de botella (puntos lentos) y sugiere cambios concretos. Cada cambio se prueba para asegurarse de que el código no se rompa. Si un cambio falla, se deshace automáticamente.

Contenido técnico (SKILL.md original)

Texto original del autor, en inglés, directo de 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)

…

Preguntas frecuentes

¿Qué es 'Big-O'?

Es una forma de describir cuánto aumenta el tiempo de ejecución del código a medida que crecen los datos. Por ejemplo, 'O(n²)' significa que si duplicas los datos, el tiempo podría cuadruplicarse.

¿Qué pasa si el código no tiene pruebas?

Antes de hacer cualquier cambio, necesitas crear una prueba sencilla que muestre cómo funciona el código ahora. Solo entonces intentas la optimización y compruebas que la prueba sigue pasando.

¿Puedo hacer varios cambios a la vez?

No. 'complexity-cuts' exige que los cambios se hagan uno a uno. Así se puede identificar qué cambio produjo la mejora y se evita que el código se rompa sin saber por qué.

Detalles

Descripción original del autor

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

Popularidad

Estrellas en GitHub
48 mil
Posición en el ranking
#4223
Licencia
MIT
Actualizada
15/10/2026

¿Te sirve esta skill?

0

Entra para votar.

Comentarios

  • …

Más skills de este repositorio

Skills parecidas