Skip to content

Commit dfe0e0b

Browse files
authored
Performance 2025 Queries (#4145)
* Begin migrating 2024 queries to 2025 * Migrate 2024 queries to 2025: generated content * sqlfluff lint * Migrate 2024 queries to 2025: INP * Migrate 2024 queries to 2025: JS bytes, LCP (part 1) * Migrate 2024 queries to 2025: LCP (part 2) * Migrate 2024 queries to 2025: Monthly CLS/LCP * Migrate 2024 queries to 2025: Render-Blocking Resources * Migrate 2024 queries to 2025: Resource Hints * Migrate 2024 queries to 2025: RTT, Viewport Meta, and Web Vitals * Update all 2025 performance queries to use July data * Remove FID from 2025 queries * Rename 'pct_cwv_good' * Remove old TODO * Update getUnloadHandler() to handle different Lighthouse versions * Update getUnloadHandler() to only handle Lighthouse >= v12.4.0 values * Rename _rank to ranking * Rename pages to home_pages in cls_animations.sql * Optimize font_resource_hints_usage.sql * Optimize font_resource_hints_usage_trends.sql * Optimize generated_content.sql * Optimize generated_content_web_vitals.sql * sqlfluff * Clean up JSON_VALUE syntax (avoid '$') * Use JSON in lcp_async_fetchpriority.sql * Optimize lcp_element_data.sql * Use JSON in lcp_lazy.sql * Use JSON in lcp_lazy_secondary_pages.sql * Use JSON in lcp_lazy_technologies.sql * Use JSON in lcp_responsive_data.sql * Optimize resource_hints_usage.sql * Use JSON in web_vitals_by_device_secondary_pages.sql * Remove sampling from inp_long_tasks.sql * Delete inp_long_tasks.sql
1 parent ed5ea5c commit dfe0e0b

39 files changed

+2292
-0
lines changed
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.crawl.requests`
11+
WHERE
12+
date = '2025-07-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: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
CREATE TEMPORARY FUNCTION getUnloadHandler(items JSON)
2+
RETURNS BOOL LANGUAGE js AS '''
3+
try {
4+
return items?.some(n => n.value?.toLowerCase()?.includes("unload event listeners"));
5+
} catch (e) {
6+
return false;
7+
}
8+
''';
9+
10+
WITH lh AS (
11+
SELECT
12+
client,
13+
page,
14+
rank,
15+
getUnloadHandler(lighthouse.audits.deprecations.details.items) AS has_unload
16+
FROM
17+
`httparchive.crawl.pages`
18+
WHERE
19+
date = '2025-07-01'
20+
)
21+
22+
SELECT
23+
client,
24+
ranking,
25+
COUNTIF(has_unload) AS pages,
26+
COUNT(0) AS total,
27+
COUNTIF(has_unload) / COUNT(0) AS pct
28+
FROM
29+
lh,
30+
UNNEST([1000, 10000, 100000, 1000000, 10000000, 100000000]) AS ranking
31+
WHERE
32+
rank <= ranking
33+
GROUP BY
34+
client,
35+
ranking
36+
ORDER BY
37+
ranking,
38+
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+
ARRAY_LENGTH(JSON_QUERY_ARRAY(lighthouse.audits.`non-composited-animations`.details.items)) AS num_animations
5+
FROM
6+
`httparchive.crawl.pages`
7+
WHERE
8+
date = '2025-07-01' AND
9+
is_root_page
10+
)
11+
12+
SELECT
13+
percentile,
14+
client,
15+
APPROX_QUANTILES(num_animations, 1000)[OFFSET(percentile * 10)] AS num_animations,
16+
COUNTIF(num_animations > 0) AS home_pages,
17+
COUNT(0) AS total,
18+
COUNTIF(num_animations > 0) / COUNT(0) AS pct
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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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.crawl.pages`,
7+
UNNEST(JSON_QUERY_ARRAY(lighthouse.audits.`unsized-images`.details.items)) AS unsized_image
8+
WHERE
9+
date = '2025-07-01' AND
10+
is_root_page
11+
)
12+
13+
SELECT
14+
percentile,
15+
client,
16+
APPROX_QUANTILES(height, 1000)[OFFSET(percentile * 10)] AS height,
17+
COUNT(0) AS unsized_images
18+
FROM
19+
lh,
20+
UNNEST([10, 25, 50, 75, 90, 100]) AS percentile
21+
GROUP BY
22+
percentile,
23+
client
24+
ORDER BY
25+
percentile,
26+
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+
ARRAY_LENGTH(JSON_QUERY_ARRAY(lighthouse.audits.`unsized-images`.details.items)) AS num_unsized_images
5+
FROM
6+
`httparchive.crawl.pages`
7+
WHERE
8+
date = '2025-07-01' AND
9+
is_root_page
10+
)
11+
12+
SELECT
13+
percentile,
14+
client,
15+
APPROX_QUANTILES(num_unsized_images, 1000)[OFFSET(percentile * 10)] AS num_unsized_images,
16+
COUNTIF(num_unsized_images > 0) AS pages,
17+
COUNT(0) AS total,
18+
COUNTIF(num_unsized_images > 0) / COUNT(0) AS pct
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: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
CREATE TEMPORARY FUNCTION getResourceHints(nodes JSON)
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+
return nodes.reduce((results, link) => {
7+
var hint = link.rel.toLowerCase();
8+
if (!hints.has(hint)) {
9+
return results;
10+
}
11+
results.push({
12+
name: hint,
13+
href: link.href
14+
});
15+
return results;
16+
}, []);
17+
} catch (e) {
18+
return [];
19+
}
20+
''';
21+
22+
WITH resource_hints AS (
23+
SELECT DISTINCT
24+
client,
25+
page,
26+
hint.name
27+
FROM
28+
`httparchive.crawl.pages`
29+
LEFT JOIN
30+
UNNEST(getResourceHints(custom_metrics.other.almanac['link-nodes'].nodes)) AS hint
31+
WHERE
32+
date = '2025-07-01' AND
33+
is_root_page
34+
),
35+
36+
font_requests AS (
37+
SELECT
38+
client,
39+
page,
40+
type
41+
FROM
42+
`httparchive.crawl.requests`
43+
WHERE
44+
date = '2025-07-01' AND
45+
type = 'font' AND
46+
is_root_page
47+
)
48+
49+
SELECT
50+
client,
51+
name,
52+
COUNT(DISTINCT page) AS pages,
53+
SUM(COUNT(DISTINCT page)) OVER (PARTITION BY client) AS total,
54+
COUNT(DISTINCT page) / SUM(COUNT(DISTINCT page)) OVER (PARTITION BY client) AS pct_hints
55+
FROM
56+
resource_hints
57+
LEFT JOIN
58+
font_requests
59+
USING (client, page)
60+
GROUP BY
61+
client, name, type
62+
ORDER BY
63+
pct_hints DESC;
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
CREATE TEMPORARY FUNCTION getResourceHints(nodes JSON)
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+
return nodes.reduce((results, link) => {
7+
var hint = link.rel.toLowerCase();
8+
if (!hints.has(hint)) {
9+
return results;
10+
}
11+
results.push({
12+
name: hint,
13+
href: link.href
14+
});
15+
return results;
16+
}, []);
17+
} catch (e) {
18+
return [];
19+
}
20+
''';
21+
22+
WITH resource_hints AS (
23+
SELECT DISTINCT
24+
client,
25+
date,
26+
page,
27+
hint.name AS name
28+
FROM
29+
`httparchive.crawl.pages`
30+
LEFT JOIN
31+
UNNEST(getResourceHints(custom_metrics.other.almanac['link-nodes'].nodes)) AS hint
32+
WHERE
33+
(date = '2025-07-01' OR date = '2024-07-01' OR date = '2023-07-01') AND
34+
is_root_page
35+
),
36+
37+
font_requests AS (
38+
SELECT
39+
client,
40+
date,
41+
page,
42+
type
43+
FROM
44+
`httparchive.crawl.requests`
45+
WHERE
46+
(date = '2025-07-01' OR date = '2024-07-01' OR date = '2023-07-01') AND
47+
type = 'font' AND
48+
is_root_page
49+
),
50+
51+
totals AS (
52+
SELECT
53+
client,
54+
date,
55+
COUNT(0) AS total_pages
56+
FROM
57+
`httparchive.crawl.pages`
58+
WHERE
59+
(date = '2025-07-01' OR date = '2024-07-01' OR date = '2023-07-01') AND
60+
is_root_page
61+
GROUP BY
62+
client,
63+
date
64+
)
65+
66+
SELECT
67+
client,
68+
date,
69+
name,
70+
type,
71+
COUNT(DISTINCT page) AS pages,
72+
ANY_VALUE(total_pages) AS total,
73+
COUNT(DISTINCT page) / ANY_VALUE(total_pages) AS pct
74+
FROM
75+
resource_hints
76+
LEFT JOIN
77+
font_requests
78+
USING (client, date, page)
79+
JOIN
80+
totals
81+
USING (client, date)
82+
GROUP BY
83+
client,
84+
date,
85+
name,
86+
type
87+
HAVING
88+
type IS NOT NULL
89+
ORDER BY
90+
client,
91+
date,
92+
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_VALUE(summary.reqFont) AS INT64) > 0) AS freq_fonts,
3+
COUNT(0) AS total,
4+
COUNTIF(SAFE_CAST(JSON_VALUE(summary.reqFont) AS INT64) > 0) / COUNT(0) AS pct_fonts
5+
FROM
6+
`httparchive.crawl.pages`
7+
WHERE
8+
date = '2025-07-01' AND
9+
client = 'mobile' AND
10+
is_root_page AND
11+
SAFE_CAST(JSON_VALUE(summary.reqFont) AS INT64) IS NOT NULL AND
12+
SAFE_CAST(JSON_VALUE(summary.bytesFont) AS INT64) IS NOT NULL
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#standardSQL
2+
CREATE TEMPORARY FUNCTION getGeneratedContent(generatedContent JSON)
3+
RETURNS STRUCT<percent FLOAT64, sizeInKB FLOAT64> LANGUAGE js AS '''
4+
try {
5+
const percent = parseFloat(generatedContent.percent);
6+
const sizeInKB = parseFloat(generatedContent.sizeInKB);
7+
8+
return {
9+
percent: percent > 0 ? percent : 0,
10+
sizeInKB: sizeInKB > 0 ? sizeInKB : 0
11+
};
12+
} catch (e) {
13+
return null;
14+
}
15+
''';
16+
17+
WITH crux AS (
18+
SELECT
19+
CONCAT(origin, '/') AS page,
20+
CASE
21+
WHEN device = 'phone' THEN 'mobile'
22+
ELSE device
23+
END AS client
24+
FROM
25+
`chrome-ux-report.materialized.device_summary`
26+
WHERE
27+
device IN ('desktop', 'phone') AND
28+
date IN ('2025-07-01')
29+
),
30+
31+
pages AS (
32+
SELECT
33+
client,
34+
page,
35+
getGeneratedContent(custom_metrics.other['generated-content']) AS generated_content
36+
FROM
37+
`httparchive.crawl.pages`
38+
WHERE
39+
date = '2025-07-01' AND
40+
is_root_page
41+
)
42+
43+
SELECT
44+
client,
45+
percentile,
46+
APPROX_QUANTILES(generated_content_percent, 1000)[OFFSET(percentile * 10)] AS generated_content_percent,
47+
APPROX_QUANTILES(generated_content_sizeInKB, 1000)[OFFSET(percentile * 10)] AS generated_content_sizeInKB,
48+
COUNT(0) AS total
49+
FROM (
50+
SELECT
51+
client,
52+
page,
53+
generated_content.percent AS generated_content_percent,
54+
generated_content.sizeInKB AS generated_content_sizeInKB
55+
FROM
56+
pages
57+
JOIN
58+
crux
59+
USING (client, page)
60+
),
61+
UNNEST([10, 25, 50, 75, 90, 100]) AS percentile
62+
WHERE
63+
generated_content_percent IS NOT NULL AND
64+
generated_content_sizeInKB IS NOT NULL
65+
GROUP BY
66+
client,
67+
percentile
68+
ORDER BY
69+
client,
70+
percentile

0 commit comments

Comments
 (0)