stylo: Trim some fat from the traversal

RESOLVED FIXED

Status

()

Core
CSS Parsing and Computation
RESOLVED FIXED
a year ago
a year ago

People

(Reporter: bholley, Assigned: bholley)

Tracking

(Blocks: 1 bug)

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(3 attachments, 1 obsolete attachment)

(Assignee)

Description

a year ago
I have some patches to reduce overhead in the traversal. A major piece of to avoid enumerating the children twice (once during preprocessing, and once from the traversal driver).
(Assignee)

Comment 5

a year ago
https://treeherder.mozilla.org/#/jobs?repo=try&revision=bddfaea9e0eabb734d0496d2989e346d2deb8549

Finally green. This took way longer than I thought to get right.
(Assignee)

Comment 6

a year ago
Created attachment 8886738 [details] [diff] [review]
Part 1 - Use Drains in parallel.rs. v1

Contrary to the comment around its declaration, we do move the SmallVec in
the replace call. This fixes that.

MozReview-Commit-ID: Bc1qFPpHQ8t
Attachment #8886738 - Flags: review?(emilio+bugs)
(Assignee)

Comment 7

a year ago
Created attachment 8886739 [details] [diff] [review]
Part 2 - Move clearing of dirty descendants bit closer to the last place it's needed. v1

In the next patch, we'll move logic to identify the children for traversal into
preprocess_children (which will be renamed), and the set_dirty_descendants logic
will move along with it. So left as-is, the code here will clobber the flags.

MozReview-Commit-ID: 7ZskKWD4QC3
Attachment #8886739 - Flags: review?(emilio+bugs)
(Assignee)

Comment 8

a year ago
Created attachment 8886740 [details] [diff] [review]
Part 3 - Pass a callback to recalc_style_at to avoid traversing children twice. v1

MozReview-Commit-ID: DIHXaVNzbFM
Attachment #8886740 - Flags: review?(emilio+bugs)
Comment on attachment 8886738 [details] [diff] [review]
Part 1 - Use Drains in parallel.rs. v1

Review of attachment 8886738 [details] [diff] [review]:
-----------------------------------------------------------------

I guess, though the code was nicer before...
Attachment #8886738 - Flags: review?(emilio+bugs) → review+
Attachment #8886739 - Flags: review?(emilio+bugs) → review+
Comment on attachment 8886740 [details] [diff] [review]
Part 3 - Pass a callback to recalc_style_at to avoid traversing children twice. v1

Review of attachment 8886740 [details] [diff] [review]:
-----------------------------------------------------------------

::: servo/components/style/gecko/traversal.rs
@@ +38,3 @@
>      {
>          if node.is_element() {
>              let el = node.as_element().unwrap();

While you're here, can you change this to:

if let Some(el) = node.as_element() {

instead?

::: servo/components/style/traversal.rs
@@ +117,5 @@
>  
>  /// A DOM Traversal trait, that is used to generically implement styling for
>  /// Gecko and Servo.
>  pub trait DomTraversal<E: TElement> : Sync {
>      /// Process `node` on the way down, before its children have been processed.

Please document the new function.

@@ +257,5 @@
>          debug_assert!(node.is_text_node());
>          false
>      }
>  
> +    /// Returns true if traversal is needed for the given element and subtree.

Document that the only place parent_data can be None is if there's no parent?

@@ +617,5 @@
> +    // * This is a reconstruct traversal.
> +    // * This is a servo non-incremental traversal.
> +    //
> +    // Additionally, there are a few scenarios where we avoid traversing the
> +    // subtree even if the element styles are out of date. These cases are

I don't think "the element styles are out of date" is a great description... Maybe just "the children styles"?

@@ +778,5 @@
>          important_rules_changed
>      )
>  }
>  
> +fn note_children<E, D, F>(

I find "note" a very generic name, and it's doing very concrete stuff... Don't have an immediate better suggestion, though I think the previous name is clearer than this (but still not great!)
Attachment #8886740 - Flags: review?(emilio+bugs) → review+
(Assignee)

Comment 11

a year ago
(In reply to Emilio Cobos Álvarez [:emilio] from comment #9)
> Comment on attachment 8886738 [details] [diff] [review]
> Part 1 - Use Drains in parallel.rs. v1
> 
> Review of attachment 8886738 [details] [diff] [review]:
> -----------------------------------------------------------------
> 
> I guess, though the code was nicer before...

Yeah, fair. I realize now that I could have just kept the old code and emptied the array after borrowing it (rather than doing the replace). But I'd probably still want a try push, and otherwise this is land-ready, so I'm just going to land it.

(In reply to Emilio Cobos Álvarez [:emilio] from comment #10)
> I find "note" a very generic name, and it's doing very concrete stuff...
> Don't have an immediate better suggestion, though I think the previous name
> is clearer than this (but still not great!)

Well, pre-process isn't really accurate here, because it both preprocesses and passes them to the caller. We can rename it if we think of a better name.

Thanks for the reviews!
(Assignee)

Comment 13

a year ago
Created attachment 8886818 [details] [diff] [review]
Part 1 - Avoid memmoving the large smallvec in Parallel.rs.

I had to rebase anyway, so I made this more minimal patch for part 1. I'm
going to assume emilio prefers this. :-)

MozReview-Commit-ID: 7nzjMwOmszZ
Attachment #8886818 - Flags: review+
(Assignee)

Updated

a year ago
Attachment #8886738 - Attachment is obsolete: true
(Assignee)

Updated

a year ago
Status: NEW → RESOLVED
Last Resolved: a year ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.