Interaction to Next Paint, or INP, is one of the stable Core Web Vitals (CWV) metrics, and is one of the most interesting ways to measure how users experience your application, since it is measured against user interactions throughout the session.
On the other hand, metrics like LCP, FCP and TTFB, although important, will offer just a glance into the actual application performance, since they target the page load. According to Chrome usage data, 90% of the time users spend on a page comes after it loads.
That’s why I believe ongoing monitoring of INP is key to the long-term success of a web application.
Definition of INP
On web.dev, INP is described as:
[…] a metric that assesses a page’s overall responsiveness to user interactions by observing the latency of all click, tap, and keyboard interactions that occur throughout the lifespan of a user’s visit to a page. The final INP value is the longest interaction observed, ignoring outliers.
In other words, the responsiveness of the page is defined by how fast your UI can paint the next frame after a discrete interaction. Hovering, scrolling and zooming are not taken into account.
The latency of each interaction is made of three parts:
- The input delay: the time before the event handlers start running
- The processing duration: the time it takes for them to run, and
- The presentation delay: the time from there until the next frame is painted.
The idea, as denoted in the article, is not to measure the full lifecycle of an interaction (more on this below), so network requests and other asynchronous work are not necessarily part of it. Instead, it exposes the visual gaps during which your app design may leave users confused on whether their actions worked, whether the page is frozen, whether their devices didn’t capture their input, and so on. It is essentially a UX metric.
How to capture INP measures
In a nutshell, the mechanics for measuring INP are pretty simple. Discrete interactions, like clicking, tapping, or typing, will produce a series of PerformanceEventTiming entries, which can be captured with a simple script like the following:
const interactions = new Map()
const observer = new PerformanceObserver(list => {
for (const entry of list.getEntries()) {
// Discrete user interactions will populate this ID
if (!entry.interactionId) continue
const prev = interactions.get(entry.interactionId)
if (!prev || entry.duration > prev.duration) {
interactions.set(entry.interactionId, entry)
}
}
})
observer.observe({
type: 'event',
buffered: true,
durationThreshold: 16, // The minimum allowed, the default is 104ms
})
// Also observe 'first-input' because the first interaction is reported
// even if its duration is below the set threshold.
observer.observe({
type: 'first-input',
buffered: true,
})
Above we listen for event and first-input entries. Then, we maintain a Map of interactions, keyed by interactionId.
This deduplication by ID is important, because each interaction can trigger multiple events, and only the longest one represents the latency of that interaction.
After some interactions, the map would look like this (entries are simplified, and duration is rounded to the nearest 8ms):
Map([
[
1788,
{
name: "pointerdown",
entryType: "first-input",
startTime: 209204.59999999963,
duration: 32,
interactionId: 1788,
processingStart: 209208.09999999963,
processingEnd: 209209.59999999963,
cancelable: true,
},
],
[
2411,
{
name: "click",
entryType: "event",
startTime: 662101.5999999996,
duration: 240,
interactionId: 2411,
processingStart: 662344.1999999993,
processingEnd: 662344.7999999989,
cancelable: true,
},
],
[
2425,
{
name: "keydown",
entryType: "event",
startTime: 665148.5999999996,
duration: 32,
interactionId: 2425,
processingStart: 665157.7999999989,
processingEnd: 665158.7999999989,
cancelable: true,
},
],
]);
To get from these interactions to the INP value, we take the longest one, but ignore one of the highest for every 50 interactions on the page. With fewer than 50 interactions, INP is simply the worst one.
The script above is just a sample, so for production it’s probably better to rely on the web-vitals library or a monitoring tool.
Each entry also contains valuable information about where the time was spent, which can already give us some insights. For instance, in the click above, most of the 240ms were spent before processingStart, that is, on input delay. However, we have tools that will automatically collect INP data and make it useful to us, like Sentry through its browserTracingIntegration, which is even more useful here due to custom spans.
Leveraging Sentry instrumentation for INP and more
As mentioned when defining INP, the metric is essentially focused on the user experience, or how the application “looks” after an interaction. This also means that slow database queries, long middleware queues, or server latency will usually not show up in your INP score, as long as the browser is free to paint while it waits for the response. A bad score points to something delaying that paint on the client side, like long tasks blocking the main thread, expensive event handlers, or heavy rendering work.
We can also use some UI techniques, like loading indicators, to give users immediate feedback during long network tasks. But a good INP doesn’t mean the whole interaction is fast, and the user may still be waiting on a broader, multi-layer performance bottleneck.
When facing this scenario, it is useful to have a full-stack observability mechanism in place, like Sentry tracing with custom spans. Custom spans allow us to measure the operations that matter to us, from the moment our event handler runs until the results are rendered again on the client side. With tracing also set up on the backend, those can be connected to server and database spans in the same trace, so we can see where the time is going between the client dispatch and the server response, complementing INP as a means to understand the interactions performance.
Conclusion
INP tells us how quickly the UI responds to users, and tracing can show us what happens through the rest of the interaction. Having both is really valuable, and is a powerful way to prevent regressions on key funnel interactions, ensuring that the most important ones stay as fast as possible, which can lead to better conversion rates and user retention.
