Core Web Vitals overview in SEO Fundamentals - Time & Space Complexity
Core Web Vitals measure how fast and smoothly a webpage loads and responds.
We want to understand how the page's performance changes as content grows.
Analyze the time complexity of measuring Core Web Vitals metrics.
// Example: Measuring Largest Contentful Paint (LCP)
window.addEventListener('load', () => {
const observer = new PerformanceObserver((list) => {
const entries = list.getEntries();
entries.forEach(entry => {
console.log('LCP candidate:', entry.startTime);
});
});
observer.observe({ type: 'largest-contentful-paint', buffered: true });
});
This code listens for the largest visible content loading and logs its timing.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Looping over performance entries as they arrive.
- How many times: Once per each LCP candidate detected during page load.
More page elements can create more LCP candidates to check.
| Input Size (elements) | Approx. Operations (entries checked) |
|---|---|
| 10 | Up to 10 entries |
| 100 | Up to 100 entries |
| 1000 | Up to 1000 entries |
Pattern observation: The number of checks grows roughly in proportion to page size.
Time Complexity: O(n)
This means the work to measure Core Web Vitals grows linearly with the number of page elements.
[X] Wrong: "Measuring Core Web Vitals takes the same time no matter how big the page is."
[OK] Correct: More page elements can create more events to process, so measurement time grows with page size.
Understanding how performance metrics scale helps you build faster, user-friendly websites.
"What if we only measured Core Web Vitals after the page fully loads? How would that affect time complexity?"