Dev.to WebDev 🛠 Dev 👁 0 📖 9 min read

Debug INP Like a Performance Engineer: Find the Real Cause of Slow Interactions

Debug INP Like a Performance Engineer: Find the Real Cause of Slow Interactions The page loads quickly. Images appear almost instantly. Lighthouse gives you a reasonable score. But when someone clicks a button, opens a

Debug INP Like a Performance Engineer: Find the Real Cause of Slow Interactions

Debug INP Like a Performance Engineer: Find the Real Cause of Slow Interactions

The page loads quickly. Images appear almost instantly. Lighthouse gives you a reasonable score.

But when someone clicks a button, opens a menu, or submits a form, the interface feels slow.

This is a different performance problem from slow page loading, and it is exactly what Interaction to Next Paint (INP) is designed to measure.

The mistake many developers make is treating every poor INP result as a JavaScript problem. Sometimes the event handler is slow. Sometimes the browser cannot start the handler because another task is blocking the main thread. In other cases, JavaScript finishes quickly, but the browser takes too long to render the visual response.

Those are three different problems. They require different fixes.

This guide explains how to identify the actual bottleneck using Chrome DevTools, real-user data, and Google's web-vitals library.

1. Understand What INP Actually Measures

INP is a Core Web Vital that evaluates how responsive a page feels throughout a user's visit.

It considers qualifying interactions such as:

  • Clicking buttons and links.
  • Opening menus and dropdowns.
  • Typing into interactive controls.
  • Selecting options.
  • Submitting forms.

Rather than measuring only the first interaction, INP considers interactions across the page's lifetime and reports the slowest qualifying interaction, with some outlier handling.

Google's recommended thresholds are:

INP value Assessment
200 ms or less Good
Above 200 ms and up to 500 ms Needs improvement
Above 500 ms Poor

These thresholds should be evaluated at the 75th percentile of real page visits, separately for mobile and desktop.

A page can therefore have a good loading experience and still provide a poor interactive experience.

Source: Google's INP optimization guide.

2. The Three Parts of a Slow Interaction

The most useful way to diagnose INP is to divide the interaction into three phases.

Phase What happens Typical cause
Input delay The browser waits before starting event handlers Main thread is busy
Processing duration Event handlers execute Expensive JavaScript
Presentation delay The browser prepares and displays the next frame Rendering, style, layout, or paint work

The total interaction latency is made up of these three parts.

Input delay: The browser cannot start yet

Imagine a user clicks a button while the browser is executing a large JavaScript task.

The click has happened, but the browser cannot immediately process the event. It must wait for the current work to finish.

Common causes include:

  • Large JavaScript bundles.
  • Expensive initialization code.
  • Third-party analytics and advertising scripts.
  • Long-running timers.
  • Multiple tasks competing for the main thread.

In this situation, optimizing the button's event handler may achieve almost nothing. The browser is already delayed before that handler begins.

Processing duration: Your JavaScript is doing too much

Now imagine the browser starts the click handler immediately, but the handler performs several expensive operations:

  • Filtering thousands of records.
  • Parsing a large JSON response.
  • Recalculating application state.
  • Updating too many components.
  • Performing synchronous calculations.

The handler itself becomes the bottleneck.

The solution is to reduce the work performed directly during the interaction.

Presentation delay: JavaScript finished, but the screen is still waiting

This is the phase developers sometimes overlook.

The event handler may complete quickly, but the browser still needs to calculate styles, update layout, paint, and present the next frame.

Large DOM updates, expensive CSS recalculations, forced layouts, and complex visual changes can all contribute to this delay.

A fast event handler does not guarantee a fast visual response.

Google explains these three phases in its INP optimization documentation.

3. Start With Real-User Data

Before changing code, find out whether users are actually experiencing the problem.

There are two different types of performance data.

Field data comes from real users visiting your website. It reflects real devices, browser conditions, network environments, and interaction patterns.

Lab data comes from controlled tests. It helps developers reproduce problems and investigate possible causes.

Use both, but do not confuse them.

Start with:

  1. Open PageSpeed Insights.
  2. Enter the affected page URL.
  3. Check the Core Web Vitals field data when available.
  4. Compare mobile and desktop results.
  5. Identify whether the problem affects a specific URL or the wider site.

Chrome's User Experience Report (CrUX) provides aggregated real-world performance data, but it does not always identify the exact button, script, or component responsible for a slow interaction.

If you need that level of detail, consider adding Real User Monitoring (RUM) to your application.

4. Use Chrome DevTools to Find the Slow Interaction

Chrome DevTools provides an Interactions track that helps identify responsiveness problems.

Step 1: Open the Performance panel

Open your website in Chrome.

Then:

  1. Press F12 or open Developer Tools.
  2. Select the Performance tab.
  3. Open the Live Metrics screen if it is available in your DevTools version.
  4. Interact with the page.
  5. Observe the INP value and interaction history.

The Live Metrics screen can also show field data from CrUX when enabled, allowing you to compare local testing with real-user measurements.

Step 2: Record the interaction

If you can reproduce the slow behavior:

  1. Start a runtime performance recording.
  2. Perform the exact action that causes the delay.
  3. Stop the recording.
  4. Find the Interactions track in the timeline.
  5. Select the slow interaction.

Chrome DevTools can show input delay, processing time, and presentation delay for the selected interaction.

It can also identify interactions that exceed the 200 ms good-INP threshold.

Official reference: Chrome DevTools Performance features.

Step 3: Inspect the Main thread

Look at the Main thread around the slow interaction.

Pay attention to:

  • Long JavaScript tasks.
  • Expensive event handlers.
  • Repeated style recalculations.
  • Layout operations.
  • Rendering activity.
  • Third-party script execution.

Do not immediately optimize the largest-looking function. First establish whether it overlaps with the phase responsible for the delay.

A large script that runs after the interaction may be less relevant than a smaller task that blocks the browser immediately before it.

5. Measure INP in Production With web-vitals

Lab testing is useful, but it cannot reproduce every interaction and device condition.

Google maintains an open-source JavaScript library called web-vitals.

Install it:

npm install web-vitals

For diagnostic attribution, import the attribution build:

import { onINP } from "web-vitals/attribution";

onINP(({ id, value, rating, attribution }) => {
  const slowestScript = attribution.longestScript;

  const report = {
    name: "INP",
    id,
    value: Math.round(value),
    rating,

    inputDelay: Math.round(attribution.inputDelay),
    processingDuration: Math.round(
      attribution.processingDuration
    ),
    presentationDelay: Math.round(
      attribution.presentationDelay
    ),

    interactionTarget: attribution.interactionTarget,

    script: slowestScript
      ? {
          url: slowestScript.entry?.sourceURL,
          functionName:
            slowestScript.entry?.sourceFunctionName,
          phase: slowestScript.subpart,
          duration: Math.round(
            slowestScript.intersectingDuration
          )
        }
      : undefined
  };

  const body = new Blob(
    [JSON.stringify(report)],
    { type: "application/json" }
  );

  const queued =
    navigator.sendBeacon?.("/api/rum", body) ?? false;

  if (!queued) {
    fetch("/api/rum", {
      method: "POST",
      body,
      keepalive: true
    }).catch(() => {});
  }
});

This example reports:

  • The INP value and rating.
  • The three latency components.
  • The interaction target.
  • The longest attributed script, when available.

The /api/rum endpoint is an example. You must implement a server-side endpoint that accepts and stores the reports.

A few implementation details matter:

  • Use the attribution build only when you need diagnostic information.
  • Avoid transmitting complete DOM contents or user-entered form values.
  • Sanitize interaction selectors before storing them.
  • Avoid collecting unnecessary personal or sensitive information.
  • Monitor report volume and storage costs.

The library may report INP near the end of a page visit rather than immediately after every click. Do not assume the absence of an immediate console message means the integration is broken.

Documentation: GoogleChrome/web-vitals.

6. Use the INP Phase to Choose the Correct Fix

Once you know which phase is responsible, you can choose a targeted optimization.

Fixing excessive input delay

If the browser is waiting before event handlers start:

  • Reduce unnecessary JavaScript execution during page initialization.
  • Defer non-critical scripts.
  • Review third-party scripts.
  • Break up large main-thread tasks.
  • Move CPU-intensive calculations into Web Workers when they do not need direct DOM access.

For example, a large indexing operation can be split into smaller batches:

const yieldToBrowser = () =>
  new Promise(resolve => setTimeout(resolve, 0));

async function rebuildIndex(records) {
  const batchSize = 200;

  for (
    let start = 0;
    start < records.length;
    start += batchSize
  ) {
    const batch = records.slice(
      start,
      start + batchSize
    );

    processBatch(batch);

    await yieldToBrowser();
  }
}

This gives the browser opportunities to process other tasks between batches.

The batch size is only an example. Measure your workload and adjust it. For heavy computations, a Web Worker may be a better solution than repeatedly yielding on the main thread.

Fixing excessive processing duration

If your event handler is the problem:

  • Keep immediate event handlers short.
  • Avoid unnecessary synchronous calculations.
  • Reduce repeated state updates.
  • Avoid rendering large lists when only a small part changed.
  • Move independent CPU-intensive work into a worker.

The key principle is simple: perform the minimum work needed to respond to the user, and avoid making the interaction wait for unrelated operations.

Fixing excessive presentation delay

If the browser is slow to display the result:

  • Reduce unnecessary DOM changes.
  • Simplify expensive CSS rules.
  • Avoid repeated layout recalculations.
  • Batch DOM reads before DOM writes.
  • Reduce the amount of content being repainted.
  • Consider CSS containment where it is appropriate.

For example, this pattern can cause unnecessary layout work:

for (const item of items) {
  item.style.width = `${container.offsetWidth}px`;
}

A better approach is to read the layout value once, then apply the updates:

const width = container.offsetWidth;

for (const item of items) {
  item.style.width = `${width}px`;
}

The important idea is to avoid repeatedly mixing layout reads and DOM writes.

7. Look Beyond the Long Tasks API

A long task is useful evidence, but it does not always explain the complete cause of a slow interaction.

The Long Tasks API identifies tasks that occupy the main thread for at least 50 milliseconds. However, it offers limited information about the exact script and rendering work involved.

The Long Animation Frames API (LoAF) provides more detailed information about slow rendering frames.

It can help developers investigate:

  • Script execution during a delayed frame.
  • Forced style recalculation.
  • Forced layout operations.
  • Rendering-phase style calculations.
  • Rendering-phase layout duration.

This is especially useful when JavaScript execution appears reasonable but the browser still takes too long to present the next frame.

Chrome shipped the Long Animation Frames API in Chrome 123.

Read the official guide: Long Animation Frames API.

8. Common INP Debugging Mistakes

Avoid these mistakes when investigating a slow page.

Mistake 1: Optimizing page loading instead of interaction responsiveness.

A faster initial load does not automatically mean faster buttons, menus, and forms.

Mistake 2: Assuming every slow interaction is caused by its event handler.

The main thread may already be busy before the handler starts.

Mistake 3: Trusting a single desktop test.

A modern desktop can hide performance problems that appear on slower mobile devices.

Mistake 4: Treating a Lighthouse result as a complete diagnosis.

A controlled test may not reproduce the interaction patterns experienced by real users.

Mistake 5: Ignoring rendering work.

JavaScript can finish quickly while layout and paint remain expensive.

Mistake 6: Fixing the wrong interaction.

INP reflects the slowest qualifying interaction during a visit, not necessarily the first button you happen to test.

9. A Practical INP Debugging Checklist

  • Identify the affected page using field data.
  • Compare mobile and desktop results.
  • Reproduce the interaction in Chrome DevTools.
  • Inspect the Interactions track.
  • Determine whether input delay, processing duration, or presentation delay dominates.
  • Identify the relevant JavaScript or rendering work.
  • Apply a targeted optimization.
  • Repeat the same interaction under comparable conditions.
  • Verify results with real-user measurements after deployment.
  • Review whether the change introduced new problems elsewhere.

Conclusion

Improving INP is not about making every JavaScript function faster. It is about understanding the complete path from a user's action to the next visible frame.

The three-phase model gives developers a practical starting point:

  • High input delay means the browser is waiting to start.
  • High processing duration means your interaction code is doing too much.
  • High presentation delay means the browser is taking too long to display the result.

Use field data to identify the problem, Chrome DevTools to reproduce it, and web-vitals attribution to understand what happened in production.

The most effective performance optimization is not the one that removes the most code. It is the one that removes the actual bottleneck experienced by users.

Discussion Question

When you investigate poor INP, which problem do you encounter most often: input delay, expensive JavaScript handlers, or rendering and layout work?

AI disclosure: This article was prepared with AI assistance for research organization and editing. The technical explanations and code examples should be reviewed and tested by the author before publication.

References

  1. Google web.dev – Optimize INP
  2. Chrome DevTools – Performance Features Reference
  3. GoogleChrome – Web Vitals Library
  4. Chrome – Long Animation Frames API
  5. GoogleChrome – Identify Causes of Poor INP
📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.