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

style: Avoid selector-matching when only the style attribute is changed. #15317

Merged
merged 2 commits into from Feb 2, 2017

Conversation

@emilio
Copy link
Member

emilio commented Jan 31, 2017

r? @bholley


This change is Reviewable

@highfive
Copy link

highfive commented Jan 31, 2017

Heads up! This PR modifies the following files:

  • @bholley: components/style/data.rs, components/style/restyle_hints.rs, components/style/rule_tree/mod.rs, components/style/traversal.rs, components/style/matching.rs
@highfive
Copy link

highfive commented Jan 31, 2017

warning Warning warning

  • These commits modify style code, but no tests are modified. Please consider adding a test!
@emilio
Copy link
Member Author

emilio commented Jan 31, 2017

@bors-servo
Copy link
Contributor

bors-servo commented Jan 31, 2017

Trying commit 9830752 with merge 2b7124f...

bors-servo added a commit that referenced this pull request Jan 31, 2017
style: Avoid selector-matching when only the style attribute is changed.

r? @bholley

<!-- 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/15317)
<!-- Reviewable:end -->
@emilio
Copy link
Member Author

emilio commented Jan 31, 2017

@bors-servo
Copy link
Contributor

bors-servo commented Jan 31, 2017

💔 Test failed - linux-rel-css

@emilio
Copy link
Member Author

emilio commented Jan 31, 2017

So there are two tests failing there, and I believe none of them is my fault.

The first seems like a timing-related incremental table layout bug (/css21_dev/html4/border-collapse-dynamic-table-002.htm). I can reproduce it sort-of reliably with my patch, but the reflow logs are identical for both, and I've verified that the styles applying are correct (thus my conclusion).

The second I can't reproduce it at all, but seems similarly a reflow issue, not a styling issue:

table
bidi

@emilio
Copy link
Member Author

emilio commented Jan 31, 2017

@bors-servo retry

@bors-servo
Copy link
Contributor

bors-servo commented Jan 31, 2017

Trying commit 9830752 with merge 75a5eeb...

bors-servo added a commit that referenced this pull request Jan 31, 2017
style: Avoid selector-matching when only the style attribute is changed.

r? @bholley

<!-- 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/15317)
<!-- Reviewable:end -->
Copy link
Contributor

bholley left a comment

lgtm with those changes. Thanks for doing this!

/// The rule nodes for each of the pseudo-elements of an element.
///
/// TODO(emilio): Probably shouldn't be a `HashMap` by default, but a smaller
/// array.

This comment has been minimized.

Copy link
@bholley

bholley Jan 31, 2017

Contributor

Can you file a bug against stylo-perf for this?

///
/// FIXME(emilio): We could in theory avoid creating these when we have
/// support for just re-cascading an element. Then the input to
/// `cascade_node` could be `MatchResults` or just `UseExistingStyle`.

This comment has been minimized.

Copy link
@bholley

bholley Jan 31, 2017

Contributor

This too.

}

/// Whether the element holding the hint needs to be restyled on some way.
pub fn needs_restyle_self(&self) -> bool {

This comment has been minimized.

Copy link
@bholley

bholley Jan 31, 2017

Contributor

Let's call this has_self_invalidations.

///
/// This hint is stripped down, and only contains hints that are a subset of
/// RestyleHint::for_single_element().
pub for_self: RestyleHint,

This comment has been minimized.

Copy link
@bholley

bholley Jan 31, 2017

Contributor

Nit: for_self is a bit of a naming clash with |descendants|. It would be nice to call these |self|, but I think that's a reserved keyword in Rust. So maybe just |self_|?


// TODO(emilio): Here we'll need to support animation-only hints
// and similar.
match_results = if data.needs_only_style_attribute_update() {

This comment has been minimized.

Copy link
@bholley

bholley Jan 31, 2017

Contributor

Given that it seems like we'll eventually want to do this the other way around, I think we want the opposite predicate here:

if data.restyle_self() {
// do full selector matching
} else {
if data.style_attribute_changed() {
// Handle style attributes
}
if data.tick_animation() {
// Handle animations
}
// etc
}

So let's get rid of needs_only_style_attribute_update() (since it doesn't scale), and replace it with restyle_self() and style_attribute_changed().

impl RestyleHint {
/// The subset hints that affect the styling of a single element during the
/// traversal.
pub fn for_single_element() -> Self {

This comment has been minimized.

Copy link
@bholley

bholley Jan 31, 2017

Contributor

I'd call this for_self.

@@ -635,6 +627,40 @@ pub trait MatchMethods : TElement {
}
}

/// Updates the style attribute rule nodes without re-running selector
/// matching, using just the rule tree.
fn update_style_attribute(&self,

This comment has been minimized.

Copy link
@bholley

bholley Jan 31, 2017

Contributor

Given that we're going to be stacking this up with similar calls (for animations and transitions, etc), it seems like this should just accept the old rule node as an argument and return a rule node, rather than operating on ElementData and returning MatchResults. We can handle grabbing the old pseudo rule nodes at the callsite, once all the rule tree fixups have been performed.

-> MatchResults {
let style_attribute = self.style_attribute();

let mut new_rule_node = data.styles().primary.rules.clone();

This comment has been minimized.

Copy link
@bholley

bholley Jan 31, 2017

Contributor

Nit: I'd just call this |rule_node|, because it's not new at this point, and it's confusing when we pass the old rule node to replace_rule_level_if_applicable as |new_rule_node|.

// transitions, but could not be so for SMIL animations, which we'd need
// to special-case (isn't hard, it's just about removing the `if` and
// special cases, and replacing them for a `while` loop, avoiding the
// optimizations).

This comment has been minimized.

Copy link
@bholley

bholley Jan 31, 2017

Contributor

Can you file this as a dependency to https://bugzilla.mozilla.org/show_bug.cgi?id=1302948 ?

/// Returns the resulting node that represents the new path.
///
/// TODO(emilio): Maybe this should be in `StrongRuleNode`?
pub fn replace_rule_at_level_if_applicable(&self,

This comment has been minimized.

Copy link
@bholley

bholley Jan 31, 2017

Contributor

So, the if_applicable part of the name here deals with the fact that we might be either inserting or removing, instead of strictly replacing?

How about fn update_rule_at_level(...)?

@bholley
Copy link
Contributor

bholley commented Jan 31, 2017

@bors-servo delegate+

@bors-servo
Copy link
Contributor

bors-servo commented Jan 31, 2017

✌️ @emilio can now approve this pull request

@bors-servo
Copy link
Contributor

bors-servo commented Jan 31, 2017

💔 Test failed - linux-rel-css

@emilio emilio force-pushed the emilio:style-attr-restyle branch from 9830752 to 758c965 Feb 1, 2017
@highfive highfive removed the S-tests-failed label Feb 1, 2017
@emilio emilio force-pushed the emilio:style-attr-restyle branch from 758c965 to bc7c4f0 Feb 1, 2017
@emilio
Copy link
Member Author

emilio commented Feb 1, 2017

@bors-servo
Copy link
Contributor

bors-servo commented Feb 1, 2017

Trying commit bc7c4f0 with merge 5980d6a...

bors-servo added a commit that referenced this pull request Feb 1, 2017
style: Avoid selector-matching when only the style attribute is changed.

r? @bholley

<!-- 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/15317)
<!-- Reviewable:end -->
@emilio
Copy link
Member Author

emilio commented Feb 1, 2017

Bobby, I added another large-ish commit refactoring stuff and adding support for the cascade-only thing, I'd appreciate if you can take another look at it.

@bors-servo
Copy link
Contributor

bors-servo commented Feb 1, 2017

💔 Test failed - mac-rel-css

@emilio
Copy link
Member Author

emilio commented Feb 1, 2017

@bors-servo
Copy link
Contributor

bors-servo commented Feb 1, 2017

Trying commit bc7c4f0 with merge abc0548...

bors-servo added a commit that referenced this pull request Feb 1, 2017
style: Avoid selector-matching when only the style attribute is changed.

r? @bholley

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

bors-servo commented Feb 1, 2017

💔 Test failed - linux-rel-css

/// Whether this element should be restyled during the traversal, and how.
///
/// This hint is stripped down, and only contains hints that are a subset of
/// RestyleHint::for_single_element().

This comment has been minimized.

Copy link
@bholley

bholley Feb 2, 2017

Contributor

Nit: This comment needs updating.

shared_context, &mut data) }
};
// TODO(emilio): Make cascade_input less expensive to compute in the cases
// we don't need to run selector matching.

This comment has been minimized.

Copy link
@bholley

bholley Feb 2, 2017

Contributor

Yeah. I'm not super wild about the structure here, but I'm ok with fixing it up later.

@bholley
Copy link
Contributor

bholley commented Feb 2, 2017

@bors-servo delegate+

@bors-servo
Copy link
Contributor

bors-servo commented Feb 2, 2017

✌️ @emilio can now approve this pull request

emilio added 2 commits Jan 31, 2017
…forward.
@emilio emilio force-pushed the emilio:style-attr-restyle branch from bc7c4f0 to 2594cb9 Feb 2, 2017
@highfive highfive removed the S-tests-failed label Feb 2, 2017
@emilio
Copy link
Member Author

emilio commented Feb 2, 2017

@bors-servo r=bholley

I backed out the first inherited_style_changed patch. It's due to a bug in servo's style damage computation, but I'll submit the fix separately.

@bors-servo
Copy link
Contributor

bors-servo commented Feb 2, 2017

📌 Commit 2594cb9 has been approved by bholley

@bors-servo
Copy link
Contributor

bors-servo commented Feb 2, 2017

Testing commit 2594cb9 with merge fb7f65f...

bors-servo added a commit that referenced this pull request Feb 2, 2017
style: Avoid selector-matching when only the style attribute is changed.

r? @bholley

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

bors-servo commented Feb 2, 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-gnu-dev, windows-msvc-dev
Approved by: bholley
Pushing fb7f65f to master...

@bors-servo bors-servo merged commit 2594cb9 into servo:master Feb 2, 2017
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@emilio emilio deleted the emilio:style-attr-restyle branch Feb 2, 2017
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.

None yet

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