<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/a-better-utf-8-automaton-17clbsjru" -->

---
title: A Better UTF-8 Automaton | daily.dev
description: A new UTF-8 validation automaton runs about 9 times faster than Björn Höhrmann's minimal C validator in the same benchmark. It is a shift-DFA whose transition...
canonical: https://daily.dev/posts/a-better-utf-8-automaton-17clbsjru
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: A Better UTF-8 Automaton | daily.dev
og:description: A new UTF-8 validation automaton runs about 9 times faster than Björn Höhrmann's minimal C validator in the same benchmark. It is a shift-DFA whose transition...
og:url: https://daily.dev/posts/a-better-utf-8-automaton-17clbsjru
og:image: https://api.daily.dev/og/posts/17CLbSJrU.png
og:image:alt: A Better UTF-8 Automaton
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# A Better UTF-8 Automaton

**[Lobsters](https://daily.dev/sources/lobsters)** · 7 min read · 0 upvotes · 0 comments

## Summary

A new UTF-8 validation automaton runs about 9 times faster than Björn Höhrmann's minimal C validator in the same benchmark. It is a shift-DFA whose transition constants were packed into uint32_t values with a Z3 SAT solver, shrinking the lookup table from 2 KiB to 1 KiB. Because it keeps states with different partial-codepoint byte counts separate, error recovery is trivial. An extra SYNC state enables parallel validation by overlapping chunks by 4 bytes. The ~30-line scalar C version runs only ~2.5x slower than simdutf on an Apple M5.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://orlp.net/blog/utf8-dfa>

## Questions this post answers

### How can I speed up UTF-8 validation in C without SIMD?

A shift-DFA validator written in about 30 lines of scalar C runs roughly 9 times faster than Björn Höhrmann's minimal C UTF-8 validator on Chinese text, and about 2.5x slower than simdutf on an Apple M5. Transitions are a byte lookup into uint32_t constants followed by a shift, and two parallel DFAs exploit instruction-level parallelism.

_Developers tuning low-level text parsing follow work like this on daily.dev._

### How do I make a UTF-8 validator recover from errors and know how many bytes to back up?

Keep DFA states that have consumed different numbers of bytes of a partial codepoint separate instead of merging them, as a minimal automaton would. Then the state itself tells you how many bytes of an incomplete sequence were consumed, so you can step back that far and insert a replacement character if you want.

_Engineers building robust parsers keep up with techniques like this on daily.dev._

### How can I validate UTF-8 in parallel chunks with a DFA?

Add a SYNC state that absorbs continuation bytes, then overlap the end of each chunk with the start of the next by 4 bytes, since no valid codepoint exceeds 4 bytes. One DFA validates the overlap while the second synchronizes on it. This lets the shift-DFA run almost twice as fast as earlier shift-DFA validators.

_Performance-minded developers explore tricks like this on daily.dev._

## Similar posts on daily.dev

- [Full Unicode Search at 50× ICU Speed with AVX‑512](https://daily.dev/posts/full-unicode-search-at-50-icu-speed-with-avx-512-s9bwdg8zf) · Hacker News · 0 upvotes · 0 comments
- [Valibot v1.5: Faster schema construction, Unicode code points, and stricter validation](https://daily.dev/posts/valibot-v1-5-faster-schema-construction-unicode-code-points-and-stricter-validation-fcqzm9kyo) · Valibot: The modular and type safe schema library · 5 upvotes · 1 comments
- [Losing 1½ Million Lines of Go](https://daily.dev/posts/losing-1-million-lines-of-go-urqxvaqw6) · Hacker News · 20 upvotes · 0 comments
- [Rewriting the Futhark type checker](https://daily.dev/posts/rewriting-the-futhark-type-checker-xhvkwalfe) · Lobsters · 0 upvotes · 0 comments
- [Bytes Speak All Languages: Cross-Script Name Retrieval via Contrastive Learning](https://daily.dev/posts/bytes-speak-all-languages-cross-script-name-retrieval-via-contrastive-learning-nexqauuco) · Towards Data Science · 2 upvotes · 0 comments

---

Tags: [#performance](https://daily.dev/tags/performance), [#c](https://daily.dev/tags/c)

[View this post on daily.dev](https://daily.dev/posts/a-better-utf-8-automaton-17clbsjru)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"A Better UTF-8 Automaton","url":"https://daily.dev/posts/a-better-utf-8-automaton-17clbsjru","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/a-better-utf-8-automaton-17clbsjru"},"datePublished":"2026-11-30T22:04:53.935Z","dateModified":"2026-11-30T22:05:18.758Z","description":"A new UTF-8 validation automaton runs about 9 times faster than Björn Höhrmann's minimal C validator in the same benchmark. It is a shift-DFA whose transition...","image":"https://media.daily.dev/image/upload/s--ZrL_HSsR--/f_auto/v1722860399/public/Placeholder%2006","thumbnailUrl":"https://media.daily.dev/image/upload/s--ZrL_HSsR--/f_auto/v1722860399/public/Placeholder%2006","isAccessibleForFree":true,"articleSection":"Lobsters","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Lobsters","logo":"https://media.daily.dev/image/upload/s--tl8v_Fku--/f_auto,t_logo/v1698841318/logos/lobste.jpg","url":"https://daily.dev/sources/lobsters"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/a-better-utf-8-automaton-17clbsjru","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"performance,c","timeRequired":"PT7M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Lobsters","item":"https://daily.dev/sources/lobsters"},{"@type":"ListItem","position":3,"name":"A Better UTF-8 Automaton"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/a-better-utf-8-automaton-17clbsjru#faq","mainEntity":[{"@type":"Question","name":"How can I speed up UTF-8 validation in C without SIMD?","acceptedAnswer":{"@type":"Answer","text":"A shift-DFA validator written in about 30 lines of scalar C runs roughly 9 times faster than Björn Höhrmann's minimal C UTF-8 validator on Chinese text, and about 2.5x slower than simdutf on an Apple M5. Transitions are a byte lookup into uint32_t constants followed by a shift, and two parallel DFAs exploit instruction-level parallelism. Developers tuning low-level text parsing follow work like this on daily.dev."}},{"@type":"Question","name":"How do I make a UTF-8 validator recover from errors and know how many bytes to back up?","acceptedAnswer":{"@type":"Answer","text":"Keep DFA states that have consumed different numbers of bytes of a partial codepoint separate instead of merging them, as a minimal automaton would. Then the state itself tells you how many bytes of an incomplete sequence were consumed, so you can step back that far and insert a replacement character if you want. Engineers building robust parsers keep up with techniques like this on daily.dev."}},{"@type":"Question","name":"How can I validate UTF-8 in parallel chunks with a DFA?","acceptedAnswer":{"@type":"Answer","text":"Add a SYNC state that absorbs continuation bytes, then overlap the end of each chunk with the start of the next by 4 bytes, since no valid codepoint exceeds 4 bytes. One DFA validates the overlap while the second synchronizes on it. This lets the shift-DFA run almost twice as fast as earlier shift-DFA validators. Performance-minded developers explore tricks like this on daily.dev."}}]}
```

