4 ms·
When Compilers Disagree About UTF‑8
- kstenerud 3mo agoYou could actually use SIMD instructions to detect sequences of bytes with the top bit cleared, thus allowing bulk copies of ASCII text without a per-byte loop. Another optimization would be to take advantage of the fact that codepoint usage tends to cluster around the language of the text. So if you detect usage of 3-byte encodings, chances are you'll continue encountering only 3-byte encodings, with the odd ASCII or emoji codepoints. This opens up even more state machine possibilities.
- duskwuff 3mo ago> So if you detect usage of 3-byte encodings, chances are you'll continue encountering only 3-byte encodings, with the odd ASCII or emoji codepoints. Depends on what kind of text you're processing. Many languages use the ASCII range for spaces/newlines, digits, and punctuation.
- mort96 3mo agoThat, plus markup, be it something XML/HTML-like or something Markdown-like.
- zX41ZdbW 3mo agoThis is one of the optimizations from ClickHouse - detect ASCII and go a fast path: https://github.com/ClickHouse/ClickHouse/blob/6cde32de1a2463c37780b7c5f9f2cc1417b2809c/src/Functions/LowerUpperUTF8Impl.h#L31 https://github.com/ClickHouse/ClickHouse/blob/6cde32de1a2463...
- vlovich123 3mo agoFWIW I believe the second optimization is at odds with the first. It’s really hard to do this kind of conditional historical check in SIMD.
- deleted 3mo ago[deleted]
- MiroslavPokorny 3mo agoTitle is misleading, the compilers do not disagree, running the compiled code produces the same output. The difference is one binary(instructions) are slightly different...