Skip to content

Commit

Permalink
CSS 2020 queries (#1577)
Browse files Browse the repository at this point in the history
* css feedback

* rework

* custom props and units

* note

* Add queries for all functions and all properties

* Fix bug with all properties query

* Normalize non-custom properties to lowercase

* Add query for all Blink Features

For @supports and a number of other things

* Create keyword_totals.sql

* Create vendor_prefix_summary.sql

* Create meta_shorthand_first_pages.sql

* spaces for tabs

* Update sql/2020/01_CSS/vendor_prefix_summary.sql

Co-authored-by: Rick Viscomi <[email protected]>

* Update sql/2020/01_CSS/vendor_prefix_summary.sql

Co-authored-by: Rick Viscomi <[email protected]>

* Update meta_longhand_first_distribution.sql

* Avoid counting vendor prefix functions and keywords when value.length > 1000

* Create repetition.sql

* Update repetition.sql

* Improve repetition query

* Update vendor_prefix_summary.sql

* Update sass_nesting.sql

* Update all_features.sql

Query the summary table instead

* Update sql/2020/01_CSS/vendor_prefix_summary.sql

* support AST >= 100KB for color/gradient queries

* gradient adoption

* gradient hints

Co-authored-by: Rick Viscomi <[email protected]>
Co-authored-by: Rick Viscomi <[email protected]>
  • Loading branch information
3 people authored Dec 7, 2020
1 parent 3f222c5 commit b269c2e
Show file tree
Hide file tree
Showing 26 changed files with 1,049 additions and 56 deletions.
12 changes: 12 additions & 0 deletions sql/2020/01_CSS/all_features.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
SELECT
client,
feature,
num_urls AS freq,
total_urls AS total,
pct_urls AS pct_pages
FROM
`httparchive.blink_features.usage`
WHERE
yyyymmdd = '20200801'
ORDER BY
pct_pages DESC
54 changes: 54 additions & 0 deletions sql/2020/01_CSS/all_functions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#standardSQL
CREATE TEMPORARY FUNCTION getProperties(css STRING) RETURNS ARRAY<STRING> LANGUAGE js AS '''
try {
function compute() {
let ret = {};
walkDeclarations(ast, ({property, value}) => {
if (value.length > 1000 || !value.includes("(") || !value.includes(")")) {
return;
}
for (let {name} of extractFunctionCalls(value)) {
incrementByKey(ret, name);
}
});
return sortObject(ret);
}
let ast = JSON.parse(css);
let props = compute(ast);
return Object.entries(props).flatMap(([prop, freq]) => {
return Array(freq).fill(prop);
});
}
catch (e) {
return [];
}
'''
OPTIONS (library="gs://httparchive/lib/css-utils.js");

SELECT
*
FROM (
SELECT
client,
prop,
COUNT(DISTINCT page) AS pages,
COUNT(0) AS freq,
SUM(COUNT(0)) OVER (PARTITION BY client) AS total,
COUNT(0) / SUM(COUNT(0)) OVER (PARTITION BY client) AS pct
FROM
`httparchive.almanac.parsed_css`,
UNNEST(getProperties(css)) AS prop
WHERE
date = '2020-08-01'
GROUP BY
client,
prop)
WHERE
pages >= 1000
ORDER BY
pct DESC
51 changes: 51 additions & 0 deletions sql/2020/01_CSS/all_properties.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#standardSQL
CREATE TEMPORARY FUNCTION getProperties(css STRING) RETURNS ARRAY<STRING> LANGUAGE js AS '''
try {
function compute(ast) {
let ret = {};
walkDeclarations(ast, ({property, value}) => {
if (!property.startsWith("--")) { // Custom props are case sensitive
property = property.toLowerCase();
}
incrementByKey(ret, property);
});
return sortObject(ret);
}
let ast = JSON.parse(css);
let props = compute(ast);
return Object.entries(props).flatMap(([prop, freq]) => {
return Array(freq).fill(prop);
});
}
catch (e) {
return [];
}
'''
OPTIONS (library="gs://httparchive/lib/css-utils.js");

SELECT
*
FROM (
SELECT
client,
prop,
COUNT(DISTINCT page) AS pages,
COUNT(0) AS freq,
SUM(COUNT(0)) OVER (PARTITION BY client) AS total,
COUNT(0) / SUM(COUNT(0)) OVER (PARTITION BY client) AS pct
FROM
`httparchive.almanac.parsed_css`,
UNNEST(getProperties(css)) AS prop
WHERE
date = '2020-08-01'
GROUP BY
client,
prop)
WHERE
pages >= 1000
ORDER BY
pct DESC
5 changes: 2 additions & 3 deletions sql/2020/01_CSS/color_arg_comma.sql
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ try {
}

walkDeclarations(ast, ({property, value}) => {
if (value.length > 1000) return;
usage.hex[3] += countMatches(value, /#[a-f0-9]{3}\b/gi);
usage.hex[4] += countMatches(value, /#[a-f0-9]{4}\b/gi);
usage.hex[6] += countMatches(value, /#[a-f0-9]{6}\b/gi);
Expand Down Expand Up @@ -163,8 +164,6 @@ FROM (
FROM
`httparchive.almanac.parsed_css`
WHERE
date = '2020-08-01' AND
# Limit the size of the CSS to avoid OOM crashes.
LENGTH(css) < 0.1 * 1024 * 1024)
date = '2020-08-01')
GROUP BY
client
5 changes: 2 additions & 3 deletions sql/2020/01_CSS/color_formats.sql
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ try {
}

walkDeclarations(ast, ({property, value}) => {
if (value.length > 1000) return;
// First remove url() references to avoid them mucking the results
for (let f of extractFunctionCalls(value, {names: "url"})) {
let [start, end] = f.pos;
Expand Down Expand Up @@ -184,9 +185,7 @@ FROM (
`httparchive.almanac.parsed_css`,
UNNEST(getColorFormats(css)) AS format
WHERE
date = '2020-08-01' AND
# Limit the size of the CSS to avoid OOM crashes.
LENGTH(css) < 0.1 * 1024 * 1024)
date = '2020-08-01')
GROUP BY
client,
format
Expand Down
3 changes: 1 addition & 2 deletions sql/2020/01_CSS/color_functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ try {
}

walkDeclarations(ast, ({property, value}) => {
if (value.length > 1000) return;
usage.hex[3] += countMatches(value, /#[a-f0-9]{3}\b/gi);
usage.hex[4] += countMatches(value, /#[a-f0-9]{4}\b/gi);
usage.hex[6] += countMatches(value, /#[a-f0-9]{6}\b/gi);
Expand Down Expand Up @@ -166,8 +167,6 @@ FROM (
UNNEST(getColorFunctions(css)) AS function
WHERE
date = '2020-08-01' AND
# Limit the size of the CSS to avoid OOM crashes.
LENGTH(css) < 0.1 * 1024 * 1024 AND
function IS NOT NULL)
JOIN (
SELECT
Expand Down
5 changes: 2 additions & 3 deletions sql/2020/01_CSS/color_keywords.sql
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ try {
}

walkDeclarations(ast, ({property, value}) => {
if (value.length > 1000) return;
// First remove url() references to avoid them mucking the results
for (let f of extractFunctionCalls(value, {names: "url"})) {
let [start, end] = f.pos;
Expand Down Expand Up @@ -174,9 +175,7 @@ FROM (
`httparchive.almanac.parsed_css`,
UNNEST(getColorKeywords(css)) AS keyword
WHERE
date = '2020-08-01' AND
# Limit the size of the CSS to avoid OOM crashes.
LENGTH(css) < 0.1 * 1024 * 1024)
date = '2020-08-01')
GROUP BY
client,
keyword
Expand Down
5 changes: 2 additions & 3 deletions sql/2020/01_CSS/color_keywords_no_system_casefold.sql
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ try {
}

walkDeclarations(ast, ({property, value}) => {
if (value.length > 1000) return;
// First remove url() references to avoid them mucking the results
for (let f of extractFunctionCalls(value, {names: "url"})) {
let [start, end] = f.pos;
Expand Down Expand Up @@ -174,9 +175,7 @@ FROM (
`httparchive.almanac.parsed_css`,
UNNEST(getColorKeywords(css)) AS keyword
WHERE
date = '2020-08-01' AND
# Limit the size of the CSS to avoid OOM crashes.
LENGTH(css) < 0.1 * 1024 * 1024)
date = '2020-08-01')
GROUP BY
client,
keyword
Expand Down
5 changes: 2 additions & 3 deletions sql/2020/01_CSS/color_p3.sql
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ try {
}

walkDeclarations(ast, ({property, value}) => {
if (value.length > 1000) return;
// First remove url() references to avoid them mucking the results
for (let f of extractFunctionCalls(value, {names: "url"})) {
let [start, end] = f.pos;
Expand Down Expand Up @@ -173,9 +174,7 @@ FROM (
`httparchive.almanac.parsed_css`,
UNNEST(getP3Usage(css)) AS p3
WHERE
date = '2020-08-01' AND
# Limit the size of the CSS to avoid OOM crashes.
LENGTH(css) < 0.1 * 1024 * 1024)
date = '2020-08-01')
GROUP BY
client,
p3
Expand Down
5 changes: 2 additions & 3 deletions sql/2020/01_CSS/color_spaces.sql
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ try {
}

walkDeclarations(ast, ({property, value}) => {
if (value.length > 1000) return;
// First remove url() references to avoid them mucking the results
for (let f of extractFunctionCalls(value, {names: "url"})) {
let [start, end] = f.pos;
Expand Down Expand Up @@ -172,9 +173,7 @@ FROM (
`httparchive.almanac.parsed_css`,
UNNEST(getColorSpaces(css)) AS color_space
WHERE
date = '2020-08-01' AND
# Limit the size of the CSS to avoid OOM crashes.
LENGTH(css) < 0.1 * 1024 * 1024)
date = '2020-08-01')
GROUP BY
client,
color_space
Expand Down
Loading

0 comments on commit b269c2e

Please sign in to comment.