JS RuntimeBaseline · Widely

Long Tasks and Interaction to Next Paint (INP)

Mental Model

A Long Task is any main-thread task exceeding 50 ms. Interaction to Next Paint (INP) sums three slices (Input Delay (waiting for active Long Tasks), Processing Duration (event handlers), and Presentation Delay (Rendering Pipeline)) and requires keeping the 75th percentile under 200 ms.

Interactive Simulator

INP Latency Budget: Input Delay + Processing + Presentation

Adjust background task duration, handler work, and DOM nodes to see when INP crosses the 200ms threshold.

Parameter Profile
backgroundTaskMs120
handlerMs45
yieldEnabledOff
backgroundTaskMs
120
handlerMs
45
yieldEnabled
Off
Parameters evaluated in real time.

Under the Hood

Chromium measures Interaction to Next Paint (INP) from the hardware input timestamp to the next compositor frame swap, summing Input Delay, Processing Duration, and Presentation Delay. Because the main thread runs tasks to completion, an active Long Task stalls the input handler before Layout and Paint can even begin.

  1. Input Delay: Because the Event Loop runs tasks to completion, a 180 ms hydration task stalls a user's tap before the click handler even starts.
  2. Processing Duration: Synchronous state updates and DOM mutations inside click, keydown, or pointerup.
  3. Presentation Delay: Recalculating style, layout, paint, and compositor layers to show visual feedback.
  4. Long Animation Frames (LoAF): Newer Chromium telemetry attributes scripts and style/layout time across the entire slow frame.
JS
// Measure Long Animation Frames in the field
new PerformanceObserver((list) => {
  for (const entry of list.getEntries()) {
    if (entry.duration > 50) {
      reportSlowFrame(entry.duration, entry.scripts);
    }
  }
}).observe({ type: 'long-animation-frame', buffered: true });

Problem Genealogy

  • 2017 (PerformanceLongTaskTiming): Defined the 50 ms threshold, the longest task leaving headroom for a 100 ms human perception budget.
  • 2020 (First Input Delay - FID): Measured only the first interaction's Input Delay, ignoring slow handlers and later clicks.
  • 2024 (INP Core Web Vital): Replaced FID, capturing full Input + Processing + Presentation latency across the entire page session.

Production Pitfalls

Production Pitfall
  • Optimizing Only the Click Handler: Shaving 10 ms off onClick fails when a background analytics Long Task causes 220 ms of Input Delay.
  • Synchronous alert() or localStorage Scans: Blocking main-thread APIs inside pointerdown freeze presentation until dismissed.
When Not to Use
  • When not to use requestAnimationFrame for non-visual work: Never defer heavy analytics or state cleanup into rAF, it runs inside the critical frame window and inflates Presentation Delay; use scheduler.yield() instead.

Connections & Logical Next Steps

Seen in Architecture Autopsies