A Better UTF-8 Automaton orlp.net · 9 points · 0 comments · HN thread TL;DR Orso...
HN Best 200 @best
A Better UTF-8 Automaton orlp.net · 9 points · 0 comments · HN thread
TL;DR Orson Peters (orlp) presents a new UTF-8 validation automaton, a shift-DFA packed into 32-bit magic constants with a SYNC state that enables parallel validation. He claims it is about 9 times faster than Björn Höhrmann's minimal validator on an Apple M5 when validating Chinese text, and about 2.5x slower than simdutf.
- The DFA has 13 states packed into uint32_t constants with a 256-entry table, reducing the lookup table from 2 KiB to 1 KiB compared with Per Vognsen's uint64_t shift-DFA.
- The constants were found with a Z3 SAT-solver search that takes about 15 minutes to run.
- A SYNC state absorbs continuation bytes, so input can be validated in two overlapping interleaved chains (overlap of 4 bytes), giving roughly twice the speed of earlier shift-DFA validators through instruction-level parallelism.
- Error recovery is trivial because states are not merged across different numbers of consumed partial-codepoint bytes, so the consumed count can be read directly from the state.
- The post reports about 9x faster than Höhrmann's validator and about 2.5x slower than simdutf on Chinese text, and the author notes the sample code lacks an ASCII fast path that a real validator should have.
Discussion No comments have been posted yet, so there is no discussion to summarize.