Closed Bug 1376245 Opened 7 years ago Closed 7 years ago

stylo: Attach styles explicitly to generated content

Categories

(Core :: CSS Parsing and Computation, enhancement, P1)

enhancement

Tracking

()

RESOLVED FIXED
mozilla56
Tracking Status
firefox56 --- fixed

People

(Reporter: bholley, Assigned: bholley)

References

(Blocks 1 open bug)

Details

Attachments

(1 file, 2 obsolete files)

I've been mulling the tiny traversal problem for a while, but haven't had enough uninterrupted time to lay out a full and general solution. However, looking at some profiles this evening, I realized that the vast majority of tiny traversals come from generated content (i.e. ::before and ::after) rather than the long tail of arbitrary NAC generated by the frame constructor. So with some special-casing, we can solve the problem quite nicely for those cases. jryans recent patches make this especially easy. This shaves ~5ms off wikipedia and ~10ms off youtube. A good omen for the week ahead. :-) https://treeherder.mozilla.org/#/jobs?repo=try&revision=99c410fc665c66850fe6a5b250f404cb104700bc
Priority: -- → P1
This avoids a lot of expensive machinery when we've already computed the style.
Attachment #8881198 - Flags: review?(cam)
Comment on attachment 8881198 [details] [diff] [review] Hand the already-resolved style directly to servo when creating generated content. v1 Review of attachment 8881198 [details] [diff] [review]: ----------------------------------------------------------------- ::: layout/base/nsCSSFrameConstructor.cpp @@ +1921,5 @@ > } > > + // Servo has already eagerly computed the style for the container, so we can > + // just stick the style on the element and avoid an additional traversal. > + if (ServoStyleContext* servoContext = aStyleContext->GetAsServo()) { I'm 99% sure you wanted to do pseudoStyleContext here instead. That may explain pretty much all the failures. If it doesn't fix the transitions issue, it may be because we don't process transitions on the parent, and if we reframe and the old pseudo still had transitions, we'd lose track of them until the next restyle I think.
Whoops, yeah. That's what I get for writing the patch too fast :-) https://treeherder.mozilla.org/#/jobs?repo=try&revision=e3652bdb8aa1fa04777b0b02b11e7155e43646c3
Blocks: 1376318
Hm, try push in comment 4 is still busted. Hiro, what's going on here?
Attachment #8881325 - Flags: feedback?(hikezoe)
Attachment #8881198 - Attachment is obsolete: true
Attachment #8881198 - Flags: review?(cam)
MayHaveAnimations flag is set after we traversed the target element and processed a SequentialTask for the element. So, in the failure cases, the pseudo element does not have MayHaveAnimations flag yet unfortunately. I can't immediately figure out another way to know the element *will* have animations.
(In reply to Hiroyuki Ikezoe (:hiro) from comment #6) > MayHaveAnimations flag is set after we traversed the target element and > processed a SequentialTask for the element. So, in the failure cases, the > pseudo element does not have MayHaveAnimations flag yet unfortunately. I > can't immediately figure out another way to know the element *will* have > animations. Ohh, so this is just because we traverse the first time, discover that it has animations, then post the task (and set the flag)... Then do the animation-only traversal. I guess we could check whether the style specifies transitions/animations, but that'd break the web animations API, wouldn't it?
(In reply to Emilio Cobos Álvarez [:emilio] from comment #7) > I guess we could check whether the style specifies transitions/animations, > but that'd break the web animations API, wouldn't it? Can you do WebAnimations for pseudo-element? I'd think you wouldn't be able to, since you can't reach the generated content in the DOM.
> Can you do WebAnimations for pseudo-element? There's a CSSPseudoElement interface which implements Animatable. So you don't get access to the actual generated content, but you do get access to an object that represents the generated content and which can be used to animate it. That said, I do not see any way Gecko currently provides to get your hands on a CSSPseudoElement instance. We don't implement the CSSPseudoElementList interface or window.getPseudoElements, which seems like the one entrypoint that would hand out CSSPseudoElement instances... But maybe we plan to implement those sometime?
(In reply to Boris Zbarsky [:bz] (if a patch has no decent message, automatic r-) from comment #9) > > Can you do WebAnimations for pseudo-element? > > There's a CSSPseudoElement interface which implements Animatable. So you > don't get access to the actual generated content, but you do get access to > an object that represents the generated content and which can be used to > animate it. > > That said, I do not see any way Gecko currently provides to get your hands > on a CSSPseudoElement instance. We don't implement the CSSPseudoElementList > interface or window.getPseudoElements, which seems like the one entrypoint > that would hand out CSSPseudoElement instances... But maybe we plan to > implement those sometime? Brian said we will eventually, but not now, so we don't need to worry about it for now. I implemented the rule checking thing and it doesn't work. It seems that the rule node for the eagerly-computed ::before style has the animation rules at author level, but nothing at the animation cascade level. Debugging this, it looks like animation rules don't come by normal selector matching, but rather via the passed-in AnimationRules [1]. And we pass an empty value for such things when computing pseudo rule nodes [2]. How is this supposed to work? [1] http://searchfox.org/mozilla-central/rev/b425854d9bbd49d5caf9baef3686e49ec91c17ec/servo/components/style/stylist.rs#1133 [2] http://searchfox.org/mozilla-central/rev/1b7b1ec949497e9fc2a9b9dfaccbe894ee2ad5ef/servo/components/style/matching.rs#1232
Flags: needinfo?(bbirtles)
Oh, I see how this works. We really need to check the computed values, not the rule node.
Attachment #8881325 - Attachment is obsolete: true
Attachment #8881325 - Flags: feedback?(hikezoe)
Flags: needinfo?(bbirtles)
This avoids a lot of expensive machinery when we've already computed the style.
Attachment #8881357 - Flags: review?(emilio+bugs)
Attachment #8881357 - Flags: review?(bbirtles)
Emilio and bz are right. We can check specified animation or transition styles instead. And in case of script animations, we currently get pseudo elements via CSS animations, i.e. generating CSS animations on pseudo elements and get the pseudo elements via getAnimations() [1], so we don't need to worrying about the case for now. [1] https://w3c.github.io/web-animations/#dom-animatable-getanimations
I did forget to comment an important thing. The thing what I am concerned is that we have already the animation or transition style when we process CreateGeneratedContentItem because I don't know when we process CreateGeneratedContentItem exactly.
Comment on attachment 8881357 [details] [diff] [review] Hand the already-resolved style directly to servo when creating generated content. v4 Review of attachment 8881357 [details] [diff] [review]: ----------------------------------------------------------------- Animation part looks good to me.
Attachment #8881357 - Flags: review?(bbirtles) → review+
As Hiro points out, the only way to get a CSSPseudoElement object at the moment is using Document.getAnimations or Element.getAnimations({subtree: true}), neither of which we currently ship, and even when we do, they will only return a CSSPseudoElement object if the element has an animation defined using CSS animations / transitions so it shouldn't affect this case where we're creating the generated content (since script won't have a chance to get this handle and trigger a new animation yet).
Attachment #8881357 - Flags: review?(emilio+bugs) → review+
Pushed by bholley@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/09c6e1a4a6df Hand the already-resolved style directly to servo when creating generated content. r=emilio,r=birtles
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla56
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: