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

Rewrite the style sharing candidate cache #12668

Merged
merged 5 commits into from Aug 18, 2016
Merged

Conversation

emilio
Copy link
Member

@emilio emilio commented Jul 31, 2016

See the first commit's description for a bit of background. I'm making the PR in this state just to verify against try I've handled all cases of possibly incorrect sharing and, if not, fix it.


  • There are tests for these changes OR

This change is Reviewable

@highfive
Copy link

Heads up! This PR modifies the following files:

  • @bholley: components/style/selector_matching.rs, components/style/sequential.rs, components/style/traversal.rs, components/style/matching.rs, components/style/Cargo.toml, components/style/restyle_hints.rs, components/style/dom.rs, components/style/context.rs, components/style/parallel.rs
  • @KiChjang: components/script/Cargo.toml, components/script/layout_wrapper.rs, components/script_layout_interface/Cargo.toml

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Jul 31, 2016
@emilio
Copy link
Member Author

emilio commented Jul 31, 2016

@bors-servo: try

@bors-servo
Copy link
Contributor

⌛ Trying commit f33cbb0 with merge a93bb08...

bors-servo pushed a commit that referenced this pull request Jul 31, 2016
[wip] Rewrite the style sharing candidate cache

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

See the first commit's description for a bit of background. I'm making the PR in this state just to verify against try I've handled all cases of possibly incorrect sharing and, if not, fix it.

---
<!-- 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 #12534

<!-- Either: -->
- [x] There are tests for these changes OR

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
@bors-servo
Copy link
Contributor

💔 Test failed - linux-rel

@highfive highfive added the S-tests-failed The changes caused existing tests to fail. label Jul 31, 2016
@highfive
Copy link

  ▶ FAIL [expected PASS] /_mozilla/css/restyle_hints_state.html
  └   → /_mozilla/css/restyle_hints_state.html e0244585b680e30247daff27d091c5acb570cb70
/_mozilla/css/restyle_hints_state_ref.html 4b148bc27c3ec95f7eba64524b0ce61ea150d26a
Testing e0244585b680e30247daff27d091c5acb570cb70 == 4b148bc27c3ec95f7eba64524b0ce61ea150d26a

@highfive highfive removed the S-tests-failed The changes caused existing tests to fail. label Jul 31, 2016
@emilio
Copy link
Member Author

emilio commented Jul 31, 2016

Hah! Funnily enough, that test fails because of (the lack of) emilio/rust-selectors@4c43337, bug that is in current rust selectors.

@bors-servo: try

@bors-servo
Copy link
Contributor

⌛ Trying commit b1a4217 with merge 729ed50...

bors-servo pushed a commit that referenced this pull request Jul 31, 2016
[wip] Rewrite the style sharing candidate cache

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

See the first commit's description for a bit of background. I'm making the PR in this state just to verify against try I've handled all cases of possibly incorrect sharing and, if not, fix it.

---
<!-- 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 #12534

<!-- Either: -->
- [x] There are tests for these changes OR

<!-- 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/12668)
<!-- Reviewable:end -->
let shareable_element = match node.as_element() {
Some(element) => {
if opts::get().style_sharing_stats {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be faster to just do the add unconditionally than to take a lock to check the option.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opts is not the same as prefs, and opts::get() is just getting a lazy-static, not a RWLock as with the preferences.

@bors-servo
Copy link
Contributor

💥 Test timed out

@emilio
Copy link
Member Author

emilio commented Aug 1, 2016

@bors-servo: retry

@bors-servo
Copy link
Contributor

⌛ Trying commit b1a4217 with merge 477db79...

bors-servo pushed a commit that referenced this pull request Aug 1, 2016
[wip] Rewrite the style sharing candidate cache

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

See the first commit's description for a bit of background. I'm making the PR in this state just to verify against try I've handled all cases of possibly incorrect sharing and, if not, fix it.

---
<!-- 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 #12534

<!-- Either: -->
- [x] There are tests for these changes OR

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

☀️ Test successful - arm32, arm64, linux-dev, linux-rel, mac-dev-unit, mac-rel-css, mac-rel-wpt, windows-dev

@emilio
Copy link
Member Author

emilio commented Aug 1, 2016

Yay!

r? @pcwalton (still some cleanup needed, but should be good enough to get it reviewed).

@highfive highfive assigned pcwalton and unassigned Manishearth Aug 1, 2016
debug!("Stylist stats:");
debug!(" - Got {} sibling-affecting selectors",
self.sibling_affecting_selectors.len());
debug!(" - Got {} non-commong-style-attribute-affecting selectors",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: "commong" -> "common"

@pcwalton
Copy link
Contributor

pcwalton commented Aug 2, 2016

This look good cc @emilio

@emilio
Copy link
Member Author

emilio commented Aug 2, 2016

cool, can I r=you when I clean this up? (and the relevant selectors pr lands)

@pcwalton
Copy link
Contributor

pcwalton commented Aug 3, 2016

I'd like to take one final look over it after you clean it up, but yeah, basically.

bors-servo pushed a commit to servo/rust-selectors that referenced this pull request Aug 10, 2016
Redesign the style sharing API.

See servo/servo#12668 for context.

r? @SimonSapin

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-selectors/93)
<!-- Reviewable:end -->
@emilio
Copy link
Member Author

emilio commented Aug 11, 2016

@bors-servo: try

@bors-servo
Copy link
Contributor

⌛ Trying commit 8a6858a with merge b93d5e9...

@bors-servo
Copy link
Contributor

☀️ Test successful - arm32, arm64, linux-dev, linux-rel, mac-dev-unit, mac-rel-css, mac-rel-wpt, windows-dev

@emilio emilio changed the title [wip] Rewrite the style sharing candidate cache Rewrite the style sharing candidate cache Aug 12, 2016
fn have_same_class<E: TElement>(element: &E, candidate: &E) -> bool {
// XXX Efficiency here, I'm only validating ideas.
let mut first = vec![];
let mut second = vec![];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These could be sets to be more accurate (fewer misses). If on the other hand we don’t mind being conservative (more misses) comparing the string values of class attributes might be slightly faster than building these vecs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sets or sorted vectors.

@SimonSapin
Copy link
Member

Looks good to me.

@pcwalton Could you have that last look? This is upgrading to an already-released version of selector that has breaking changes, so it blocks using in Servo further breaking changes to selectors. (Version numbers don’t branch easily.)

@pcwalton
Copy link
Contributor

r=me when rebased. Awesome!

The style candidate cache had regressed a few times (see servo#12534), and my
intuition is that being able to disable all style sharing with a single rule in
the page is really unfortunate.

This commit redesigns the style sharing cache in order to be a optimistic cache,
but then reject candidates if they match different sibling-affecting selectors
in the page, for example.

So far the numbers have improved, but not so much as I'd wanted (~10%/20% of
non-incremental restyling time in general). The current implementation is really
dumb though (we recompute and re-match a lot of stuff), so we should be able to
optimise it quite a bit.

I have different ideas for improving it (that may or may not work), apart of the
low-hanging fruit like don't re-matching candidates all the time but I have to
measure the real impact.

Also, I need to verify it against try.
Haven't measured a lot, will do tomorrow, but I want a test run.
This was the underlying cause of the restyle_hints_state.html failure.

It was uncovered only when fixing the HAS_EDGE_CHILD_SELECTOR flags because this
was the series of events happening.

 * <script> starts executing.
 * All the restyle hint processing takes place.
 * <script> ends executing, gets appended to the body (I think this is also a bug).
 * <body> receives children_changed notification, with an Append mutation.
   * <body> had the HAS_EDGE_CHILD_SELECTOR flag, so due to its bogus value, it
     restyled the whole tree after <body>, fixing any mishandling of restyle
     hints.
@emilio
Copy link
Member Author

emilio commented Aug 17, 2016

@bors-servo: r=SimonSapin,pcwalton

  • Will fill followups for the perf improvements.

@bors-servo
Copy link
Contributor

📌 Commit a46f0c3 has been approved by SimonSapin,pcwalton

@highfive highfive assigned SimonSapin and unassigned pcwalton Aug 17, 2016
@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels Aug 17, 2016
@bors-servo
Copy link
Contributor

⌛ Testing commit a46f0c3 with merge ec7efff...

bors-servo pushed a commit that referenced this pull request Aug 17, 2016
Rewrite the style sharing candidate cache

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

See the first commit's description for a bit of background. I'm making the PR in this state just to verify against try I've handled all cases of possibly incorrect sharing and, if not, fix it.

---
<!-- 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 #12534

<!-- Either: -->
- [x] There are tests for these changes OR

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

💔 Test failed - linux-rel

@highfive highfive added S-tests-failed The changes caused existing tests to fail. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Aug 17, 2016
@emilio
Copy link
Member Author

emilio commented Aug 17, 2016

@bors-servo: retry

That was my fault, I was investigating WebGL tests failures in the build
slave and I had a wpt socket already up, sorry.

On 08/17/2016 02:54 PM, bors-servo wrote:

💔 Test failed - linux-rel
http://build.servo.org/builders/linux-rel/builds/2689


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#12668 (comment), or
mute the thread
https://github.com/notifications/unsubscribe-auth/ABQwupceLBqmNCwTaYrzb6mpEVLvxlvPks5qg4MsgaJpZM4JY-U9.

@bors-servo
Copy link
Contributor

⚡ Previous build results for arm32, arm64, linux-dev, mac-dev-unit, mac-rel-css, windows-dev are reusable. Rebuilding only linux-rel, mac-rel-wpt...

@bors-servo
Copy link
Contributor

☀️ Test successful - arm32, arm64, linux-dev, linux-rel, mac-dev-unit, mac-rel-css, mac-rel-wpt, windows-dev

@bors-servo bors-servo merged commit a46f0c3 into servo:master Aug 18, 2016
@emilio emilio deleted the style-cache branch August 27, 2016 03:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-tests-failed The changes caused existing tests to fail.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Style sharing candidate cache code is probably not working as intended.
7 participants