Closed
Bug 1273303
Opened 8 years ago
Closed 7 years ago
style sheet additions (etc.) should check that rules might apply to the current document
Categories
(Core :: CSS Parsing and Computation, defect)
Core
CSS Parsing and Computation
Tracking
()
RESOLVED
WONTFIX
Performance Impact | medium |
People
(Reporter: dbaron, Assigned: bugs)
References
(Depends on 1 open bug)
Details
(Keywords: perf, Whiteboard: [platform-rel-Facebook])
Sites that dynamically add style sheets while pages are already loaded often do this in a way that the added style sheets cannot affect elements in the current page.
We should optimize for this by improving the aStyleSheet->HasRules() checks in methods like PresShell::StyleSheetAdded, etc. (all of the ones that call RecordStyleSheetChange) to check that there is at least one rule in the sheet that doesn't require the presence of an id or class that's known not to be in the document.
This requires maintaining a data structure for all of the ids/classes that are in the document -- or perhaps even better -- all the ones we've resolved style for.
We'd still need to rebuild the rule cascade -- which might make the dynamic media query change handling a little bit tricky (see, e.g., bug 1089417).
We also might want to first measure to try to figure out, for important cases, how much performance improvement we'd get from this versus bug 1273302.
Comment 1•8 years ago
|
||
We have nsDocument::mIdentifierMap, which stores elements by id="" (and by name=""). Not sure if it's better to extend that to store elements by class="" too or to do as you suggest and have a separate table of IDs/classes that were used during previous selector matchings.
With bug 1213122 we will take all of the selectors in the added style sheet and only resolve style for elements in the document that do match them. If that lands, we could skip adding selectors for those that fail this ID/class test.
Reporter | ||
Comment 2•8 years ago
|
||
FWIW, I believe this approach will be good enough to suppress the restyles for Facebook, and likely other sites that take a similar approach. And it should be much cheaper than scanning the document, per-selector.
It's also probably worth issuing a console warning when we do have to restyle, and saying which selector was responsible.
Updated•8 years ago
|
platform-rel: --- → ?
Whiteboard: [platform-rel-Facebook]
Updated•8 years ago
|
platform-rel: ? → +
Updated•8 years ago
|
Rank: 5
Assignee | ||
Comment 3•8 years ago
|
||
I'm inclined to implement this in Stylo rather than in the existing Gecko style system.
+cc: Xidorn who's now working on Stylo's StyleSheet handling to put this on his radar.
Updated•8 years ago
|
Rank: 5 → 51
Comment 4•8 years ago
|
||
I wonder how it makes sense to add a style sheet that the page doesn't use at the moment. Is that just for preloading the stylesheet? For that, I think the website should either add a style sheet which is disabled initially, and enable it later, or just use the resouce hint to trigger preload.
I'm not sure whether we've optimized for adding disabled style sheet, but that seems to be a much easier optimization than trying to figure out whether the style sheet could potentially affect the current rendering.
Reporter | ||
Comment 5•8 years ago
|
||
This is apparently very common in large (and widely used!) sites that use large module systems for their content. They ensure that they styles they add don't apply to the current page, and then add the content to the page that depends on those styles.
Updated•8 years ago
|
Blocks: QuantumFlow
Updated•8 years ago
|
Whiteboard: [platform-rel-Facebook] → [platform-rel-Facebook][qf]
Updated•8 years ago
|
Whiteboard: [platform-rel-Facebook][qf] → [platform-rel-Facebook][qf:p1]
Comment 6•8 years ago
|
||
(In reply to Jet Villegas (:jet) from comment #3)
> I'm inclined to implement this in Stylo rather than in the existing Gecko
> style system.
Is this bug in the scope of stylo implementation ?
Flags: needinfo?(cam)
Comment 7•8 years ago
|
||
It's not one of the optimizations we discussed on Friday, but it's certainly something we could do in Stylo. (And I agree that putting effort into doing it in Stylo rather than Gecko is the right thing to do.) Given that this is on the Quantum Flow radar -- Bobby, do you think we should add this to our backlog?
Flags: needinfo?(cam) → needinfo?(bobbyholley)
Comment 8•8 years ago
|
||
I would really want to see this done as part of stylo (I thought about doing that as a followup, given there's so much to do already, but we could also try to do it now).
Se an analysis of the blink approach at https://bugzilla.mozilla.org/show_bug.cgi?id=1213122#c34. FWIW they don't have any class to element map, they just do a full DOM traversal. Given we need to potentially do that traversal to do styling too, it seems like a good compromise to me, but we could also have that kind of map.
I think this shouldn't be hard to do, specially for the easy cases like bug 1213122 and facebook (which uses mostly class scopes). I can take this once I'm done with bug 1355343 and dependencies if you want.
Comment 9•8 years ago
|
||
(In reply to Emilio Cobos Álvarez [:emilio] from comment #8)
> I would really want to see this done as part of stylo (I thought about doing
> that as a followup, given there's so much to do already, but we could also
> try to do it now).
>
> Se an analysis of the blink approach at
> https://bugzilla.mozilla.org/show_bug.cgi?id=1213122#c34. FWIW they don't
> have any class to element map, they just do a full DOM traversal. Given we
> need to potentially do that traversal to do styling too, it seems like a
> good compromise to me, but we could also have that kind of map.
>
> I think this shouldn't be hard to do, specially for the easy cases like bug
> 1213122 and facebook (which uses mostly class scopes). I can take this once
> I'm done with bug 1355343 and dependencies if you want.
Yes, I think it makes sense to do this. We can use our parallel traversal machinery to make the traversal fast. It should be easy to add a perf-reftest for this as well.
Flags: needinfo?(bobbyholley)
Comment 10•8 years ago
|
||
Filed bug 1357583 for doing this in stylo.
Assignee | ||
Updated•7 years ago
|
Assignee: nobody → bugs
Comment 11•7 years ago
|
||
Since this is a non-trivial style system change, we should aim to fix this in Stylo first (bug 1357583), and then we can "backport" the fix to Gecko (fixing this bug here) as needed.
--> adding dependency on bug 1357583
Depends on: 1357583
Comment 12•7 years ago
|
||
Given comment 11, I'm going to call this [qf:p2] as a Gecko bug.
Whiteboard: [platform-rel-Facebook][qf:p1] → [platform-rel-Facebook][qf:p2]
Comment 13•7 years ago
|
||
Just to be clear, we shouldn't have somebody work on this for the Gecko style system unless it becomes clear that stylo won't make 57.
Comment 14•7 years ago
|
||
dbaron, what was the original context where we saw this showing up on Facebook? If there's a workflow we can profile, it would be interesting to compare stylo vs gecko given bug 1357583.
Flags: needinfo?(dbaron)
Reporter | ||
Comment 15•7 years ago
|
||
The original context was that we were told about it verbally by folks who work at Facebook. I think the thing to profile would probably be initial load of https://www.facebook.com/, perhaps with a preference for a slower network connection. But I'm not entirely sure.
Flags: needinfo?(dbaron)
Comment 16•7 years ago
|
||
Given bug 1357583 is fixed (in Stylo) and I don't think we want to do work on the old style system, I'm going to close this.
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → WONTFIX
Updated•3 years ago
|
Performance Impact: --- → P2
Whiteboard: [platform-rel-Facebook][qf:p2] → [platform-rel-Facebook]
You need to log in
before you can comment on or make changes to this bug.
Description
•