# When Compilers Disagree About UTF-8

Original title: When Compilers Disagree About UTF‑8

> Hacker News story 49180059 · language: en · submitted 2026-08-05
> Web version: https://zeli.app/story/49180059
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 44 · by [rbanffy](<https://news.ycombinator.com/user?id=rbanffy>) · 💬 6
[original](<https://nemanjatrifunovic.substack.com/p/when-compilers-disagree-about-utf8>) · [HN discussion](<https://news.ycombinator.com/item?id=49180059>)

## Summary

The author revisits a UTF-8 decoding function in his open-source C++ library, utfcpp, and adds a fast path for ASCII characters. Benchmarking shows a 3x throughput improvement with clang, but no change with gcc. Investigating the assembly reveals clang fails to eliminate redundant validity checks, while gcc already does. The author then refactors the validation into the sequence functions, satisfying both compilers and achieving 15-20% improvement with gcc on mixed text.

## Key quote

> Compilers just never stop surprising me: this time there was no difference for the ASCII text at all! Zero!

## HN discussion (6 comments)

### [kstenerud](<https://news.ycombinator.com/item?id=49180287>)

> You 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.

---

## Cite

- Page: https://zeli.app/story/49180059
- Date: 2026-08-05
- Source: nemanjatrifunovic.substack.com (https://nemanjatrifunovic.substack.com/p/when-compilers-disagree-about-utf8)
- Hacker News: https://news.ycombinator.com/item?id=49180059

## Other languages

- zh: https://zeli.app/zh/story/49180059 · markdown: https://zeli.app/zh/story/49180059.md
- ko: https://zeli.app/ko/story/49180059 · markdown: https://zeli.app/ko/story/49180059.md
- de: https://zeli.app/de/story/49180059 · markdown: https://zeli.app/de/story/49180059.md
- es: https://zeli.app/es/story/49180059 · markdown: https://zeli.app/es/story/49180059.md
