scale-canary
Performance complexity and resource allocation canary — checks for O(N^2) loops, database N+1 query patterns, memory leaks (unbounded collections), and blocking calls in main event loop. Triggers on keywords: "/scale-canary", "scale-canary", "performance audit", "scale audit". Us
Install
npx skills add https://github.com/TheColliery/CoalMine/tree/main/skills/scale-canary
claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install hetcreep-coalmine@llmmart
git clone https://github.com/TheColliery/CoalMine.git
The skills CLI installs just this skill, for any of its supported agents. Claude Code installs the whole hetcreep/coalmine collection as a plugin from our marketplace. Git is the plain clone.
Skill manifest
Scale Canary (Performance & Resource Allocation Audit)
Audit code for scalability issues, performance bottlenecks, and resource leaks.
Auditing Categories
- O(N^2) Complexity — nested loops over growable collections without indexing or caching (crashes at scale).
- N+1 Database Queries — querying records in a loop instead of a batch JOIN or bulk prefetch.
- Memory Bloat / Leaks — appending to global arrays/maps without clearing them → unbounded growth.
- Blocking Main Loop — synchronous FS ops or CPU-heavy work on the main event thread (lag/hangs).
- Resource Leakage — streams, connections, or handles left open without a
finallyclose.
Per-ORM N+1 shapes, per-stack blocking patterns, and what NOT to flag: read references/checks.md before scanning.
Fix mode (choice-gated)
In Agent Context, after the report, present via ask_question:
- Apply safe optimizations: async-ify synchronous file ops; insert
finallyblocks for stream closing. Each fix: checkpoint (git stash/commit in a git repo; else copy the file aside — never assume git) → apply → build + tests → auto-revert if newly red. - Let me pick: user selects specific optimizations.
- Report only: exit unchanged.
Grants & denials (CLASSIFY-BLOCK)
| class | step it powers | grant | on denial |
|---|---|---|---|
| read | scan loops/queries/caches for the categories above | Read·Grep·Glob |
refuse that file, name it — never a clean bill |
| write | Fix mode's safe-optimization apply, incl. checkpoint → build+tests → auto-revert if newly red | Edit·Bash (checkpoint/build/revert need exec) |
report the fix as NOT applied AND the checkpoint/revert as NOT available, never claim done |
Output
| file:line | bottleneck | severity | finding | optimization plan |
Severity: CRITICAL (O(N^2) on user-facing API / unclosed file handles) · HIGH (N+1 query pattern / blocking main loop) · MEDIUM (unbounded cache growth) · LOW (minor efficiency suggestions)
Files (coalmine)
-
references
-
checks.md 2 KB
<!-- coalmine: verified 2026-06-12 · revalidate 90d · definition file for scale-canary --> # Scale canary — concrete detection procedures ## 1. O(N²) on growable data - Nested loops where the inner iterates a collection that grows with usage (users, orders, files) — `for ... { for ... { } }`, `.filter().map()` inside `.forEach`, `Where` inside `foreach`. - `Array.includes`/`indexOf`/`list.Contains` inside a loop over another list → suggest Set/Dictionary index (O(N²)→O(N)). - Only flag when N is unbounded user data; fixed small enums are fine. ## 2. N+1 queries (per-ORM shapes) | ORM | Smell | Fix | |---|---|---| | EF Core | navigation property access in a loop (lazy load) | `.Include()` / projection | | Prisma | `findUnique`/`findMany` inside `for`/`map` over rows | single `findMany({ where: { in } })` / `include` | | Sequelize | per-row `.get...()` association calls | `include` eager load | | Django | attribute access on FK in template/loop | `select_related`/`prefetch_related` | | Raw SQL | query call inside loop | batch `IN (...)` / JOIN | ## 3. Memory bloat / unbounded growth - Appends to module/global collections that never clear: `cache.push(...)`, `dict[key] = ...` in long-lived process without eviction/TTL. - Event listeners/subscriptions added per request and never removed. - Caches: flag any hand-rolled cache without max-size or TTL. ## 4. Blocking the main/event loop | Stack | Patterns | |---|---| | Node | `fs.*Sync`, `child_process.execSync`, `crypto.pbkdf2Sync`, JSON.parse on multi-MB payloads — inside server handlers | | C# | `.Result`, `.Wait()`, `Task.Run(...).Result` in async context (deadlock + thread starvation) | | Python (async) | sync `requests`/file I/O inside `async def` without `to_thread` | | UI apps | disk/network on UI thread | - CLI/startup code may legitimately use sync I/O — scope to request/event paths. ## 5. Resource leakage - Streams/connections/handles opened without `using`/`try-finally`/`with`/`defer` close. - Pools: connections acquired and returned on the happy path only — check the error path.
-
-
skill-meta.json 195 B
{ "lightIntent": "Spot performance check, hot paths only", "standardIntent": "Balanced scalability audit, multi-category", "heavyIntent": "Full 5-category audit + adversarial profiling verify" } -
SKILL.md 2.5 KB
--- name: scale-canary description: >- Performance complexity and resource allocation canary — checks for O(N^2) loops, database N+1 query patterns, memory leaks (unbounded collections), and blocking calls in main event loop. Triggers on keywords: "/scale-canary", "scale-canary", "performance audit", "scale audit". Use when writing loops over growing data, DB queries, caches, or async/event-loop code. --- # Scale Canary (Performance & Resource Allocation Audit) <!-- SHARED:LANGUAGE_HEADER --> Audit code for scalability issues, performance bottlenecks, and resource leaks. ## Auditing Categories 1. **O(N^2) Complexity** — nested loops over growable collections without indexing or caching (crashes at scale). 2. **N+1 Database Queries** — querying records in a loop instead of a batch JOIN or bulk prefetch. 3. **Memory Bloat / Leaks** — appending to global arrays/maps without clearing them → unbounded growth. 4. **Blocking Main Loop** — synchronous FS ops or CPU-heavy work on the main event thread (lag/hangs). 5. **Resource Leakage** — streams, connections, or handles left open without a `finally` close. Per-ORM N+1 shapes, per-stack blocking patterns, and what NOT to flag: read `references/checks.md` before scanning. ## Fix mode (choice-gated) In Agent Context, after the report, present via `ask_question`: - **Apply safe optimizations:** async-ify synchronous file ops; insert `finally` blocks for stream closing. Each fix: checkpoint (git stash/commit in a git repo; else copy the file aside — never assume git) → apply → build + tests → auto-revert if newly red. - **Let me pick:** user selects specific optimizations. - **Report only:** exit unchanged. ## Grants & denials (CLASSIFY-BLOCK) | class | step it powers | grant | on denial | |---|---|---|---| | read | scan loops/queries/caches for the categories above | `Read`·`Grep`·`Glob` | refuse that file, name it — never a clean bill | | write | Fix mode's safe-optimization apply, incl. checkpoint → build+tests → auto-revert if newly red | `Edit`·`Bash` (checkpoint/build/revert need exec) | report the fix as NOT applied AND the checkpoint/revert as NOT available, never claim done | <!-- SHARED:CLASSIFY_BLOCK --> ## Output `| file:line | bottleneck | severity | finding | optimization plan |` Severity: CRITICAL (O(N^2) on user-facing API / unclosed file handles) · HIGH (N+1 query pattern / blocking main loop) · MEDIUM (unbounded cache growth) · LOW (minor efficiency suggestions) <!-- SHARED:REPORTING_FOOTER --> <!-- SHARED:ORCHESTRATION --> <!-- SHARED:ESCALATION_FOOTER -->
Comments (0)
Sign in to join the conversation.
Reviews (0)
No reviews yet.
No comments yet.