-
-
Notifications
You must be signed in to change notification settings - Fork 202
Stream-based extractor #414
Description
In #330 (comment) @untitaker mentioned that html parsing could be improved:
html parsing is slow. I know that using html5ever's Tokenizer more than doubled hyperlink's runtime, which is why I didn't manage to move hyperlink away from quick-xml for a long time. I see that you're constructing an entire tree in lychee instead of iterating over tokens. Shamelessly plugging my own html parser at this point, but swapping out html5ever with literally anything else, or replacing the document parser with just the Tokenizer will give you some boost. Quickly skimming over what you do with the element tree, you don't really need anything but tokens.
We could do so by using implementing our own TokenSink as shown in this example:
https://github.com/servo/html5ever/blob/master/html5ever/examples/tokenize.rs
TokenSink could be an iterator or even a stream of tokens; we don't have to create an entire DOM for our use-case.
- Rewrite
extractor.rsto use a customTokenSink. - Add a benchmark for the extractor (the tokenizer)
- Check if the performance improved