Skip to content
Back to skills

Coding

ASecurity

Estimate Big-O time complexity of code via static analysis (tree-sitter MCP).

  • 23 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added October 14, 2026
developmentjavascripttypescriptpythongojavaphpkotlinreactnodeexpress

Works with

  • mcp

Security analysis

A100/100

Pro scans all 21 files and shows the line behind each finding

Scanned October 14, 2026

npx -y skills add andreibesleaga/GABBE --skill coding --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Coding?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Coding
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/andreibesleaga-coding-b8590afc/badge)](https://www.skillsdirectory.com/skills/andreibesleaga-coding-b8590afc)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: time-complexity
description: Estimate Big-O time complexity of code via static analysis (tree-sitter MCP).
triggers: [complexity, big-o, performance, hotspot, time complexity, analyze complexity]
tags: [coding, performance, analysis]
context_cost: medium
---
# Time Complexity Skill

## Goal
Estimate Big-O time complexity of functions, files, directories, or entire GitHub repositories using the **time-complexity-mcp** server — a static-analysis engine powered by tree-sitter. No code execution; code is parsed into ASTs and inspected.

## Prerequisites
- **MCP Server**: `time-complexity` must be configured in your MCP config (see `templates/core/MCP_CONFIG_TEMPLATE.json`).
- **Runtime**: Node.js 18+ on the host machine.
- **Optional**: `git` in PATH (required only for `analyze_github_repo`).

## Supported Languages
JavaScript (`.js`, `.mjs`, `.cjs`, `.jsx`), TypeScript (`.ts`, `.tsx`), Python (`.py`), Java (`.java`), Go (`.go`), PHP (`.php`), Dart (`.dart`), Kotlin (`.kt`, `.kts`).

## Capabilities

### 1. MCP Tools Available
| Tool | Purpose |
|---|---|
| `analyze_file` | Analyze all functions in a single source file |
| `analyze_function` | Analyze a specific named function in a file |
| `analyze_directory` | Scan an entire directory for complexity hotspots |
| `analyze_github_repo` | Clone and analyze a public GitHub repo (requires `git`) |
| `get_supported_languages` | List all file extensions the server can parse |

### 2. What It Detects
- **Loop nesting** — `for`, `while`, `do-while` with depth tracking. Constant-bound loops (e.g., `for i in range(10)`) recognized as O(1).
- **Recursion** — Linear recursion (O(n)) vs branching recursion like Fibonacci (O(2^n)).
- **Known stdlib methods** — `.sort()` as O(n log n), `.filter()`/`.map()` as O(n), `.push()`/`.pop()` as O(1). Each language has its own patterns.
- **Combined complexity** — An O(n) method inside an O(n) loop correctly reports O(n²).

### 3. Output Format
Results include per-function complexity with:
- **Function name and line range**
- **Big-O classification** (O(1), O(n), O(n log n), O(n²), O(n³), O(2^n))
- **Reasoning** (loop counts, nesting depth, recursion type)
- **Line-level annotations** (which line contributes which complexity)

## Steps

1. **Scope the analysis**
   - Single function → `analyze_function`
   - Entire file → `analyze_file`
   - Directory / codebase → `analyze_directory`
   - External repo → `analyze_github_repo`

2. **Interpret results**
   - Focus on functions with O(n²) or worse — these are performance hotspots.
   - Check line annotations to understand *where* complexity accumulates.
   - Verify constant-bound loops are correctly recognized as O(1).

3. **Act on findings**
   - Use `refactor.skill` to restructure high-complexity functions.
   - Use `performant-*.skill` for language-specific optimizations.
   - Document findings in `TIME_COMPLEXITY_REPORT_TEMPLATE.md`.

4. **Integrate into workflow**
   - Run before code reviews (`code-review.skill`) to flag regression.
   - Run on PR diffs to catch new O(n²)+ code.
   - Run on full codebase periodically to track complexity trends.

## Deliverables
- `TIME_COMPLEXITY_REPORT_TEMPLATE.md`: Structured complexity analysis with hotspots and recommendations.

## Usage Examples

### Analyze a single file
```
> Analyze the complexity of src/utils/sort.ts
```

### Analyze a specific function
```
> What's the complexity of the fibonacci function in recursion.py?
```

### Scan an entire codebase for hotspots
```
> Scan src/ for complexity hotspots
```

### Analyze a GitHub repository
```
> Analyze the complexity of facebook/react
```

### Focus on a subdirectory of a remote repo
```
> Analyze https://github.com/expressjs/express, focus on the lib/ directory
```

## Security & Guardrails

### 1. Skill Security (Time Complexity)
- **Static Analysis Only**: Code is parsed into ASTs and inspected — never evaluated, executed, or imported. No risk of running malicious code.
- **Read-Only File Access**: Source files are read for parsing. Nothing is written, modified, or deleted.
- **Scope Limiting**: When analyzing directories, be aware of repo size. For very large codebases, scope to specific subdirectories.

### 2. System Integration Security
- **Network Access (opt-in)**: The `analyze_github_repo` tool invokes `git clone` to fetch public GitHub repos. All other tools run locally with no network access. Clone URLs are restricted to HTTPS GitHub URLs only.
- **No Secrets Exposure**: The tool does not process environment variables, config files, or secrets — only source code syntax.

### 3. LLM & Agent Guardrails
- **Over-reliance on Static Analysis**: Big-O from static analysis is an *estimate*. It cannot account for runtime data distributions, caching effects, or algorithm-specific constants. Always note: "Static estimate — verify with runtime profiling for critical paths."
- **False Precision**: The tool may report O(n) for a function that is effectively O(1) due to bounded inputs in practice. Do not blindly optimize functions flagged as complex without considering real-world usage context.
- **Hallucinated Remediation**: When suggesting fixes for high-complexity functions, the agent must provide concrete, tested alternatives — not theoretical rewrites that may introduce bugs.

Files in this skill

  • agent-trajectory-eval.skill.md5.7 KB
  • artisan-commands.skill.md3.7 KB
  • browser-tdd.skill.md7 KB
  • chaos-fault-injection.skill.md8.1 KB
  • ci-autofix.skill.md4.2 KB
  • clean-coder.skill.md4.5 KB
  • code-review.skill.md6.1 KB
  • debug.skill.md6.5 KB
  • documentation.skill.md7.3 KB
  • eval-driven-development.skill.md6.9 KB
  • evals/code-review.eval.yaml1 KB
  • excalidraw.skill.md3.7 KB
  • file-processing.skill.md4.3 KB
  • git-workflow.skill.md7.2 KB
  • metamorphic-testing.skill.md7.8 KB
  • mobile-dev.skill.md4.2 KB
  • nodejs-expert.skill.md1.6 KB
  • output-validation.skill.md5.4 KB
  • pbt-strategy.skill.md8 KB
  • performant-ai.skill.md3.7 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.