[Other] Frontend Build and Performance Metrics
tl;dr
RomM has rapidly expanded. This issue captures Frontend build metrics like Lighthouse scores, Github Actions log stats, and general phsyica build sizes. Some metrics that should stay low are trending up, some metrics are improving, and some metrics are dead level.
Read on to explore which is which.
Task
Add Lighthouse reporting in the frontend, and record its results in our Github Actions CI. That way, the results are part of Github, and we don't need any additional third party tools to store our data. It's text in the logs.
Then, we write a simple script that parses the logs of a given long running linear branch, pull the logs for their git history at some level of detail we prefer, and chart it. I've had a reasonable degree of success just pulling basic metrics directly from GH logs, and I would be happy to share the scripts.
The result is that with a very very simple addition of Lighthouse running against a fresh localhost:3000 login page, we start getting a lot of value without a lot of additional infrastructure.
Given the evidence, RomM's CI could due with some regular metrics at each build time, or at release during tagging. This allows maintainers and contributors to make smart choices when it comes to how to balance amazing new features and their intake velocity against the lived reality of run-time performance.
Subsequently, improve the performance of the login from 60/100 to 90/100.
Also, reduce Total Blockingg Time from [600-1000]ms down to 400ms.
For reference, the amount of JavaScript we require each page to have is about 500kb... but a flat JPG screenshot of the website at desktop resolution is 60kb.
The rest of this issue simply logs my findings.
Thanks for reading!
The Process
I vibed up some local scripts that do the following:
// pseudo code
// take all the shas on a linear branch like master,
// starting from like, a few month ago and store
// them into an array of SHAs.
for (const sha of shasOnMaster) {
// from a sha on master, make a nice build using `npm run build`
const buildDirectory = await doTheEntireBuild(sha);
// then host the thing using `npm run preview`
await hostTheBuildOnLocalhost(buildDirectory);
// great, now run a lighthouse against it
const lighthouseReportDirectory = await doTheLighthouseAgainstLoginPage("localhost:3000")
// do teardown, stop the server, etc etc
await killThePreview();
// now move them into a static directory, extract their stats into a tsv
await moveTheFolders([buildDirectory, lighthouseReportDirectory]);
// put the row into the tsv
await updateTheTsv();
}Results
I was able to get some nice metrics.
Build Sizes on disk (excerpt)
Interactive Chart of last 60 days or so
https://datawrapper.dwcdn.net/arrDV/5/
What the metrics mean
This section was generated with AI assistance (Claude) and reviewed by a human.
Lighthouse (login page)
performance: Higher is better. Lighthouse's overall 0 to 100 performance score, a weighted blend of the timing metrics below. 90+ is "good", 50 to 89 "needs improvement". Docsfcp_ms(First Contentful Paint): Lower is better. How long until the browser draws the first text or image. It tells a visitor the page is actually loading. Docslcp_ms(Largest Contentful Paint): Lower is better. How long until the largest visible element (usually the main image or text block) is drawn. It is the best single measure of when the page looks loaded. Docstbt_ms(Total Blocking Time): Lower is better. Total time the main thread was too busy running JavaScript to respond to clicks or typing. Large bundles and heavy startup code push it up. Docssi_ms(Speed Index): Lower is better. How quickly the visible page fills in during load. It rewards pages that show content early, not all at the end. Docscls(Cumulative Layout Shift): Lower is better. How much content jumps around while the page loads. Under 0.1 is considered good. Docstti_ms(Time to Interactive): Lower is better. How long until the page is fully ready to respond to input. Lighthouse no longer uses it in the score, but it is a useful gauge of total startup work. Docstotal_bytes: Lower is better. Everything the browser downloaded for the page, compressed as sent over the network. Big downloads are slow on mobile and cost users data. Docsscript_bytes: Lower is better. The JavaScript part oftotal_bytes. It is usually the most expensive part, because the browser has to download, parse and run it.
Build (measured from the built dist/ folder, gzip bytes)
initial_js_gz/initial_css_gz: Lower is better. JavaScript and CSS thatindex.htmlloads for every visitor before the app starts. This is the cost every page pays.lazy_js_gz: Lower is usually better, but growth here is often fine. JavaScript split into chunks that only load when a page or feature needs them. New features tend to land here.total_js_gz/total_css_gz: Lower is better. All JavaScript or CSS in the build, first-load plus lazy. It tracks the overall size of the app over time.total_raw: Lower is better. Size of every file in the build, uncompressed, including images and fonts. It is the disk footprint of the frontend.js_chunk_count: Neither direction is clearly better. How many JavaScript files the build produced. More chunks usually means finer code splitting.largest_js_gz: Lower is better. The biggest single JavaScript file, normally the main entry chunk. It sets a floor on how fast the first paint can be.build_seconds: Lower is better. How longnpm run buildtook on the machine that ran it. Only compare runs from the same machine.
GitHub CI (sizes Vite printed in the "Frontend Checks" build log, kB)
gh_largest_js_gz_kb,gh_total_js_gz_kb,gh_total_css_gz_kb: Lower is better. The same sizes as above, as measured by CI's own build of that commit. They confirm the local build matches what CI built.gh_js_files: Neither direction is clearly better. How many JavaScript files CI's build produced. It should matchjs_chunk_count.gh_status:ok,expired(GitHub deleted the log after ~90 days),no-run(the commit did not changefrontend/, so CI did not build it), orskipped(ghwas not available).
Source: rommapp/romm