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: Don't loop over all the set of dependencies always. #13108

Merged
merged 1 commit into from Aug 30, 2016

Conversation

@emilio
Copy link
Member

emilio commented Aug 29, 2016

Instead, divide which kind of dependencies could match a mutation. This cuts down incremental restyle time in BrowserHTML quite a bit.


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • There are tests for these changes OR

The dependency count is not at all minor, and this way we avoid looping
through all of them in the common cases, mainly either changing state, or
attributes.


This change is Reviewable

@highfive
Copy link

highfive commented Aug 29, 2016

Heads up! This PR modifies the following files:

  • @bholley: components/style/restyle_hints.rs
@highfive
Copy link

highfive commented Aug 29, 2016

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 Aug 29, 2016

@highfive highfive assigned SimonSapin and unassigned KiChjang Aug 29, 2016
@emilio
Copy link
Member Author

emilio commented Aug 29, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Aug 29, 2016

Trying commit e65c3ea with merge 5687523...

bors-servo added a commit that referenced this pull request Aug 29, 2016
style: Don't loop over all the set of dependencies always.

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

Instead, divide which kind of dependencies could match a mutation. This cuts down incremental restyle time in BrowserHTML quite a bit.

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

<!-- 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. -->

The dependency count is not at all minor, and this way we avoid looping
through all of them in the common cases, mainly either changing state, or
attributes.
@@ -341,16 +341,38 @@ struct Dependency {
#[derive(Debug)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct DependencySet {

This comment has been minimized.

@bholley

bholley Aug 29, 2016

Contributor

Please add a comment above this struct that there are measurable performances wins from storing these separately.

}
}

if !state_changes.is_empty() {

This comment has been minimized.

@bholley

bholley Aug 29, 2016

Contributor

Rather than doing this in three places here, I think this should be abstracted into a method on DependencySet.

}
}

impl DependencySet {
fn test_dependency<E>(&self,

This comment has been minimized.

@bholley

bholley Aug 29, 2016

Contributor

This doesn't really make sense as a Dep on DependencySet. Can we impl it as a method on Vec, or does rust not let us do that? If not, I guess best would be to make it a non-method helper function.

@bholley
Copy link
Contributor

bholley commented Aug 29, 2016

Nice find! Looks good in general, though I'd like to look at the result of the refactor.

@bors-servo
Copy link
Contributor

bors-servo commented Aug 29, 2016

@@ -330,27 +337,52 @@ impl Sensitivities {
/// This allows us to quickly scan through the dependency sites of all style
/// rules and determine the maximum effect that a given state or attribute
/// change may have on the style of elements in the document.
///
/// Note that there are measurable perf wins from storing them separately, and

This comment has been minimized.

@bholley

bholley Aug 29, 2016

Contributor

I don't think the meaning of "storing them separately" is clear in this context.

This comment has been minimized.

@bholley

bholley Aug 29, 2016

Contributor

Would probably be better to move this into the comment on DependencySet, and say "storing attribute and state dependencies separately".

}
}

fn test_dependencies<E>(deps: &[Dependency],

This comment has been minimized.

@bholley

bholley Aug 29, 2016

Contributor

Hm, the free-floating function is still kind of annoying. Could we make a newtype:

struct DependencyList(Vec)

Inside DependencySet and then impl that?

This comment has been minimized.

@bholley

bholley Aug 29, 2016

Contributor

Also, given that we're now storing restyle hints instead of combinators, maybe "test" isn't quite the right word anymore for the operations on DependencyList. Maybe we should call it compute_partial_hint or collect_hints?

@emilio emilio force-pushed the emilio:stupidest-opt-ever branch from 811a3e4 to a02fcbd Aug 29, 2016
}
}
if hint.is_all() {

This comment has been minimized.

@bholley

bholley Aug 29, 2016

Contributor

Nit: Seems like this should go inside the branch where we actually modify hint, right?

This comment has been minimized.

@emilio

emilio Aug 29, 2016

Author Member

Whoops, good catch :-)

attrs_changed: bool,
hint: &mut RestyleHint)
where E: ElementExt
{

This comment has been minimized.

@bholley

bholley Aug 29, 2016

Contributor

It seems cleaner to check hint.is_all() here and early-return, and then not check it in the callers.

@bholley
Copy link
Contributor

bholley commented Aug 29, 2016

r=me with those fixes.

@bors-servo delegate+

@bors-servo
Copy link
Contributor

bors-servo commented Aug 29, 2016

✌️ @emilio can now approve this pull request

The dependency count is not at all minor, and this way we avoid looping
through all of them in the common cases, mainly either changing state, or
attributes.
@emilio emilio force-pushed the emilio:stupidest-opt-ever branch from a02fcbd to 3e80f48 Aug 29, 2016
@emilio
Copy link
Member Author

emilio commented Aug 29, 2016

@bors-servo: r=bholley

@bors-servo
Copy link
Contributor

bors-servo commented Aug 29, 2016

📌 Commit 3e80f48 has been approved by bholley

@bors-servo
Copy link
Contributor

bors-servo commented Aug 29, 2016

Testing commit 3e80f48 with merge 6dfb5f0...

bors-servo added a commit that referenced this pull request Aug 29, 2016
style: Don't loop over all the set of dependencies always.

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

Instead, divide which kind of dependencies could match a mutation. This cuts down incremental restyle time in BrowserHTML quite a bit.

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

<!-- 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. -->

The dependency count is not at all minor, and this way we avoid looping
through all of them in the common cases, mainly either changing state, or
attributes.

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

bors-servo commented Aug 30, 2016

@bors-servo bors-servo merged commit 3e80f48 into servo:master Aug 30, 2016
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 added a commit to emilio/servo that referenced this pull request Aug 30, 2016
I'm stupid, and when I did the last moving-the-code-around, I failed miserably
to double-check it in a debug build.
bors-servo added a commit that referenced this pull request Aug 30, 2016
Fix debug assertion introduced in #13108 by me.

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

---
<!-- 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 #13125 (github issue number if applicable).

<!-- Either: -->
- [x] These changes do not require tests because #13127

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

I'm stupid, and when I did the last moving-the-code-around, I failed miserably
to double-check it in a debug build.

<!-- 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/13128)
<!-- Reviewable:end -->
samuknet added a commit to samuknet/servo that referenced this pull request Sep 6, 2016
I'm stupid, and when I did the last moving-the-code-around, I failed miserably
to double-check it in a debug build.
@emilio emilio deleted the emilio:stupidest-opt-ever branch Apr 12, 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

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