0
0
SEO Fundamentalsknowledge~5 mins

Core Web Vitals overview in SEO Fundamentals - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Core Web Vitals overview
O(n)
Understanding Time 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.

Scenario Under Consideration

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 Repeating Operations

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.
How Execution Grows With Input

More page elements can create more LCP candidates to check.

Input Size (elements)Approx. Operations (entries checked)
10Up to 10 entries
100Up to 100 entries
1000Up to 1000 entries

Pattern observation: The number of checks grows roughly in proportion to page size.

Final Time Complexity

Time Complexity: O(n)

This means the work to measure Core Web Vitals grows linearly with the number of page elements.

Common Mistake

[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.

Interview Connect

Understanding how performance metrics scale helps you build faster, user-friendly websites.

Self-Check

"What if we only measured Core Web Vitals after the page fully loads? How would that affect time complexity?"