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

Implement discarding Document objects to reclaim space. #14312

Merged
merged 5 commits into from Jan 4, 2017

Conversation

@asajeffrey
Copy link
Member

asajeffrey commented Nov 21, 2016

This PR implements document discarding. Active documents are kept alive strongly, but inactive documents are only kept alive weakly. When a document is GCd, it is marked as discarded, and if it is every reactivated, a reload of the URL is triggered.

Note that this PR is pretty aggressive about discarding, and can any inactive document (other than those being kept alive by other same-origin pipelines). We might want to damp it down a bit.

Also note that this interacts with browser.html in that the reloading triggered by reactivating a document triggers mozbrowser events.

To test this, I added a -Zdiscard-inactive-documents debug flag, which discards all inactive documents, even ones which are reachable through other same-origin pipelines.


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #14262.
  • These changes do not require tests because we should be able to use the existing tests with -Zdiscard-inactive-documents.

This change is Reviewable

@highfive
Copy link

highfive commented Nov 21, 2016

Heads up! This PR modifies the following files:

  • @fitzgen: components/script/script_thread.rs, components/script/dom/document.rs
  • @KiChjang: components/script/script_thread.rs, components/script/dom/document.rs
@highfive
Copy link

highfive commented Nov 21, 2016

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!
@asajeffrey
Copy link
Member Author

asajeffrey commented Nov 21, 2016

cc @Ms2ger @ConnorGBrewster @metajack

@metajack
Copy link
Contributor

metajack commented Nov 22, 2016

Maybe the name of that flag needs unsafe in it? It seems a little confusingly worded as is.

@bors-servo
Copy link
Contributor

bors-servo commented Nov 22, 2016

The latest upstream changes (presumably #14313) made this pull request unmergeable. Please resolve the merge conflicts.

@asajeffrey
Copy link
Member Author

asajeffrey commented Nov 22, 2016

@metajack: yes, that option name isn't my best-ever writing. -Zaggressively-discard-documents? -Zdiscard-on-navigation? -Zunsafe-navigation-discard?

@asajeffrey asajeffrey force-pushed the asajeffrey:script-discard-documents branch from e398d45 to 376f059 Nov 22, 2016
@bors-servo
Copy link
Contributor

bors-servo commented Nov 23, 2016

The latest upstream changes (presumably #14211) made this pull request unmergeable. Please resolve the merge conflicts.

@asajeffrey asajeffrey force-pushed the asajeffrey:script-discard-documents branch from 376f059 to 39f3cea Nov 23, 2016
@asajeffrey
Copy link
Member Author

asajeffrey commented Nov 23, 2016

Might be worth disabling this by default, and enabling it with a flag?

@metajack
Copy link
Contributor

metajack commented Nov 23, 2016

@asajeffrey Why disable by default?

@asajeffrey
Copy link
Member Author

asajeffrey commented Nov 23, 2016

@metajack just being conservative. This change makes servo a lot more like FF, in that back/fwd will almost always result in a reload. This is not necessarily bad, but it is different.

@metajack
Copy link
Contributor

metajack commented Nov 23, 2016

Leaving it off by default will make it consume infinite memory, no?

I can see a case for some middle ground setting being desireable, but I assume that is much more complex to guarantee since somehow we will have to keep the appropriate pipelines alive artificially.

@asajeffrey
Copy link
Member Author

asajeffrey commented Nov 23, 2016

@metajack yes, there are more space leaks without this PR than with it. It wouldn't be too hard to implement whatever heuristic we want, we just add a message from the constellation to the script thread saying when a pipeline is discardable. I just piggybacked freeze/thaw because it was already there.

/// The state that a document managed by this script thread could be in.
#[must_root]
enum DocumentState {
Kept(bool, JS<Document>),

This comment has been minimized.

@emilio

emilio Nov 26, 2016

Member

Could you document what this bool means? I guess it's thawed, but would be ok to have it written here, or alternatively add a binary enum or a Kept { thawed: bool, document: JS<Document> } instead of a plain bool.

This comment has been minimized.

@asajeffrey

asajeffrey Nov 28, 2016

Author Member

Done.

fn trace(&self, trc: *mut JSTracer) {
// Note: we only trace thawed documents.
if let DocumentState::Kept(true, ref doc) = *self {
doc.trace(trc);

This comment has been minimized.

@nox

nox Nov 27, 2016

Member

Why is this needed? Just derive the trait on DocumentState.

This comment has been minimized.

@asajeffrey

asajeffrey Nov 28, 2016

Author Member

The derived version would trace documents even if they were Kept(false, doc). The idea is to implement poor-dev's weak references, that don't keep the documents alive.

@asajeffrey asajeffrey force-pushed the asajeffrey:script-discard-documents branch from 39f3cea to 4d70ef6 Nov 28, 2016
@KiChjang
Copy link
Member

KiChjang commented Dec 1, 2016

r? @jdm

@highfive highfive assigned jdm and unassigned KiChjang Dec 1, 2016
@bors-servo
Copy link
Contributor

bors-servo commented Dec 9, 2016

The latest upstream changes (presumably #13489) made this pull request unmergeable. Please resolve the merge conflicts.

@asajeffrey
Copy link
Member Author

asajeffrey commented Jan 4, 2017

@bors-servo
Copy link
Contributor

bors-servo commented Jan 4, 2017

Trying commit c14c431 with merge 9673fcb...

bors-servo added a commit that referenced this pull request Jan 4, 2017
Implement discarding Document objects to reclaim space.

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

This PR implements document discarding. Active documents are kept alive strongly, but inactive documents are only kept alive weakly. When a document is GCd, it is marked as discarded, and if it is every reactivated, a reload of the URL is triggered.

Note that this PR is pretty aggressive about discarding, and can any inactive document (other than those being kept alive by other same-origin pipelines). We might want to damp it down a bit.

Also note that this interacts with browser.html in that the reloading triggered by reactivating a document triggers mozbrowser events.

To test this, I added a `-Zdiscard-inactive-documents` debug flag, which discards all inactive documents, even ones which are reachable through other same-origin pipelines.

---
<!-- 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 #14262.
- [X] These changes do not require tests because we should be able to use the existing tests with `-Zdiscard-inactive-documents`.

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

bors-servo commented Jan 4, 2017

@jdm
Copy link
Member

jdm commented Jan 4, 2017

This is ready to merge from my point of view.

@asajeffrey
Copy link
Member Author

asajeffrey commented Jan 4, 2017

@bors-servo r=cbrewster cross fingers

@bors-servo
Copy link
Contributor

bors-servo commented Jan 4, 2017

📌 Commit c14c431 has been approved by cbrewster

@highfive highfive assigned cbrewster and unassigned jdm Jan 4, 2017
@cbrewster
Copy link
Member

cbrewster commented Jan 4, 2017

@bors-servo retry

@bors-servo
Copy link
Contributor

bors-servo commented Jan 4, 2017

Testing commit c14c431 with merge 16b0da5...

bors-servo added a commit that referenced this pull request Jan 4, 2017
Implement discarding Document objects to reclaim space.

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

This PR implements document discarding. Active documents are kept alive strongly, but inactive documents are only kept alive weakly. When a document is GCd, it is marked as discarded, and if it is every reactivated, a reload of the URL is triggered.

Note that this PR is pretty aggressive about discarding, and can any inactive document (other than those being kept alive by other same-origin pipelines). We might want to damp it down a bit.

Also note that this interacts with browser.html in that the reloading triggered by reactivating a document triggers mozbrowser events.

To test this, I added a `-Zdiscard-inactive-documents` debug flag, which discards all inactive documents, even ones which are reachable through other same-origin pipelines.

---
<!-- 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 #14262.
- [X] These changes do not require tests because we should be able to use the existing tests with `-Zdiscard-inactive-documents`.

<!-- 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/14312)
<!-- Reviewable:end -->
@bors-servo bors-servo merged commit c14c431 into servo:master Jan 4, 2017
1 of 3 checks passed
1 of 3 checks passed
continuous-integration/appveyor/pr AppVeyor was unable to build non-mergeable pull request
Details
continuous-integration/travis-ci/pr The Travis CI build failed
Details
homu Test successful
Details
@asajeffrey asajeffrey mentioned this pull request Jan 5, 2017
3 of 3 tasks complete
bors-servo added a commit that referenced this pull request Jan 5, 2017
…when-discarding, r=cbrewster

Index the session past correctly when discarding.

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

Oops, indexed from the wrong end when discarding documents in #14312.

---
<!-- 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 do not require tests because we're not testing document discarding

<!-- 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/14860)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this pull request Jan 5, 2017
…when-discarding, r=cbrewster

Index the session past correctly when discarding.

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

Oops, indexed from the wrong end when discarding documents in #14312.

---
<!-- 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 do not require tests because we're not testing document discarding

<!-- 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/14860)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this pull request Jan 6, 2017
…when-discarding, r=cbrewster

Index the session past correctly when discarding.

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

Oops, indexed from the wrong end when discarding documents in #14312.

---
<!-- 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 do not require tests because we're not testing document discarding

<!-- 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/14860)
<!-- Reviewable:end -->
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.

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