Fixing Ill‐Formed UTF ‐16 Strings With SIMD Instructions
ABSTRACT Background We must fix ill‐formed UTF‐16 strings, where surrogate pairs are mismatched. Programming languages such as JavaScript provide functions that replace mismatched surrogates with the Unicode replacement character (U + FFFD). Objectives We seek to accelerate the correction of ill‐formed UTF‐16 strings. Methods We propose using Single Instruction, Multiple Data (SIMD) instructions to handle multiple code units in parallel, enabling faster and more efficient execution. We provide implementations for ARM NEON and x64 (SSE, AVX2, AVX‐512). Results Our implementations reach 18.9 GB/s on an Apple M4 processor and 7.5 GB/s on an Intel Ice Lake processor—up to nine times faster than the scalar baseline of the V8 JavaScript engine—while requiring as little as 0.4 instructions per byte. Integrated into Node.js, our functions make the toWellFormed JavaScript function about five times faster. Conclusions Our algorithm achieves significant performance improvements over conventional methods. Our software is part of the Google JavaScript engine (V8) and thus part of several major Web browsers.
Authors
- Robert Clausecker
- Daniel Lemire (ORCID: https://orcid.org/0000-0003-3306-6922)
Institutions
- Université du Québec à Montréal (CA)
- Zuse Institute Berlin (DE)
- Université TÉLUQ (CA)
Publication Details
- Journal
- Software Practice and Experience
- Published
- 2026-08-25
- DOI
- https://doi.org/10.1002/spe.70105
- Primary Topic
- Advanced Wireless Communication Techniques
- Type
- article
- Field-Weighted Citation Impact
- 0.00