Skip to content

Commit 3d31ca3

Browse files
kevinfarrugiaguacamgiffordtunetheweb
authored
Performance 2024 Queries (#3712)
* Migrated queries from previous editions * Removed TABLESAMPLE; Resolved lint errors * Updated sqlfluff and re-run linter * prefer_count_0 * Reverted .sqlfluff * Add performance queries * Update web_vitals_by_technology.sql Fixing Linter error - Files must end with a single trailing newline. * Update monthly_cls_lcp.sql Fixing linter error * Update font_usage_mobile.sql Fixing linter * Update render_blocking_resources.sql Fixing linter error * Update render_blocking_resources.sql adding spaces. * Add font_resource_hints_usage query * Updated bfcache_unload due to changes in Lighthouse audits structure * Removed sampling * Added render_blocking_savings_* * Added query for web_vitals root and secondary page * Updated secondary pages CWV * Update performance queries * Added resource hint queries * Resolved lint issues * Reverted change to lcp_preload_discoverable * Added queries for client-side generated content * Updated PR following review * Removed TABLESAMPLE --------- Co-authored-by: guaca <estela.francoc@gmail.com> Co-authored-by: Mike Gifford <mike.gifford@civicactions.com> Co-authored-by: Barry Pollard <barrypollard@google.com>
1 parent f610a48 commit 3d31ca3

40 files changed

Lines changed: 2403 additions & 0 deletions
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
CREATE TEMP FUNCTION HAS_NO_STORE_DIRECTIVE(cache_control STRING) RETURNS BOOL AS (
2+
REGEXP_CONTAINS(cache_control, r'(?i)\bno-store\b')
3+
);
4+
5+
WITH requests AS (
6+
SELECT
7+
client,
8+
LOGICAL_OR(HAS_NO_STORE_DIRECTIVE(JSON_VALUE(payload, '$._cacheControl'))) AS includes_ccns
9+
FROM
10+
`httparchive.all.requests`
11+
WHERE
12+
date = '2024-06-01' AND
13+
is_main_document
14+
GROUP BY
15+
client,
16+
page
17+
)
18+
19+
SELECT
20+
client,
21+
COUNTIF(includes_ccns) AS pages,
22+
COUNT(0) AS total,
23+
COUNTIF(includes_ccns) / COUNT(0) AS pct
24+
FROM
25+
requests
26+
GROUP BY
27+
client
28+
ORDER BY
29+
client
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
CREATE TEMPORARY FUNCTION getUnloadHandler(audit STRING)
2+
RETURNS BOOL LANGUAGE js AS '''
3+
try {
4+
var $ = JSON.parse(audit);
5+
return $.details?.items?.some(n => n.value?.toLowerCase() === "unloadhandler");
6+
} catch (e) {
7+
return false;
8+
}
9+
''';
10+
11+
WITH lh AS (
12+
SELECT
13+
client,
14+
page,
15+
rank,
16+
getUnloadHandler(JSON_EXTRACT(lighthouse, '$.audits.deprecations')) AS has_unload
17+
FROM
18+
`httparchive.all.pages`
19+
WHERE
20+
date = '2024-06-01'
21+
)
22+
23+
24+
SELECT
25+
client,
26+
_rank AS rank,
27+
COUNTIF(has_unload) AS pages,
28+
COUNT(0) AS total,
29+
COUNTIF(has_unload) / COUNT(0) AS pct
30+
FROM
31+
lh,
32+
UNNEST([1000, 10000, 100000, 1000000, 10000000, 100000000]) AS _rank
33+
WHERE
34+
rank <= _rank
35+
GROUP BY
36+
client,
37+
rank
38+
ORDER BY
39+
rank,
40+
client
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
WITH lh AS (
2+
SELECT
3+
client,
4+
ARRAY_LENGTH(JSON_QUERY_ARRAY(lighthouse, '$.audits.non-composited-animations.details.items')) AS num_animations
5+
FROM
6+
`httparchive.all.pages`
7+
WHERE
8+
date = '2024-06-01' AND
9+
is_root_page
10+
)
11+
12+
13+
SELECT
14+
percentile,
15+
client,
16+
APPROX_QUANTILES(num_animations, 1000)[OFFSET(percentile * 10)] AS num_animations,
17+
COUNTIF(num_animations > 0) AS pages,
18+
COUNT(0) AS total,
19+
COUNTIF(num_animations > 0) / COUNT(0) AS pct
20+
FROM
21+
lh,
22+
UNNEST([10, 25, 50, 75, 90, 100]) AS percentile
23+
GROUP BY
24+
percentile,
25+
client
26+
ORDER BY
27+
percentile,
28+
client
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
WITH lh AS (
2+
SELECT
3+
client,
4+
CAST(JSON_VALUE(unsized_image, '$.node.boundingRect.height') AS INT64) AS height
5+
FROM
6+
`httparchive.all.pages`,
7+
UNNEST(JSON_QUERY_ARRAY(lighthouse, '$.audits.unsized-images.details.items')) AS unsized_image
8+
WHERE
9+
date = '2024-06-01' AND
10+
is_root_page
11+
)
12+
13+
14+
SELECT
15+
percentile,
16+
client,
17+
APPROX_QUANTILES(height, 1000)[OFFSET(percentile * 10)] AS height,
18+
COUNT(0) AS unsized_images
19+
FROM
20+
lh,
21+
UNNEST([10, 25, 50, 75, 90, 100]) AS percentile
22+
GROUP BY
23+
percentile,
24+
client
25+
ORDER BY
26+
percentile,
27+
client
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
WITH lh AS (
2+
SELECT
3+
client,
4+
ARRAY_LENGTH(JSON_QUERY_ARRAY(lighthouse, '$.audits.unsized-images.details.items')) AS num_unsized_images
5+
FROM
6+
`httparchive.all.pages`
7+
WHERE
8+
date = '2024-06-01' AND
9+
is_root_page
10+
)
11+
12+
13+
SELECT
14+
percentile,
15+
client,
16+
APPROX_QUANTILES(num_unsized_images, 1000)[OFFSET(percentile * 10)] AS num_unsized_images,
17+
COUNTIF(num_unsized_images > 0) AS pages,
18+
COUNT(0) AS total,
19+
COUNTIF(num_unsized_images > 0) / COUNT(0) AS pct
20+
FROM
21+
lh,
22+
UNNEST([10, 25, 50, 75, 90, 100]) AS percentile
23+
GROUP BY
24+
percentile,
25+
client
26+
ORDER BY
27+
percentile,
28+
client
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
CREATE TEMPORARY FUNCTION getResourceHints(payload STRING)
2+
RETURNS ARRAY < STRUCT < name STRING, href STRING >>
3+
LANGUAGE js AS '''
4+
var hints = new Set(['preload', 'prefetch', 'preconnect', 'prerender', 'dns-prefetch']);
5+
try {
6+
var $ = JSON.parse(payload);
7+
var almanac = JSON.parse($._almanac);
8+
return almanac['link-nodes'].nodes.reduce((results, link) => {
9+
var hint = link.rel.toLowerCase();
10+
if (!hints.has(hint)) {
11+
return results;
12+
}
13+
results.push({
14+
name: hint,
15+
href: link.href
16+
});
17+
return results;
18+
}, []);
19+
} catch (e) {
20+
return [];
21+
}
22+
''';
23+
24+
WITH resource_hints AS (
25+
SELECT DISTINCT
26+
client,
27+
page,
28+
hint.name
29+
FROM
30+
`httparchive.all.pages`
31+
LEFT JOIN
32+
UNNEST(getResourceHints(payload)) AS hint
33+
WHERE
34+
date = '2024-06-01' AND
35+
is_root_page
36+
),
37+
38+
font_requests AS (
39+
SELECT
40+
client,
41+
page,
42+
type
43+
FROM
44+
`httparchive.all.requests`
45+
WHERE
46+
date = '2024-06-01' AND
47+
type = 'font' AND
48+
is_root_page
49+
)
50+
51+
SELECT
52+
client,
53+
name,
54+
COUNT(DISTINCT page) AS pages,
55+
SUM(COUNT(DISTINCT page)) OVER (PARTITION BY client) AS total,
56+
COUNT(DISTINCT page) / SUM(COUNT(DISTINCT page)) OVER (PARTITION BY client) AS pct_hints
57+
FROM
58+
resource_hints
59+
LEFT JOIN
60+
font_requests
61+
USING
62+
(client, page)
63+
GROUP BY
64+
client, name, type
65+
ORDER BY
66+
pct_hints DESC;
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
CREATE TEMPORARY FUNCTION getResourceHints(payload STRING)
2+
RETURNS ARRAY < STRUCT < name STRING, href STRING >>
3+
LANGUAGE js AS '''
4+
var hints = new Set(['preload', 'prefetch', 'preconnect', 'prerender', 'dns-prefetch']);
5+
try {
6+
var $ = JSON.parse(payload);
7+
var almanac = JSON.parse($._almanac);
8+
return almanac['link-nodes'].nodes.reduce((results, link) => {
9+
var hint = link.rel.toLowerCase();
10+
if (!hints.has(hint)) {
11+
return results;
12+
}
13+
results.push({
14+
name: hint,
15+
href: link.href
16+
});
17+
return results;
18+
}, []);
19+
} catch (e) {
20+
return [];
21+
}
22+
''';
23+
24+
WITH resource_hints AS (
25+
SELECT DISTINCT
26+
client,
27+
date,
28+
page,
29+
hint.name AS name
30+
FROM
31+
`httparchive.all.pages`
32+
LEFT JOIN
33+
UNNEST(getResourceHints(payload)) AS hint
34+
WHERE
35+
(date = '2024-06-01' OR date = '2023-06-01' OR date = '2022-06-01') AND
36+
is_root_page
37+
),
38+
39+
font_requests AS (
40+
SELECT
41+
client,
42+
date,
43+
page,
44+
type
45+
FROM
46+
`httparchive.all.requests`
47+
WHERE
48+
(date = '2024-06-01' OR date = '2023-06-01' OR date = '2022-06-01') AND
49+
type = 'font' AND
50+
is_root_page
51+
),
52+
53+
totals AS (
54+
SELECT
55+
client,
56+
date,
57+
COUNT(0) AS total_pages
58+
FROM
59+
`httparchive.all.pages`
60+
WHERE
61+
(date = '2024-06-01' OR date = '2023-06-01' OR date = '2022-06-01') AND
62+
is_root_page
63+
GROUP BY
64+
client,
65+
date
66+
)
67+
68+
SELECT
69+
client,
70+
date,
71+
name,
72+
type,
73+
COUNT(DISTINCT page) AS pages,
74+
ANY_VALUE(total_pages) AS total,
75+
COUNT(DISTINCT page) / ANY_VALUE(total_pages) AS pct
76+
FROM
77+
resource_hints
78+
LEFT JOIN
79+
font_requests
80+
USING
81+
(client, date, page)
82+
JOIN
83+
totals
84+
USING
85+
(client, date)
86+
GROUP BY
87+
client,
88+
date,
89+
name,
90+
type
91+
HAVING
92+
type IS NOT NULL
93+
ORDER BY
94+
client,
95+
date,
96+
name DESC
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
SELECT
2+
COUNTIF(SAFE_CAST(JSON_EXTRACT_SCALAR(summary, '$.reqFont') AS INT64) > 0) AS freq_fonts,
3+
COUNT(0) AS total,
4+
COUNTIF(SAFE_CAST(JSON_EXTRACT_SCALAR(summary, '$.reqFont') AS INT64) > 0) / COUNT(0) AS pct_fonts
5+
FROM
6+
`httparchive.all.pages`
7+
WHERE
8+
date = '2024-06-01' AND
9+
client = 'mobile' AND
10+
is_root_page AND
11+
SAFE_CAST(JSON_EXTRACT_SCALAR(summary, '$.reqFont') AS INT64) IS NOT NULL AND
12+
SAFE_CAST(JSON_EXTRACT_SCALAR(summary, '$.bytesFont') AS INT64) IS NOT NULL

0 commit comments

Comments
 (0)