XPerf
LanguagesPHP

PHP performance guide (v0)

Fewer quadratic builders, quieter hot paths.

Scope: PHP 8+. Speedup claims cite a local bench, an upstream source, or are marked provisional. Corpus residual counts are lint hit counts, not wall-time savings.

Profile first (hrtime, Blackfire, Xdebug). Extensions and JIT differ — re-bench.

Contents

1. Strings and arrays

$s .= $piece in a loop can still be costly at scale; prefer collectors + implode. Repeated $a = array_merge($a, …) copies; prefer $a[] = $item.

Lint: ph-string-dot-hot (default off); ph-array-merge-rebind (default error).

2. Hot I/O

echo / print in a tight loop flushes. Gate debug output or buffer.

Lint: ph-echo-hot (default hint).

Lint map

IDSmellDefault
ph-string-dot-hotstring .= in loopoff
ph-array-merge-rebindarray_merge rebinding in looperror
ph-echo-hotecho / print in loophint

Escalate only with evidence/ph-*.jsonl — see evidence-policy.md.

References