Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stream-based extractor #414

Closed
3 tasks done
mre opened this issue Dec 1, 2021 · 2 comments
Closed
3 tasks done

Stream-based extractor #414

mre opened this issue Dec 1, 2021 · 2 comments

Comments

@mre
Copy link
Member

mre commented Dec 1, 2021

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.rs to use a custom TokenSink.
  • Add a benchmark for the extractor (the tokenizer)
  • Check if the performance improved
@mre
Copy link
Member Author

mre commented Dec 3, 2021

Started working on this last night in the extractor branch.

@mre mre closed this as completed Dec 17, 2021
@mre
Copy link
Member Author

mre commented Dec 17, 2021

This has landed in master now. There is a 10-25% perf improvement thanks to it.
See #424 for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant