Will It Vibe logoWill It Vibe?
PERF-003Low severity-4 points

Array search call inside a loop body

Part of Code Quality & Syntax, which counts for 20% of the overall score. When this check fires it deducts 4 points from that category, once per scan, no matter how many places it turns up.

What it detects

A loop body calls .find()/.includes()/.indexOf() on an array, so each of the n loop iterations does its own O(m) linear scan (O(n*m) total). Heuristic: it cannot confirm the array size or that it is populated outside the loop; for a small array this is harmless. Building a Map or Set once before the loop turns repeated lookups into O(1).

Why it matters

When a loop body calls array.find(), array.includes(), or array.indexOf() on some array, each of the n loop iterations does its own linear scan of that array, so the total work is proportional to n times the array length instead of n. On small arrays this is invisible; on large ones (thousands of rows against thousands of lookups) it becomes a real, measurable slowdown that gets worse as both grow. This detector cannot confirm the array size or that it was actually built outside the loop, so treat it as a prompt to check, not a certainty.

How to fix it

If the array being searched does not change during the loop, build a Map (keyed by whatever field you search on) or a Set once before the loop, then do O(1) lookups inside it. This turns O(n*m) into O(n+m).

The paid report includes a ready-to-paste prompt for your AI coding agent for every check it finds, pointed at the exact findings from your scan. See pricing

Does your repo trip this check?

Paste a GitHub URL or drop a project folder. Scans run in your browser and take seconds.

Scan your repo

Related Code Quality & Syntax checks