Login
You're viewing the code4lib.social public feed.
  • Dec 1, 2026, 7:20 AM

    I emailed him a note that fitting the UTF-8 automaton's table entries in 32 bits was done right after the original article by @dougall, also with Z3 to solve for the table entries, and it's what everyone uses now.

    💬 1🔄 0⭐ 0

Replies

  • Dec 1, 2026, 8:21 AM

    @pervognsen I'm not sure if I'd seen your shift-DFA gist before (and if I have, if I've already mentioned the following), but the reversal of transition[state][byte] to transition[byte][state] is mentioned pretty far down in my 2015 lexer writeup, except I mentioned it then skip right past it into a different optimization: nothings.org/computer/lexing.h

    💬 0🔄 0⭐ 1
  • Dec 1, 2026, 9:06 AM

    @nothings @pervognsen FWIW, in that article, about re-scanning to find line numbers:

    "If every file has at least one warning, this will clearly be slower."

    Not even that, necessarily! If the files are large enough to thrash the cache maybe, but if they fit in L2 (which these days is south of 1MB) there's decent odds a two-pass approach where one pass lexes and one pass marks the start offsets for every line is faster than many common impls of a lexer that tracks line numbers in the inner loop.

    💬 1🔄 0⭐ 0
  • Dec 1, 2026, 9:11 AM

    @nothings @pervognsen "Write down the position of every \n in the file" SIMDs up nicely and the speed you can run it at is certainly in the same ballpark as your L2$ bandwidth (details would depend on the exact impl and output format).

    One-byte-at-a-time branchy lexing certainly is not, especially when you take branches to count lines.

    💬 3🔄 0⭐ 0
  • 💬 0🔄 0⭐ 0
  • 💬 1🔄 0⭐ 0
  • Dec 1, 2026, 5:00 PM

    @rygorous Yep, my current fastest non-SIMD lexer approach is already multipass in two passes, the first pass uses a state machine to divide the stream into tokens of known types (1 mispredict at end of each token), and the second pass isn't actually a continuous pass, it iterates over each type of token (or really, each state machine final state) and does type-specific processing in a series of tight loops per type (avoids branch mispredict switching on token type). Def inspired by Oodle SIMD.

    💬 0🔄 0⭐ 0
  • Dec 1, 2026, 9:21 AM

    @rygorous @nothings Typically there's only a few places in a branch-based PL lexer where \n needs to be explicitly handled: the main lexer switch and inside quoted strings and comments; those few places can update the start-of-line pointer or add to a newline table or whatever. I do use the separate SIMD newline indexer if I have a separate fast indexing pass for top-level declarations.

    💬 0🔄 0⭐ 0