Writing a fast lexer: many parts of a compiler toolchain (other than optimisation) are O(N), and the lexer has the largest values of N.
A walkthrough showing different designs and performance considerations.
https://nothings.org/computer/lexing.html