Skip to content

Off-main-thread, speculative HTML parsing #3847

Open

Activity

  1. added
    I-perf-slow
    A-content/parsers
    B-interesting-project
    on Oct 29, 2014
  2. kmcallister commented on Oct 29, 2014

    @kmcallister
    Contributor

    This would basically entail writing an implementation of TreeSink which implements every method by sending a message on a channel. The node handles can just be sequentially assigned IDs. We would also keep the TrustedNodeAddress implementation so we don't pay for off-main-thread overhead when we don't use it.

    There is also the possibility of doing tokenization off-thread and tree construction on thread. I don't how that would perform in comparison, but it's an easy experiment to try.

  3. psdh commented on Feb 19, 2015

    @psdh
    Contributor

    I am trying to implement this!

  4. psdh commented on Feb 19, 2015

    @psdh
    Contributor

    ^^ Should I implement TreeSink on top of existing implementation, implementing the missing functions and adding the sending a message part.
    Can you also, elaborate on the sending a message part

  5. psdh commented on Feb 28, 2015

    @psdh
    Contributor

    Okay, After irc discussions with kmc, and jdm, I have understood that I need to
    Add one more implementation of TreeSink that would implement each of these methods by sending a enum to a channel(say message), this enum would have information about
    i) target
    ii) arguments
    And then I queue these dom manipulations as enum vairants( in a vec?) and flush them from time to time
    When do we make the actual changes(to the dom) though?
    Is it when we flush them, we can check which enum variant has been stored and make changes according to that?

  6. jdm commented on Feb 28, 2015

    @jdm
    Member

    As you say, the DOM changes would occur when flushing them in the main script task. There would need to be a synchronization point - when the script task is going to execute a newly-parsed script element, it needs to operate on the up-to-date DOM tree. Does that make sense?

  7. kmcallister commented on Feb 28, 2015

    @kmcallister
    Contributor

    I queue these dom manipulations as enum vairants(in a vec?)

    And/or in the message channel itself.

    You'll need a cross-thread way for tree ops to refer to nodes that haven't been constructed yet, but will be constructed by a previous tree op. Gecko uses nsIContent** for this: a pointer to a slot which will eventually hold a pointer to the node, when the main thread gets around to constructing it.

    This approach seems pretty unsafe, and anyway will be impossible without unsafe code in Rust. So for Servo's parser, I'd like to try using simple integer IDs, and then figure out what the performance cost is.

    When do we make the actual changes(to the dom) though?

    I think this depends on why you're doing the parse.

    If you're speculatively parsing characters after </script> while the main thread is running the script, then you can't commit any DOM manipulations until the script finishes and you check whether it did anything to invalidate your speculative assumptions. The Gecko link above has more to say about this.

    You can speculatively fetch any URLs you've discovered in the parse, even if the DOM manipulations are discarded. I think there's no need to coordinate that with the main thread at all.

    We can also do the initial page load parse off-main-thread, which allows parallelism between the parser and the actual DOM manipulations (a bottleneck today for whatever reason). In that case I think you'd execute the tree ops as soon as possible, until you see a </script>.

    Naturally, <script defer> and <script async> don't block parsing in the same way. I'm not sure about the details; you'll have to consult the spec. It's not necessary to implement these right away, but we should keep them in mind.

  8. LifeIsStrange commented on Dec 10, 2015

    @LifeIsStrange

    Just for say that some blockers addons like uBlock Origin or noscript will need to disable this feature.

  9. mbrubeck commented on Dec 10, 2015

    @mbrubeck
    ContributorAuthor

    Just for say that some blockers addons like uBlock Origin or noscript will need to disable this feature.

    Can you explain why? This feature does not cause any additional fetches or script executions. uBlock and NoScript work fine in Firefox and other browsers that do off-thread parsing.

  10. tetsuharuohzeki commented on Dec 10, 2015

    @tetsuharuohzeki
    Contributor

    @LifeIsStrange

    uBlock blocks the network traffic which is in a blacklist, and NoScript just disable to execution script without in the whitelist. This would not prevent them

  11. LifeIsStrange commented on Dec 10, 2015

    @LifeIsStrange

    Sorry, I expressed myself badly,I Just speaked about prefetching.

    UBlock Origin do this: " Disable "Prefetch resources to load pages more quickly"

    This will ensure no TCP connection is opened at all for blocked requests: It's for your own protection privacy-wise.[1]
    For pages with lots for blocked requests, this will actually remove overhead from page load (if you did not have the setting already disabled).
    When uBlock blocks a network request, the expectation is that it blocks completely the connection, hence the new permission is necessary for uBlock to do truthfully what it says it does."
    
  12. Syrcon commented on Jan 18, 2016

    @Syrcon

    I'll try to implement this as my master's thesis.

    As @jdm said, there is some timeline needed.
    So the main period of work is February - April 2016.

  13. 17 remaining items

  14. nox commented on Sep 30, 2017

    @nox
    Contributor

    Cc @cynicaldevil

  15. added 10 commits that reference this issue on Sep 6, 2019
    419002d
    def6295
    ad394cf
    2b97bc9
    d39267e
    f1a161f
    c3ae478
    32d32bf
    8a20090
    4e9967b
  16. nox commented on Sep 12, 2019

    @nox
    Contributor

    #24148 doesn't fix this.

  17. reopened this on Sep 12, 2019
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

    A-content/parsersB-interesting-projectI-perf-slow

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions