Skip to content

Stream-based extractor #414

Closed
Closed

Description

@mre

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

Activity

  1. mre commented on Dec 3, 2021

    @mre
    MemberAuthor

    Started working on this last night in the extractor branch.

  2. mre commented on Dec 17, 2021

    @mre
    MemberAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions