Long Tasks and Interaction to Next Paint (INP)
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.
INP Latency Budget: Input Delay + Processing + Presentation
Adjust background task duration, handler work, and DOM nodes to see when INP crosses the 200ms threshold.
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.
- Input Delay: Because the Event Loop runs tasks to completion, a 180 ms hydration task stalls a user's tap before the
clickhandler even starts. - Processing Duration: Synchronous state updates and DOM mutations inside
click,keydown, orpointerup. - Presentation Delay: Recalculating style, layout, paint, and compositor layers to show visual feedback.
- Long Animation Frames (LoAF): Newer Chromium telemetry attributes scripts and style/layout time across the entire slow frame.
// 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
- Optimizing Only the Click Handler: Shaving 10 ms off
onClickfails when a background analytics Long Task causes 220 ms of Input Delay. - Synchronous
alert()orlocalStorageScans: Blocking main-thread APIs insidepointerdownfreeze presentation until dismissed.
- When not to use
requestAnimationFramefor non-visual work: Never defer heavy analytics or state cleanup intorAF, it runs inside the critical frame window and inflates Presentation Delay; use scheduler.yield() instead.
Connections & Logical Next Steps
Chunking reconciliation into 5 ms slices prevents >50 ms long tasks that degrade INP.
Synchronous schema validation over huge arrays can exceed 50 ms on the main thread and degrade INP.
Input events cannot run until the currently executing main-thread macrotask finishes.
Chunking >50ms Long Tasks via scheduler.yield() cuts Input Delay for subsequent interactions.
Presentation Delay reflects the Style, Layout, Paint, and Composite cost after the handler returns.
Catastrophic O(2^n) RegExp backtracking locks the main thread as an uninterruptible Long Task.