The RuleProcessorData constructor pretty routinely shows up in profiles as a few % of total time. For profiles of things like querySelector or frame construction it can be closer to 10%.

The fundamental design assumption with RuleProcessorData is that a single element is compared to a bunch of selectors, so that it makes sense to pre-grab all sorts of information about the element and then have fast access to it.

But in practice, not all RuleProcessorDatas are created equal. The querySelector ones only ever get compared to one selector. The ones created by the LHS selector of various combinators might not be compared to as many selectors as the RHS.

I did some measuring (excluding XUL elements for now due to bug 523047, but I should consider measuring even with those rules in), and after a bit of gmailing I have some data in histogram form (sadly the histogram bar sizes seem to be the log_2 of the number, not the number itself). "RHS selectors" refers to rule processor data that was not created due to needing to test an ancestor or prev sibling due to a combinator. "LHS" selectors" refers to data created due to combinators. "Matches against ___ selectors" are the number of SelectorMatches calls for data of that type. "Matches against non-tag ___ selectors" are numbers of such calls that make it past the tag/namespace check up front. "Matches against non-tag non-class non-id ___ selectors" are numbers of such calls that make it past the tag, class, and id checks (I moved the class and id checks earlier in SelectorMatches).

Summary: for the "LHS" case, 88% of the RuleProcessorData only need tag/namespace/id/class to not match and 95% are only matched against one selector that includes anything other than tag/namespace/id/class. If I only look at tag/namespace, then the numbers are 2 and 11% respectively. For the "RHS" case, the tag/namespace/id/class numbers are 70% and 71% respectively. The tag/namespace numbers are 26% and 50%. Note that in general there are 3x as many "LHS" SelectorMatches calls as there are "RHS" ones on gmail.

I'm going to try to get some numbers from our Tp set as well, but at first glance it looks like at least for LHS selectors we should consider lazy-initializing everything other than tag/namespace/id/class. For RHS selectors it might even be worth lazy-initializing id/class, since a quarter of the selectors don't need even those, and they aren't that cheap to initialize...

Histogram data:

mean Matches against LHS selectors 12.516, std. deviation 10.1721, max 50
        [     0]:        0
        [     1]:    21314 ***************
        [     2]:    60864 ****************
[     3,      4]:    31481 ***************
[     5,      8]:    67105 *****************
[     9,     16]:    64733 ****************
[    17,     32]:     8112 *************
[    33,     64]:        0
[    65,    128]:        0
[   129,    256]:        0
[   257,    512]+        0

mean Matches against non-tag LHS selectors 10.3095, std. deviation 9.08071, max 47
        [     0]:     4244 *************
        [     1]:    22969 ***************
        [     2]:    68128 *****************
[     3,      4]:    50734 ****************
[     5,      8]:    42523 ****************
[     9,     16]:    56968 ****************
[    17,     32]:     8043 *************
[    33,     64]:        0
[    65,    128]:        0
[   129,    256]:        0
[   257,    512]+        0

mean Matches against non-tag non-class non-id LHS selectors 0.20821, std. deviation 0
.699949, max 10
        [     0]:   224166 ******************
        [     1]:    17347 ***************
        [     2]:     6340 *************
        [     3]:     1045 ***********
        [     4]:     4040 ************
        [     5]:      608 **********
        [     6]:       47 ******
        [     7]:        0
        [     8]:        0
        [     9]:        0
        [    10]+       16 ****

mean Matches against RHS selectors 16.7178, std. deviation 35.2128, max 501
        [     0]:    22216 ***************
        [     1]:    21129 ***************
        [     2]:        2 *
[     3,      4]:      171 ********
[     5,      8]:    21572 ***************
[     9,     16]:     9827 **************
[    17,     32]:     7552 *************
[    33,     64]:      718 **********
[    65,    128]:     3460 ************
[   129,    256]:      160 ********
[   257,    512]+        0

mean Matches against non-tag RHS selectors 8.09371, std. deviation 15.0481, max 75
        [     0]:    60925 ****************
        [     1]:      454 *********
        [     2]:        4 **
[     3,      4]:     2015 ***********
[     5,      8]:     4961 *************
[     9,     16]:    10514 **************
[    17,     32]:     7471 *************
[    33,     64]:      463 *********
[    65,    128]:        0
[   129,    256]:        0
[   257,    512]+        0

mean Matches against non-tag non-class non-id RHS selectors 7.94906, std. deviation 1
5.0236, max 75
        [     0]:    61272 ****************
        [     1]:      107 *******
        [     2]:      190 ********
[     3,      4]:     3136 ************
[     5,      8]:     3816 ************
[     9,     16]:    10376 **************
[    17,     32]:     7447 *************
[    33,     64]:      463 *********
[    65,    128]:        0
[   129,    256]:        0
[   257,    512]+        0

-Boris
_______________________________________________
dev-tech-layout mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-layout

Reply via email to