Core Web Vitals: INP — Performance

INP is the time from an interaction until the next frame is drawn: input delay + processing time + presentation delay. Good is at most 200 ms…

Your event handler only needs 250 ms. But the person who clicked waits 530 ms for the screen to change. Where did the rest go?

INP (Interaction to Next Paint) is the Core Web Vitals metric for responsiveness: the time from a user's click, tap or key press until the screen shows the result in the next frame. You already know its limits from the Core Web Vitals lesson. Here we take it apart. Picture ordering coffee at a busy café: you wait for the cashier to finish with the person before you, the barista makes your coffee, then it's brought to your table. The time you feel is all three added up, not just how long the barista worked.

The three parts of an interaction

All of a page's JavaScript, and also style, layout and paint, is done on one and the same lane: the main thread. It can only do one thing at a time. One interaction goes through three parts:

Part Cause in the example Time
Input delay the analytics script that is running 180 ms
Processing time the "Add to cart" handler 250 ms
Presentation delay 1,500 rows drawn again 100 ms
This interaction's INP 530 ms

The total is 530 ms, and that is poor. The limits: good is at most 200 ms, needs-improvement up to 500 ms, poor above 500 ms. A value of exactly 200 is still good. A page's INP is taken from the slowest interaction during the visit (with a very large number of interactions, a few of the most extreme are ignored), then Google grades it at the 75th percentile of real visits.

INP replaced FID (First Input Delay) in March 2024. FID only measured the input delay, and only for the first interaction. In the example above the FID is 180 ms and looks good, while the user waits 530 ms.

Long tasks: why the main thread gets stuck

A long task is a task that runs on the main thread for more than 50 ms. While a long task runs, the browser can't run the click handler and can't draw. The 180 ms analytics script and the 250 ms handler above are both long tasks.

function classifyInp(milliseconds) {
  if (milliseconds <= 200) return "good";
  if (milliseconds <= 500) return "needs-improvement";
  return "poor";
}

function identifyBlockingTasks(tasks) {
  return tasks.filter((task) => task.duration > 50); // long task: more than 50 ms
}

console.log(classifyInp(530)); // "poor"

const tasks = [
  { name: "parseHTML", duration: 30 },
  { name: "evalScript", duration: 120 },
  { name: "styleRecalc", duration: 20 },
  { name: "fetchData", duration: 80 },
];
console.log(identifyBlockingTasks(tasks));
// [{ name: "evalScript", duration: 120 }, { name: "fetchData", duration: 80 }]

Yield: give the main thread a chance

The main way to shrink INP is to yield: split long work into short pieces, and between the pieces, hand the main thread back to the browser so it gets a chance to draw and take clicks.

function yieldToMain() {
  if (globalThis.scheduler?.yield) return scheduler.yield();
  return new Promise((resolve) => setTimeout(resolve, 0)); // fallback
}

button.addEventListener("click", async () => {
  updateCartBadge();       // what the user sees is done first
  for (const chunk of chunks) {
    await yieldToMain();   // the browser may draw and take clicks first
    processChunk(chunk);   // each piece under 50 ms
  }
});

In the example above, if the analytics script is also split into 50 ms pieces and the handler yields after 12 ms, the INP becomes 50 + 12 + 100 = 162 ms: good.

The big part How to shrink it
Input delay split other long tasks with yields, defer third-party scripts
Processing time do what the user sees first then yield, debounce heavy handlers, move heavy computing to a Web Worker
Presentation delay change as little DOM as possible: batch, virtual scrolling, avoid layout thrashing

⚠️ An INP that stays bad, and limits that miss

TL;DR: INP is the time from an interaction until the next frame is drawn: input delay + processing time + presentation delay. Good is at most 200 ms, needs-improvement up to 500 ms, poor above 500 ms, and a page's INP comes from its slowest interaction. INP replaced FID in March 2024, which only measured the input delay of the first interaction. A long task is a task of more than 50 ms on the main thread. Shrink INP by yielding: do what the user sees first, then await scheduler.yield() (with a setTimeout fallback) between short pieces.

⚡ The three parts of an interaction

Guess first: your handler only takes 250 ms. Why does the person who clicked wait 530 ms?

INP counts from the click until the next frame is drawn: an input delay of 180 ms (the analytics script that is running), a processing time of 250 ms (your handler), and a presentation delay of 100 ms (drawing again).

Meaning: Good is at most 200 ms, needs-improvement up to 500 ms, poor above 500 ms. A page's INP comes from its slowest interaction.

⚡ Long tasks jam the main thread

Write:

function identifyBlockingTasks(tasks) {
  return tasks.filter((task) => task.duration > 50);
}

Meaning: A long task is a task of more than 50 ms on the main thread. While it runs, the browser can't run the click handler and can't draw. A 50 ms task isn't a long task yet.

⚡ Yield at every piece

Write:

updateCartBadge();
for (const chunk of chunks) {
  await yieldToMain();
  processChunk(chunk);
}

Meaning: Do what the user sees first, then hand the main thread back to the browser between short pieces. Yielding only once isn't enough: the rest of the work is still one long task.

What you will learn