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
Off-main-thread, speculative HTML parsing #3847
Comments
This would basically entail writing an implementation of 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. |
I am trying to implement this! |
^^ Should I implement TreeSink on top of existing implementation, implementing the missing functions and adding the sending a message part. |
You can learn more about message passing in Rust at http://doc.rust-lang.org/book/concurrency.html |
Okay, After irc discussions with kmc, and jdm, I have understood that I need to |
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? |
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 This approach seems pretty unsafe, and anyway will be impossible without
I think this depends on why you're doing the parse. If you're speculatively parsing characters after 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 Naturally, |
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. |
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 |
Sorry, I expressed myself badly,I Just speaked about prefetching. UBlock Origin do this: " Disable "Prefetch resources to load pages more quickly"
|
I'll try to implement this as my master's thesis. As @jdm said, there is some timeline needed. |
Did you make any progress on this @Syrcon? |
Well, @jdm helped with making a parser work asynchronously, and I'm working right now on executing parser in its own thread. So there will be some commits by the weekend. You'd like to work on this? |
No, no rush at all! If it was the case that nothing had been done for this, I was going to remove the |
My experimental branch that tried to make the parser asynchronous is https://github.com/jdm/servo/tree/asyncparse. |
@jdm, hi jdm, I'm going to use this idea as my GSoC 2017 project idea. Is there anyone working on this? I will try to explore the working flows about this idea recently. Is there any related suggested issue to work on? |
I don't think there are any other issues related to this. |
@mrmiywj actually there is this |
@jdm I'd also like to take a cursory look into this project, if you don't mind multiple people investigating it at once. |
It's intended as a GSoC project, so it's probably best suited for people intending to apply for that. |
Sorry for not being clear. I am also a prospective GSoC student. |
Cc @cynicaldevil |
Prefetch img, scripts and stylesheets during parsing <!-- Please describe your changes on the following line: --> Eagerly tokenize html input, and scan for `script` and `img` tags which can be prefetched into the cache. This allows resources to be loaded concurrently, which would otherwise be loaded sequentially due to being blocked by script execution. On the cloth webgl demo, this takes the time-to-paint down from 732ms to 560ms. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #3847 - [x] These changes do not require tests because it's a perf improvement <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/24148) <!-- Reviewable:end -->
Prefetch img, scripts and stylesheets during parsing <!-- Please describe your changes on the following line: --> Eagerly tokenize html input, and scan for `script` and `img` tags which can be prefetched into the cache. This allows resources to be loaded concurrently, which would otherwise be loaded sequentially due to being blocked by script execution. On the cloth webgl demo, this takes the time-to-paint down from 732ms to 560ms. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #3847 - [x] These changes do not require tests because it's a perf improvement <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/24148) <!-- Reviewable:end -->
Prefetch img, scripts and stylesheets during parsing <!-- Please describe your changes on the following line: --> Eagerly tokenize html input, and scan for `script` and `img` tags which can be prefetched into the cache. This allows resources to be loaded concurrently, which would otherwise be loaded sequentially due to being blocked by script execution. On the cloth webgl demo, this takes the time-to-paint down from 732ms to 560ms. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #3847 - [x] These changes do not require tests because it's a perf improvement <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/24148) <!-- Reviewable:end -->
Prefetch img, scripts and stylesheets during parsing <!-- Please describe your changes on the following line: --> Eagerly tokenize html input, and scan for `script` and `img` tags which can be prefetched into the cache. This allows resources to be loaded concurrently, which would otherwise be loaded sequentially due to being blocked by script execution. On the cloth webgl demo, this takes the time-to-paint down from 732ms to 560ms. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #3847 - [x] These changes do not require tests because it's a perf improvement <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/24148) <!-- Reviewable:end -->
Prefetch img, scripts and stylesheets during parsing <!-- Please describe your changes on the following line: --> Eagerly tokenize html input, and scan for `script` and `img` tags which can be prefetched into the cache. This allows resources to be loaded concurrently, which would otherwise be loaded sequentially due to being blocked by script execution. On the cloth webgl demo, this takes the time-to-paint down from 732ms to 560ms. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #3847 - [x] These changes do not require tests because it's a perf improvement <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/24148) <!-- Reviewable:end -->
Prefetch img, scripts and stylesheets during parsing <!-- Please describe your changes on the following line: --> Eagerly tokenize html input, and scan for `script` and `img` tags which can be prefetched into the cache. This allows resources to be loaded concurrently, which would otherwise be loaded sequentially due to being blocked by script execution. On the cloth webgl demo, this takes the time-to-paint down from 732ms to 560ms. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #3847 - [x] These changes do not require tests because it's a perf improvement <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/24148) <!-- Reviewable:end -->
Prefetch img, scripts and stylesheets during parsing <!-- Please describe your changes on the following line: --> Eagerly tokenize html input, and scan for `script` and `img` tags which can be prefetched into the cache. This allows resources to be loaded concurrently, which would otherwise be loaded sequentially due to being blocked by script execution. On the cloth webgl demo, this takes the time-to-paint down from 732ms to 560ms. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #3847 - [x] These changes do not require tests because it's a perf improvement <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/24148) <!-- Reviewable:end -->
Prefetch img, scripts and stylesheets during parsing <!-- Please describe your changes on the following line: --> Eagerly tokenize html input, and scan for `script` and `img` tags which can be prefetched into the cache. This allows resources to be loaded concurrently, which would otherwise be loaded sequentially due to being blocked by script execution. On the cloth webgl demo, this takes the time-to-paint down from 732ms to 560ms. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #3847 - [x] These changes do not require tests because it's a perf improvement <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/24148) <!-- Reviewable:end -->
Prefetch img, scripts and stylesheets during parsing <!-- Please describe your changes on the following line: --> Eagerly tokenize html input, and scan for `script` and `img` tags which can be prefetched into the cache. This allows resources to be loaded concurrently, which would otherwise be loaded sequentially due to being blocked by script execution. On the cloth webgl demo, this takes the time-to-paint down from 732ms to 560ms. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #3847 - [x] These changes do not require tests because it's a perf improvement <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/24148) <!-- Reviewable:end -->
#24148 doesn't fix this. |
By running the HTML parser in a separate task from script, we could allow tokenization and speculative tree building to continue while content scripts are fetched and executed.
References on HTML parser threading in Gecko and WebKit:
The text was updated successfully, but these errors were encountered: