Defect
JSON.stringify(value, replacerArray) preserves first occurrence order by scanning the complete accepted PropertyList for every string/number wrapper entry. A unique user-controlled replacer array therefore performs Θ(n²) byte comparisons before serialization.
A production ReleaseFast growth witness using unique keys measured 2k → 4k → 8k → 16k entries at 0.03s → 0.21s → 1.15s → 5.11s user time while producing the correct output.
Implementation
- Keep the ordered PropertyList required by ECMA-262.
- Add invocation-local content membership so duplicates are rejected without rescanning prior entries.
- Preserve coercion/getter order, String/Number wrapper behavior, encoded property keys, first-occurrence order, OOM propagation, and no-GIL isolation.
Acceptance
- Tests cover unique keys, duplicates, encoded keys, numbers, wrappers with observable coercion, ignored values, and throwing accessors/coercions.
- A deterministic growth row demonstrates near-linear membership work rather than quadratic scanning.
- Focused normal + TSan, full unit, and JSON.stringify test262 pass with zero regressions.
- Exact-parent evidence records CPU and memory impact with matching output/checksum identity.