Skip to content

Commit 214b6bf

Browse files
authored
use node.prelude/block.children.size instead of walking rules separately (#235)
1 parent 32bfeac commit 214b6bf

File tree

4 files changed

+24
-49
lines changed

4 files changed

+24
-49
lines changed

benchmark/readme.md

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@
22

33
## Running time
44

5-
```
65
Bol.com 468 kB 114ms 4.11 MB/s
7-
Bootstrap 5.0.0 195 kB 48ms 4.06 MB/s
8-
CNN 1.77 MB 380ms 4.65 MB/s
6+
Bootstrap 5.0.0 195 kB 47ms 4.14 MB/s
7+
CNN 1.77 MB 359ms 4.92 MB/s
98
CSS-Tricks 195 kB 50ms 3.9 MB/s
10-
Facebook.com 268 kB 71ms 3.78 MB/s
11-
GitHub.com 514 kB 92ms 5.59 MB/s
12-
Gazelle.nl 972 kB 296ms 3.28 MB/s
13-
Lego.com 246 kB 57ms 4.31 MB/s
14-
Smashing Magazine.com 1.1 MB 288ms 3.83 MB/s
15-
Trello.com 312 kB 75ms 4.15 MB/s
9+
Facebook.com 268 kB 67ms 4.01 MB/s
10+
GitHub.com 514 kB 90ms 5.71 MB/s
11+
Gazelle.nl 972 kB 293ms 3.32 MB/s
12+
Lego.com 246 kB 53ms 4.64 MB/s
13+
Smashing Magazine.com 1.1 MB 279ms 3.95 MB/s
14+
Trello.com 312 kB 77ms 4.05 MB/s
1615
```
1716
1817
## Parsing vs. analyzing
@@ -23,14 +22,14 @@ Trello.com 312 kB 75ms 4.15 MB/s
2322
=====================================================================
2423
File | Size | total | parse | Analyze |
2524
=====================================================================
26-
Bol.com | 468 kB | 340ms | 206ms | 133ms (39.1%) |
27-
Bootstrap 5.0.0 | 195 kB | 128ms | 91ms | 37ms (28.9%) |
28-
CNN | 1.77 MB | 577ms | 375ms | 200ms (34.7%) |
29-
CSS-Tricks | 195 kB | 110ms | 72ms | 35ms (31.8%) |
30-
Facebook.com | 268 kB | 101ms | 42ms | 58ms (57.4%) |
31-
GitHub.com | 514 kB | 120ms | 52ms | 66ms (55.0%) |
32-
Gazelle.nl | 972 kB | 322ms | 208ms | 109ms (33.9%) |
33-
Lego.com | 246 kB | 65ms | 38ms | 26ms (40.0%) |
34-
Smashing Magazine.com | 1.1 MB | 311ms | 166ms | 144ms (46.3%) |
35-
Trello.com | 312 kB | 87ms | 48ms | 38ms (43.7%) |
25+
Bol.com | 468 kB | 322ms | 203ms | 119ms (37.0%) |
26+
Bootstrap 5.0.0 | 195 kB | 131ms | 95ms | 35ms (26.7%) |
27+
CNN | 1.77 MB | 588ms | 402ms | 184ms (31.3%) |
28+
CSS-Tricks | 195 kB | 110ms | 72ms | 36ms (32.7%) |
29+
Facebook.com | 268 kB | 99ms | 44ms | 55ms (55.6%) |
30+
GitHub.com | 514 kB | 122ms | 57ms | 64ms (52.5%) |
31+
Gazelle.nl | 972 kB | 319ms | 217ms | 98ms (30.7%) |
32+
Lego.com | 246 kB | 62ms | 38ms | 24ms (38.7%) |
33+
Smashing Magazine.com | 1.1 MB | 313ms | 164ms | 148ms (47.3%) |
34+
Trello.com | 312 kB | 82ms | 46ms | 35ms (42.7%) |
3635
```

src/__fixtures__/cnn-20220403.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12000,11 +12000,11 @@
1200012000
"declarations": {
1200112001
"min": 0,
1200212002
"max": 31,
12003-
"mean": 2.5101573938506587,
12003+
"mean": 2.510340409956076,
1200412004
"mode": 1,
1200512005
"median": 1,
1200612006
"range": 31,
12007-
"sum": 27431,
12007+
"sum": 27433,
1200812008
"items": [
1200912009
2,
1201012010
1,
@@ -12980,7 +12980,7 @@
1298012980
1,
1298112981
1,
1298212982
1,
12983-
11,
12983+
12,
1298412984
1,
1298512985
1,
1298612986
6,
@@ -13229,7 +13229,7 @@
1322913229
1,
1323013230
5,
1323113231
1,
13232-
5,
13232+
6,
1323313233
1,
1323413234
6,
1323513235
8,

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import parse from 'css-tree/parser'
22
import walk from 'css-tree/walker'
3-
import { analyzeRule } from './rules/rules.js'
43
import { analyzeSpecificity, compareSpecificity } from './selectors/specificity.js'
54
import { colorFunctions, colorNames } from './values/colors.js'
65
import { isFontFamilyKeyword, getFamilyFromFont } from './values/font-families.js'
@@ -200,7 +199,8 @@ const analyze = (css) => {
200199
break
201200
}
202201
case 'Rule': {
203-
const [numSelectors, numDeclarations] = analyzeRule(node)
202+
const numSelectors = node.prelude.children ? node.prelude.children.size : 0
203+
const numDeclarations = node.block.children ? node.block.children.size : 0
204204

205205
totalRules++
206206

src/rules/rules.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)