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

Use microtasks to await a stable state. #16861

Merged

Conversation

@gterzian
Copy link
Member

gterzian commented May 14, 2017

@jdm @KiChjang First pass at using microtasks to await a stable state. I ran into all sorts of problems to get it to compile, I think it's mainly related to the fact that the microtasks are stored in a Vec, which meant the Runnalbe.handler(self: Box<Self>) couldn't be called while iterating over the Vec... It compiles now although I haven't run any tests. I'm assuming I'm missing something fundamental and was hoping my changes would highlight the problems I run into, and you had a better idea of how to implement this... Perhaps we shouldn't pass a Runnable to await_stable_state at all?


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #15375 (github issue number if applicable).
  • There are tests for these changes OR
  • These changes do not require tests because _____

This change is Reviewable

@highfive
Copy link

highfive commented May 14, 2017

Heads up! This PR modifies the following files:

  • @fitzgen: components/script/script_thread.rs, components/script/dom/htmlmediaelement.rs, components/script/dom/bindings/trace.rs, components/script/microtask.rs
  • @KiChjang: components/script/script_thread.rs, components/script/dom/htmlmediaelement.rs, components/script/dom/bindings/trace.rs, components/script/microtask.rs
@highfive
Copy link

highfive commented May 14, 2017

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!
  • These commits modify script code, but no tests are modified. Please consider adding a test!
@gterzian gterzian mentioned this pull request May 15, 2017
1 of 5 tasks complete
@gterzian
Copy link
Member Author

gterzian commented May 15, 2017

As an update on the above, I have used this commit(as well as implemented a ref_handler method to the Runnable used) in #16238, and it all the tests in the-img-element passed succesfully. So as a proof of concept it works, however I am wondering if instead of adding this ref_handler method to Runnable, we should perhaps add a new Microtask specific trait.

@@ -420,6 +421,13 @@ unsafe impl JSTraceable for Box<LayoutRPC + Send + 'static> {
}
}

unsafe impl JSTraceable for Box<Runnable + Send + 'static> {

This comment has been minimized.

Copy link
@jdm

jdm May 15, 2017

Member

This is not a safe construct, since it allows us to store non-GC safe values in Runnables.

@@ -28,6 +32,13 @@ pub struct MicrotaskQueue {
#[derive(JSTraceable, HeapSizeOf)]
pub enum Microtask {
Promise(EnqueuedPromiseCallback),
AwaitStableState(Box<Runnable + Send>)

This comment has been minimized.

Copy link
@jdm

jdm May 15, 2017

Member

Instead of using Runnables for this and await_stable_state, let's have MedieElement(MediaElementMicrotask), ImageElement(ImageElementMicrotask), where the inner types are enums. We can define a MicrotaskRunnable trait that the enums implement with a handler(&self) method.

@jdm jdm assigned jdm and unassigned cbrewster May 15, 2017
@gterzian gterzian force-pushed the gterzian:use_microtask_to_await_stable_state branch from 242bf4d to 0e6bcee May 16, 2017
@gterzian gterzian force-pushed the gterzian:use_microtask_to_await_stable_state branch 2 times, most recently from 100f6f1 to 98744a0 May 16, 2017
@gterzian
Copy link
Member Author

gterzian commented May 16, 2017

@jdm thanks for the suggestions, I've made an attempt using enums...

Note I've had to impl HeapSizeOf for Trusted<HTMLMediaElement>, is it necessary to store the HTMLMediaElement inside a Trusted, since microtask are not multi-threaded as I understand it?

@jdm
Copy link
Member

jdm commented May 16, 2017

It's better to use #[ignore_heap_size_of = "Can't measure Trusted<T>"] instead.

@jdm
Copy link
Member

jdm commented May 16, 2017

As for whether it's necessary, that's a good point. It's true that there's no threading involved, so a Root value should work instead.

}
}

impl HeapSizeOf for Trusted<HTMLMediaElement> {

This comment has been minimized.

Copy link
@jdm

jdm May 16, 2017

Member

Remove this.

@@ -626,14 +626,12 @@ impl ScriptThread {
}

// https://html.spec.whatwg.org/multipage/#await-a-stable-state
pub fn await_stable_state<T: Runnable + Send + 'static>(task: T) {
pub fn await_stable_state(task: Microtask) {
//TODO use microtasks when they exist

This comment has been minimized.

Copy link
@jdm

jdm May 16, 2017

Member

Let's remove this comment :)

base_url: ServoUrl
},
PauseIfNotInDocumentTask {
elem: Trusted<HTMLMediaElement>,

This comment has been minimized.

Copy link
@jdm

jdm May 16, 2017

Member

We can use Root<HTMLMediaElement> values now.

@gterzian gterzian force-pushed the gterzian:use_microtask_to_await_stable_state branch from 98744a0 to 3fdf6c8 May 17, 2017
@gterzian
Copy link
Member Author

gterzian commented May 17, 2017

@jdm thanks, ready for another round or review...

@gterzian gterzian force-pushed the gterzian:use_microtask_to_await_stable_state branch from 3fdf6c8 to b1c4edb May 17, 2017
@jdm
Copy link
Member

jdm commented May 17, 2017

@bors-servo: r+
Thanks!

@bors-servo
Copy link
Contributor

bors-servo commented May 17, 2017

📋 Looks like this PR is still in progress, ignoring approval

@jdm jdm changed the title [WIP] Use microtasks to await a stable state. Use microtasks to await a stable state. May 17, 2017
bors-servo added a commit that referenced this pull request May 19, 2017
…r=jdm

Use microtasks to await a stable state.

<!-- Please describe your changes on the following line: -->

@jdm @KiChjang First pass at using microtasks to await a stable state. I ran into all sorts of problems to get it to compile, I think it's mainly related to the fact that the microtasks are stored in a `Vec`, which meant the `Runnalbe.handler(self: Box<Self>)` couldn't be called while iterating over the Vec... It compiles now although I haven't run any tests. I'm assuming I'm missing something fundamental and was hoping my changes would highlight the problems I run into, and you had a better idea of how to implement this... Perhaps we shouldn't pass a `Runnable` to `await_stable_state` at all?

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [ ] `./mach build -d` does not report any errors
- [ ] `./mach test-tidy` does not report any errors
- [ ] These changes fix #15375 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- 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/16861)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented May 19, 2017

💔 Test failed - linux-rel-wpt

@jdm
Copy link
Member

jdm commented May 19, 2017

Oh, it does seem like networkState_during_progress.html consistently times out. Could you revert that expectation change?

@gterzian gterzian force-pushed the gterzian:use_microtask_to_await_stable_state branch from 765d199 to a8390ae May 19, 2017
@gterzian
Copy link
Member Author

gterzian commented May 19, 2017

@jdm yep, done. Build failure seems unrelated by the way...

screen shot 2017-05-19 at 6 09 35 pm

@jdm
Copy link
Member

jdm commented May 19, 2017

@bors-servo
Copy link
Contributor

bors-servo commented May 19, 2017

📌 Commit a8390ae has been approved by jdm

@bors-servo
Copy link
Contributor

bors-servo commented May 19, 2017

Testing commit a8390ae with merge f713c76...

bors-servo added a commit that referenced this pull request May 19, 2017
…r=jdm

Use microtasks to await a stable state.

<!-- Please describe your changes on the following line: -->

@jdm @KiChjang First pass at using microtasks to await a stable state. I ran into all sorts of problems to get it to compile, I think it's mainly related to the fact that the microtasks are stored in a `Vec`, which meant the `Runnalbe.handler(self: Box<Self>)` couldn't be called while iterating over the Vec... It compiles now although I haven't run any tests. I'm assuming I'm missing something fundamental and was hoping my changes would highlight the problems I run into, and you had a better idea of how to implement this... Perhaps we shouldn't pass a `Runnable` to `await_stable_state` at all?

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [ ] `./mach build -d` does not report any errors
- [ ] `./mach test-tidy` does not report any errors
- [ ] These changes fix #15375 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- 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/16861)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented May 19, 2017

💔 Test failed - linux-rel-wpt

@jdm
Copy link
Member

jdm commented May 19, 2017

@bors-servo: retry

  • the builder was totally busted
@bors-servo
Copy link
Contributor

bors-servo commented May 20, 2017

Testing commit a8390ae with merge f054911...

bors-servo added a commit that referenced this pull request May 20, 2017
…r=jdm

Use microtasks to await a stable state.

<!-- Please describe your changes on the following line: -->

@jdm @KiChjang First pass at using microtasks to await a stable state. I ran into all sorts of problems to get it to compile, I think it's mainly related to the fact that the microtasks are stored in a `Vec`, which meant the `Runnalbe.handler(self: Box<Self>)` couldn't be called while iterating over the Vec... It compiles now although I haven't run any tests. I'm assuming I'm missing something fundamental and was hoping my changes would highlight the problems I run into, and you had a better idea of how to implement this... Perhaps we shouldn't pass a `Runnable` to `await_stable_state` at all?

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [ ] `./mach build -d` does not report any errors
- [ ] `./mach test-tidy` does not report any errors
- [ ] These changes fix #15375 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- 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/16861)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented May 20, 2017

☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css, mac-rel-wpt1, mac-rel-wpt2, windows-msvc-dev
Approved by: jdm
Pushing f054911 to master...

@bors-servo bors-servo merged commit a8390ae into servo:master May 20, 2017
2 of 3 checks passed
2 of 3 checks passed
continuous-integration/appveyor/pr AppVeyor build failed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@gterzian gterzian deleted the gterzian:use_microtask_to_await_stable_state branch Jan 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

5 participants
You can’t perform that action at this time.