Selector performance Competition
Three efficiency optimization policies for selector are introduced:
1. the rightmost self-selection tool is accurate to reduce the number of sea selections.
". AAA" is optimized to "input. AAA" ----- Hai Xuan *. AAA is converted to Hai Xuan input. AAA
". CTN. AAA" is optimized to ". CTN input. AAA" ----- Hai Xuan *. AAA is converted to Hai Xuan input. AAA
2. Carry the container ID to reduce the number of sea selections.
"Div. AAA" is optimized to "# container Div. AAA" ----- select Div. AAA to select # container input. AAA
3. In addition to the kinship with ID or ID, the relationship should be as simple as possible to reduce the difficulty of lineage identification.
"Body input. AAA" is optimized to "input. AAA" ----- reduces unnecessary relationships.
In many cases, users who write pages can ignore the performance (the selector has been optimized a lot ),
However, some basic optimization strategies should be kept in mind.
Let's take a look at the selector performance competition.
Take situ students of the cutting-edge selector as an example of the speed of the game (http://www.cnblogs.com/rubylouvre/archive/2010/01/27/1657684.html), to see the end of this game there are few places to consider.
Selector |
Comments |
Body: empty |
Multiple Levels of invalid kinship identification. ---- Some selectors have made special Optimizations to the body, so they will show its unique ancestor. The self-selected device does not have a tagname, and whether it can be accurate or not |
Div: Not (. example) |
: Not is used less often, and the probability of use is not weighted in the speed competition. John resig once wrote an articleArticle. |
P: Contains (selectors) |
: Contains is rarely used. |
Div P |
The cost of the three-layer kinship authentication is a little too high. See optimization policy 3" |
Div, P, |
With the "," link character, sizzle sorts and removes duplicates by default. So it is very slow. ---- Default sorting has advantages and disadvantages. Many selector abandoned this policy. |
Div P |
Lineage verification time |
Body Div |
Multiple Levels of invalid kinship identification. ---- Some selectors have made special Optimizations to the body, so they will show its unique ancestor. |
. Note |
The self-selected device does not have a tagname, and whether it can be accurate or not |
Ul. TOC Li. tocline2 |
|
Ul. TOC> Li. tocline2 |
|
Tr. Pattern |
The self-selected device does not have a tagname, and whether it can be accurate or not |
P |
|
Div |
|
Div ~ P |
Low usage Probability |
Div> Div |
Bottom of probability of use |
Div ~ Div |
Low usage Probability |
Div> P |
Low usage Probability |
Body |
Some selectors optimize the body. |
Div + P |
Low usage Probability |
Div [class ^ = exa] [class $ = mple] |
|
Div. Example |
High usage probability. It is recommended. Weighted factors can be considered. |
Ul. tocline2 |
The self-selected device does not have a tagname, and whether it can be accurate or not |
Div. example, Div. Note |
With the "," link character, sizzle sorts and removes duplicates by default. So it is very slow. ---- Default sorting has advantages and disadvantages. Many selector abandoned this policy. |
# Title |
High usage probability. It is recommended. Weighted factors can be considered. |
H1 # title |
|
Div # title |
|
H1 # title + div> P |
Low Probability of use in the second half |
A [href] [Lang] [Class] |
|
Div [Class] |
|
Div [class = example] |
|
Div [class ^ = exa] |
|
Div [class $ = mple] |
|
Div [class * = E] |
|
Div [class | = Dialog] |
|
Div [class! = Made_up] |
|
Div [class ~ = Example] |
|
P: Nth-child (even) |
|
P: Nth-child (2n) |
|
P: Nth-child (ODD) |
|
P: Nth-child (2n + 1) |
|
P: Nth-child (N) |
|
P: Only-Child |
|
P: Last-child |
|
P: First-child |
|
Div: Only-Child |
Low usage probability. Multi-layer kinship identification. The self-selected device does not have a tagname, and whether it can be accurate or not |
Div: only-of-type |
Low usage probability. Multi-layer kinship identification. The self-selected device does not have a tagname, and whether it can be accurate or not |
TH: first-of-type |
Low usage probability. |
TH: Last-of-type |
Low usage probability. |
TD: Nth-of-type (even) |
Low usage probability. |
TD: Nth-last-of-type (ODD) |
Low usage probability. |
TD: odd |
|
P: Even |
|
To sum up, analyze the main issues:
In the speed competition, most of the time is spent on the use of low probability, or you can consider improving the selector writing method.
Therefore, the total score of the competition is not of great reference significance. Looking at each item, you may gain more.
The only special "," link character. Sizzle does not seem to seriously face this problem-maybe not many people actually use it.
Visual: when the "," separator is selected, sizzle does not optimize the ordering of IE. Otherwise, it takes 600 ms for more than 200 elements, which is a little exaggerated.
In IE, sortby (resultarr, function (EL) {return el. sourceindex + 100000000;}), the time consumed should be reduced to less than 20 ms-take it for granted that it has not been tested.
Https://github.com/wedteam/qwrap/blob/master/resource/js/core/dev/array.h.js