Hypothesis
The ANSI color prefix string in formatArgs (node.js lines 171-175) is recomputed on every enabled call, but depends only on this.color and this.namespace which are fixed at instance creation. Caching it at init time eliminates per-call string concatenation.
Rationale
Every enabled call rebuilds:
- colorCode = '\u001B[3' + (c < 8 ? c : '8;5;' + c)
- prefix = ' ${colorCode};1m${name} \u001B[0m'
These are pure functions of color and namespace. Computing once at init and storing as debug._colorPrefix saves 2-3 string concatenations per enabled call (200K times in the benchmark).
Scope
- src/node.js init() (lines 231-238): compute and store prefix string on debug instance
- src/node.js formatArgs() (lines 167-180): use cached prefix instead of recomputing
Expected impact
Moderate. Eliminates per-call string alloc for the prefix. The suffix still varies by diff so it cannot be cached.
Risks
Low. The color and namespace are immutable once the debug instance is created.
Hypothesis
The ANSI color prefix string in formatArgs (node.js lines 171-175) is recomputed on every enabled call, but depends only on this.color and this.namespace which are fixed at instance creation. Caching it at init time eliminates per-call string concatenation.
Rationale
Every enabled call rebuilds:
These are pure functions of color and namespace. Computing once at init and storing as debug._colorPrefix saves 2-3 string concatenations per enabled call (200K times in the benchmark).
Scope
Expected impact
Moderate. Eliminates per-call string alloc for the prefix. The suffix still varies by diff so it cannot be cached.
Risks
Low. The color and namespace are immutable once the debug instance is created.