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

String += concatenation inside a for loop

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 variable is rebuilt with += inside a for loop and the appended value looks like a string or raw-string literal, the classic result += piece antipattern. Go strings are immutable, so each += allocates a new backing array, making the loop O(n^2) in the total length. Heuristic: a quote or backtick in the appended value is required to avoid flagging numeric accumulators. strings.Builder (or bytes.Buffer) writes in place and is linear.

Why it matters

Go strings are immutable, so result += piece inside a for loop allocates a new backing array and copies the old contents into it on every single iteration, making the total work O(n^2) in the final string's length instead of O(n). This is idiomatic-Go's best-known gotcha for anyone coming from a language where in-place string mutation is normal. This detector requires the appended value to look like a string or raw-string literal to avoid flagging numeric accumulators.

How to fix it

Use a strings.Builder (or bytes.Buffer): call builder.WriteString(piece) inside the loop instead of +=, then builder.String() once after the loop to get the final result. Builder grows its internal buffer geometrically, so the total work is linear.

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