Closed Bug 1228877 Opened 9 years ago Closed 9 years ago

nsStyleContext::HasChildThatUsesGrandancestorStyle is slow

Categories

(Core :: CSS Parsing and Computation, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla45
Tracking Status
firefox45 --- fixed

People

(Reporter: dbaron, Assigned: dbaron)

Details

(Keywords: perf)

Attachments

(1 file)

I just took a profile in which 5% of the time was in nsStyleContext::HasChildThatUsesGrandancestorStyle .

(I was profiling the leaflet-osm-conversion branch of https://github.com/dbaron/timezone-map .  I'd definitely expect this to have some elements with very large numbers of different children.)

This seems trivial to fix; we should just set the bit on the parent and rename the bit to NS_STYLE_CHILD_USES_GRANDANCESTOR_STYLE
Assignee: nobody → dbaron
Comment on attachment 8693379 [details] [diff] [review]
Make nsStyleContext::HasChildThatUsesGrandancestorStyle by setting bit on grandchild's parent instead of grandchild

I was going to put this in heycam's queue for when he gets back, but given that I can't, I'll ask xidorn to review it...
Attachment #8693379 - Flags: review?(quanxunzhen)
Comment on attachment 8693379 [details] [diff] [review]
Make nsStyleContext::HasChildThatUsesGrandancestorStyle by setting bit on grandchild's parent instead of grandchild

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

Looks like a mostly straightforward refactoring.

r=me with some nits below.

::: layout/style/nsRuleNode.cpp
@@ +1714,4 @@
>      return;
>    }
>  
>    for (;;) {

It seems this loop could now be simplified to a tranditional "for" loop to make things more compact and clearer. (And the "if" above could probably be removed as well, so that we don't have two identical assertions.)

::: layout/style/nsStyleContext.h
@@ +246,5 @@
>                     "parent mismatch");
>      }
>    }
>  
> +  // Does any child this style context, or any of its descendants, have

Does any child *of*. Probably only "Does any of this context's descendants" is enough now.
Attachment #8693379 - Flags: review?(quanxunzhen) → review+
(In reply to Xidorn Quan [:xidorn] (UTC+10) from comment #3)
> It seems this loop could now be simplified to a tranditional "for" loop to
> make things more compact and clearer. (And the "if" above could probably be
> removed as well, so that we don't have two identical assertions.)

Indeed.   This also removes the requirement that callers check that the inherited-from context is not the parent, so I removed that condition from the initial assertion, although I didn't adjust either of the callers.
https://hg.mozilla.org/integration/mozilla-inbound/rev/4a3c509bcb25a533b0eb161f2c5604962a837c37
Bug 1228877 - Make nsStyleContext::HasChildThatUsesGrandancestorStyle by setting bit on grandchild's parent instead of grandchild.  r=xidorn
https://hg.mozilla.org/integration/mozilla-inbound/rev/ddaae692ddd9a7427fe18e93334d80a1f49bac96
Bug 1228877 - Make nsStyleContext::HasChildThatUsesGrandancestorStyle by setting bit on grandchild's parent instead of grandchild.  r=xidorn
Flags: needinfo?(dbaron)
https://hg.mozilla.org/mozilla-central/rev/ddaae692ddd9
Status: NEW → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla45
Comment on attachment 8693379 [details] [diff] [review]
Make nsStyleContext::HasChildThatUsesGrandancestorStyle by setting bit on grandchild's parent instead of grandchild

Probably good for heycam to have a look at this now that he's back.
Attachment #8693379 - Flags: feedback?(cam)
Comment on attachment 8693379 [details] [diff] [review]
Make nsStyleContext::HasChildThatUsesGrandancestorStyle by setting bit on grandchild's parent instead of grandchild

I probably should have looked at this earlier, but the code is now gone. :-)
Attachment #8693379 - Flags: feedback?(cam)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: