CSS matching: the best way to do this might be a two-dimensional regex-like state machine, which simplifies to an array and a queue of bits. One dimension for matching descendant and child combinators, and then another dimension for general sibling and previous-sibling. As far as I know, this is not something any other browser engine has discovered, although there's some mention of it elsewhere:
http://stackoverflow.com/questions/4656975/use-css-selectors-to-collect-html-elements-from-a-streaming-parser-e-g-sax-str/4752067If there's 32 (64 for the 64-bit version) or fewer width/height combinators, which is very likely, we can store the state array entirely in a register and get even more efficient... but even the basic implementation should beat the backtracking (:facepalm:) that contemporary implementations do.
https://swtch.com/~rsc/regexp/regexp1.htmlThere is a team working on a C implemented www browser: netsurf.
It works and is "lightweight" compared to the big ones but, could be
much better...
https://bbs.progrider.org/prog/read/1406427616/549-556