Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tech Report: Performance opportunities #49

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 63 additions & 23 deletions definitions/output/core_web_vitals/technologies.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,51 @@ CREATE TEMP FUNCTION IS_NON_ZERO(
) RETURNS BOOL AS (
good + needs_improvement + poor > 0
);

CREATE TEMP FUNCTION extract_audits (lighthouse JSON)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rviscomi please give me feedback here, if we understand performance opportunities the same way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LMK if #38 (comment) helps

RETURNS ARRAY<STRUCT<
id STRING,
savings_ms INT64,
savings_bytes INT64
>>
LANGUAGE js AS """
const results = []
const performance_audits = lighthouse?.categories ? lighthouse.categories.performance.auditRefs
.filter((audit) => audit.group === "diagnostics")
.map((audit) => audit.id) : null
if(performance_audits) {
for (const [key, audit] of Object.entries(lighthouse.audits)) {
if (
performance_audits.includes(audit.id) &&
audit.score !== null &&
audit.scoreDisplayMode === 'metricSavings'
) {
results.push({
id: audit.id,
savings_ms: audit?.details?.overallSavingsMs || audit?.numericUnit === 'millisecond' ? audit.numericValue : null,
savings_bytes: audit?.details?.overallSavingsBytes || audit?.numericUnit === 'byte' ? audit.numericValue : null,
})
}
}
return results;
} else {
return null;
}
""";
`).query(ctx => `
WITH geo_summary AS (
WITH pages AS (
SELECT
client,
page,
root_page AS origin,
technologies,
summary,
lighthouse
FROM ${ctx.ref('crawl', 'pages')}
WHERE
date = '${pastMonth}'
${constants.devRankFilter}
), geo_summary AS (
SELECT
CAST(REGEXP_REPLACE(CAST(yyyymm AS STRING), r'(\\d{4})(\\d{2})', r'\\1-\\2-01') AS DATE) AS date,
* EXCEPT (country_code),
Expand Down Expand Up @@ -92,51 +135,50 @@ crux AS (
WHERE rank <= _rank
),

audits AS (
SELECT
client,
page,
performance_opportunities.id
FROM pages,
UNNEST(extract_audits(lighthouse)) AS performance_opportunities
WHERE
performance_opportunities.savings_ms > 0 OR
performance_opportunities.savings_bytes > 0
),

technologies AS (
SELECT
technology.technology,
client,
page
FROM ${ctx.ref('crawl', 'pages')},
FROM pages,
UNNEST(technologies) AS technology
WHERE
date = '${pastMonth}'
${constants.devRankFilter} AND
technology.technology IS NOT NULL AND
technology.technology != ''
UNION ALL
SELECT
'ALL' AS technology,
client,
page
FROM ${ctx.ref('crawl', 'pages')}
WHERE
date = '${pastMonth}'
${constants.devRankFilter}
FROM pages
),

categories AS (
SELECT
technology.technology,
ARRAY_TO_STRING(ARRAY_AGG(DISTINCT category IGNORE NULLS ORDER BY category), ', ') AS category
FROM ${ctx.ref('crawl', 'pages')},
FROM pages,
UNNEST(technologies) AS technology,
UNNEST(technology.categories) AS category
WHERE
date = '${pastMonth}'
${constants.devRankFilter}
GROUP BY technology
UNION ALL
SELECT
'ALL' AS technology,
ARRAY_TO_STRING(ARRAY_AGG(DISTINCT category IGNORE NULLS ORDER BY category), ', ') AS category
FROM ${ctx.ref('crawl', 'pages')},
FROM pages,
UNNEST(technologies) AS technology,
UNNEST(technology.categories) AS category
WHERE
date = '${pastMonth}' AND
client = 'mobile'
${constants.devRankFilter}
),

summary_stats AS (
Expand All @@ -151,11 +193,9 @@ summary_stats AS (
SAFE.FLOAT64(lighthouse.categories['best-practices'].score) AS best_practices,
SAFE.FLOAT64(lighthouse.categories.performance.score) AS performance,
SAFE.FLOAT64(lighthouse.categories.pwa.score) AS pwa,
SAFE.FLOAT64(lighthouse.categories.seo.score) AS seo
FROM ${ctx.ref('crawl', 'pages')}
WHERE
date = '${pastMonth}'
${constants.devRankFilter}
SAFE.FLOAT64(lighthouse.categories.seo.score) AS seo,
extract_audits(lighthouse) AS performance_opportunities,
FROM pages
),

lab_data AS (
Expand Down
Loading