agentleFS
Kappaemme-gitKappaemme-git/codex-complexity-optimizer/complexity-optimizer/SKILL.md

complexity-optimizer

Skill913 starsChanged 6 months agoMITView on GitHub

Analyze a software codebase for algorithmic complexity and performance hotspots, then propose or implement safe optimizations without breaking behavior. Use when Codex is asked to scan many files, find inefficient loops, nested iteration, repeated scans, costly rendering/recomputation, N+1 queries, avoidable O(n^2) or O(n) operations, or reduce complexity such as O(n^2) to O(n log n) / O(n), while preserving tests, APIs, outputs, and maintainability.

3 other projects use a version of this.

Adopted by

Most recently taken up by

  • Other versions3 projects use a version of this.

    Word for word · 1

    1. langgenius/mosoo-skills★ 2100% same

    Edited · 0

    None found.

    Wrote their own version · 2

    1. markoblogo/abvx-agent-skills★ 16same name
    2. themusecatcher/ai-coding-kit★ 2same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

The file

Show its rules and text

We split this skill into the rules it gives an agent

13 rules. About 0 are common, 9 are distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈9

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When the user asks to analyze, scan, audit, review, or "give me a report" for a codebase, produce the full complexity report automatically.

    line 14
  2. Distinctive:

    Only edit files when the user asks to implement, fix, optimize, apply, change, refactor, or otherwise clearly requests code modification.

    line 29
  3. Very specific:

    Run scripts/analyze_complexity.py <repo> for a first-pass hotspot list when scanning a repository.

    line 36
  4. Distinctive:

    Do not patch every warning.

    line 41
  5. Distinctive:

    If tests are absent and behavior is ambiguous, make the smallest refactor or ask for expected behavior before changing semantics.

    line 47
  6. Very specific:

    Run relevant tests and type/lint/build commands.

    line 56
  7. Distinctive:

    Add a micro-benchmark or measurement when the complexity improvement is non-obvious or performance-critical.

    line 57
  8. Distinctive:

    Use the bundled scanner from the skill directory:

    line 62
  9. Distinctive:

    If the scanner reports nothing, still inspect known hot paths manually.

    line 71
  10. Distinctive:

    Run the narrow test first, then the broadest relevant test/build command.

    line 86
  11. Distinctive:

    Keep the patch localized. Avoid formatting churn in unrelated files.

    line 88
  12. Very specific:

    Read references/optimization-playbook.md for common O(n^2) to O(n log n) / O(n) transformations and framework-specific patterns.

    line 92
  13. Very specific:

    Read references/report-template.md when preparing the final analysis or audit output.

    line 93

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Complexity Optimizer

Core Rule

Optimize only when the current behavior is understood and can be preserved. Prefer a small, proven improvement with tests over a broad rewrite with unclear correctness.

Default Behavior

When the user asks to analyze, scan, audit, review, or "give me a report" for a codebase, produce the full complexity report automatically. Do not require the user to specify report fields.

Default report contents:

  • Scope analyzed and detected stack/test commands.
  • Top findings ranked by likely impact.
  • File and line for each finding.
  • Current pattern and why it may be costly.
  • Estimated current complexity.
  • Recommended change.
  • Estimated complexity after the change.
  • Risk level.
  • Tests, benchmarks, or manual checks needed.
  • Clear statement that no files were modified, unless the user explicitly requested implementation.

Only edit files when the user asks to implement, fix, optimize, apply, change, refactor, or otherwise clearly requests code modification. If the user only asks for analysis or a report, do not modify files.

Workflow

  1. Establish the baseline:
    • Identify the language, framework, test command, build command, and performance-sensitive paths.
    • Inspect existing tests before touching code.
    • Run scripts/analyze_complexity.py <repo> for a first-pass hotspot list when scanning a repository.
  2. Rank opportunities:
    • Prioritize code on hot paths, large input paths, rendering loops, database/API loops, and shared utilities.
    • Separate algorithmic complexity from constant-factor cleanup.
    • Do not patch every warning. Treat scanner output as leads, not proof.
    • For report-only requests, inspect enough surrounding code to estimate current and proposed complexity; do not stop at raw scanner output.
  3. Prove behavior:
    • Locate or add focused tests for the function/component being changed.
    • Capture edge cases: empty input, duplicates, ordering stability, null/missing values, errors, permissions, pagination, time zones, and mutation side effects.
    • If tests are absent and behavior is ambiguous, make the smallest refactor or ask for expected behavior before changing semantics.
  4. Optimize conservatively:
    • Replace repeated linear lookup with maps/sets when key equality is stable.
    • Replace nested scans with indexing, grouping, two-pointer scans, sweep-line logic, binary search, memoization, batching, or precomputation only when the data shape supports it.
    • In UI code, reduce unnecessary renders with stable props, memoized derived data, virtualization, debounced work, and moving expensive work out of render paths.
    • In data access code, remove N+1 behavior with bulk fetches, joins, preloading, caching, or batching while preserving authorization and filtering.
  5. Verify:
    • Run relevant tests and type/lint/build commands.
    • Add a micro-benchmark or measurement when the complexity improvement is non-obvious or performance-critical.
    • Report the original complexity, new complexity, changed files, tests run, and any residual risk.

First-Pass Scanner

Use the bundled scanner from the skill directory:

python3 scripts/analyze_complexity.py /path/to/repo --format markdown
python3 scripts/analyze_complexity.py /path/to/repo --format json

The scanner flags common patterns in Python, JavaScript, TypeScript, JSX/TSX, Java, Go, C, C++, C#, Ruby, PHP, and Swift files. It intentionally favors readable leads over perfect static analysis.

If the scanner reports nothing, still inspect known hot paths manually. Rendering churn, database query patterns, and framework lifecycle issues often require repository-specific context.

Optimization Safety Checklist

Before editing:

  • Confirm the data sizes are large enough for complexity to matter.
  • Confirm the optimization preserves output ordering where callers may rely on it.
  • Confirm object identity, mutability, and reference sharing are not part of the public behavior.
  • Confirm caches have a valid invalidation strategy.
  • Confirm deduplication does not collapse distinct records that share a display label.
  • Confirm database batching preserves tenant, permission, soft-delete, pagination, and sorting constraints.

After editing:

  • Run the narrow test first, then the broadest relevant test/build command.
  • Compare before/after benchmark numbers when a benchmark exists or was added.
  • Keep the patch localized. Avoid formatting churn in unrelated files.

References

  • Read references/optimization-playbook.md for common O(n^2) to O(n log n) / O(n) transformations and framework-specific patterns.
  • Read references/report-template.md when preparing the final analysis or audit output.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.