How webkit/speedometer works
Project Type and Purpose
• Speedometer is an open-source browser benchmark tool (not a full-stack app).
• It delivers static web assets (HTML/CSS/JS) that, when loaded in a browser, run a suite of simulated user interactions against small sample applications (“workloads”) and measure timing.
• It also provides Node.js-based automation scripts for running headless tests and CI integration (GitHub Actions).
High-Level File Structure Analysis
• Top level: build/config (babel.config.json, .eslintrc, package.json, netlify.toml), docs (README.md, Development.md, Testing.md), static pages (index.html, about.html, instructions.html).
• experimental/: proof-of-concept workloads (e.g. todomvc-localstorage).
• resources/: the heart of the benchmark –
– benchmark harness: benchmark-runner.mjs, suite-runner.mjs, shared modules (resources/shared/*.mjs).
– workload definitions/apps: charts/, editors/, newssite/, perf.webkit.org/, react-stockcharts/, todomvc/… plus utility scripts.
– data and helper modules (resources/main.mjs, resources/metric*.mjs, resources/translations.mjs).
• tests/: Node.js scripts to run unit- and end-to-end tests (run-unittests.mjs, run-end2end.mjs, server.mjs).
• package.json scripts and .github/workflows/test.yml define CI/CD pipelines.
README Insights
• Speedometer measures real-world-style end-to-end journeys (each “workload” is a small demo app with UI interactions).
• It measures both sync and async JS time per step.
• Final score is the inverse of the geometric mean of test durations.
Components
a. Main Components
1. Static Asset Host (e.g., Netlify, or any HTTP server)
2. Browser Environment (Chrome, Firefox, etc.)
3. Benchmark Harness (JavaScript modules in resources/, e.g. benchmark-runner.mjs, suite-runner.mjs)
4. Workload Modules (subfolders under resources/, each implementing a test scenario)
5. Measurement Engine (sync/async timing collectors, score calculator)
6. Reporting UI (HTML/CSS/JS pages that present timing charts and final score)
7. Node.js Automation (tests/ scripts + headless browser launch)
8. CI Pipeline (GitHub Actions invoking Node.js automation and reporting pass/fail)
b. Relationships and Interactions
• Browser <– HTTP GET –– Static Asset Host
• Browser → loads index.html → bootstraps Benchmark Harness
• Harness → dynamically loads each Workload Module (via ES modules or script tags)
• Workload Module ↔ Measurement Engine (harness invokes workload steps; measurement collects timestamps)
• Measurement Engine → aggregates metrics → Score Calculator
• Score Calculator → Reporting UI → renders graphs and numeric score
• Node.js Automation → spins up headless browser (Puppeteer or playwright) → loads benchmark → collects result → outputs JSON/CI logs
• CI Pipeline → triggers Node.js Automation → posts results/status
c. Architectural Patterns and Principles
• Plugin-style workload architecture: each test lives in its own folder under resources/ and adheres to a common API.
• Modular ES-module design: shared modules under resources/shared for common logic.
• Separation of concerns:
– Static hosting/build layer (package.json, netlify.toml)
– Runtime harness & workloads (resources/)
– Automation & CI (tests/, .github/)
• Measurement decoupled from UI: timing collectors feed a pure data output, then UI layers render graphs.
d. Key Technologies and Frameworks
• Core: HTML5, CSS, ES Modules, plain JavaScript
• Build tools: Babel, Rollup/Vite (in some workloads), npm scripts
• Automation: Node.js, MJS modules, headless browser tooling
• CI: GitHub Actions (test.yml), Netlify for static deploys