Closed Bug 996776 Opened 7 years ago Closed 7 years ago

[Messages] Speed up reflowing by improving CSS selectors and properties


(Firefox OS Graveyard :: Gaia::SMS, defect, P2)



(Not tracked)

1.4 S6 (25apr)


(Reporter: drs, Unassigned)



(Keywords: perf, Whiteboard: [c=handeye p= s=2014.04.25 u=])


(2 files)

We have some of universal and non-direct descendant selectors in the CSS. I believe we can speed up reflowing in general by eliminating unnecessary specificity.
Blocks: 893838
Summary: [SMS] Speed up CSS selectors and properties → [Messages] Speed up reflowing by improving CSS selectors and properties
(In reply to Doug Sherk (:drs) from comment #0)
> We have some of universal and non-direct descendant selectors in the CSS. I
> believe we can speed up reflowing in general by eliminating unnecessary
> specificity.

Actually this is going to speed up all kind of interactions, +1 :)
Keywords: perf
Priority: -- → P2
Whiteboard: [c=handeye p= s= u=]
I think we should especially have more classes and less compound selectors.

I don't really mind about non-direct descendants by itself if this is only 2 parts, but we have compound selectors with like 4 parts, and 2 IDs.

I'm all for removing IDs in the CSS too. This is gonna be hard and better do it panel by panel.
Here are my two cents: I think we can start from splitting huge sms.css file into more panel-specific files, at least composer, inbox, thread and etc... and optimize it one by one.
Yep, definitely.

All common things should be building blocks already.
+1 To Julien's comment in #2, removing all the tag and descendant selectors and moving towards single class names as much as possible will really speed up selection time.
Okay, I did some looking into this, and suffice it to say I think this is a bust, at least from the perspective of performance. There's definitely some sanity issues, including duplicated styles, bizarre selectors, etc., but I don't think that it's a good use of our time at this point to tackle them.

For starters, I did some research into this. Here are some of the articles I read and a talk I listened to:
[1] (slides) / (audio)
    this article is written about WebKit, but we have since implemented almost everything in it

The older articles give specific optimization tips which involve the things already mentioned in this thread, while the newer ones and the talk mostly focus around eliminating overly generic selectors (such as universals). They also allude to this not actually being worth the time spent to optimize in a lot of cases.

In particular, after listening to David's talk [1], I chatted with him on IRC, and he told me that the new bloom filter that we've implemented in Gecko [2] has eliminated most of the gains we can get by reducing complexity of selectors.

Still, I decided to try doing some optimizations to see what happened. The attached patch includes some really obvious optimizations that could be made. I profiled with and without this, and here are the results:

without patch:
with    patch:

without patch: 1415 ms in layout flush
with    patch: 1394 ms in layout flush

So we eked out 21 ms, or a ~1.5% gain with several of the most obvious optimizations that we could make.

Steve Souders wrote an article [3] which includes benchmarks and shows that even older browsers don't experience significant performance degradation with poorly written selectors. It seems that performance is mostly a function of number of DOM nodes and number of CSS selectors. We're not even close to having the number of CSS selectors or DOM nodes where performance degrades, even on these older browsers.

I'm still not happy that layout takes 1415 ms to complete, and I again chatted with dbaron about this. He says that there's no easy way to profile individual CSS selectors. We also have to remember that a lot of our selectors come from building blocks. He linked me to a snippet which will flush layout, but it isn't indicative of real-world performance:

Anyways, if anyone has any ideas, I'm all ears. If not, I'm going to resolve wontfix this.
As a somewhat humorous thought experiment, I tried deleting all the CSS from sms.css that wasn't absolutely necessary for being able to delete a message. This resulted in about 80% of it being removed. (ship it!)

I then profiled this:

We still spend 1173 ms in layout, and this is obviously not a realistic goal. So I think it's pretty clear that this is a bust.
We can open more bugs to fix sanity issues, but I'll leave that to the SMS app peers for now.
Closed: 7 years ago
Resolution: --- → WONTFIX
Whiteboard: [c=handeye p= s= u=] → [c=handeye p= s=2014.04.25 u=]
Target Milestone: --- → 1.4 S6 (25apr)
Thanks a lot Doug, that was very useful even if no change in the end. At least we know now that this is a dead end!

More than 1sec for layout, this is a lot :(
See Also: → 918347
You need to log in before you can comment on or make changes to this bug.