Debounce vs Throttle: Peas in a Perfomance Pod

If you’ve ever tried to improve performance in a frontend app — especially when dealing with scrolls, inputs, or window resize events, you’ve likely heard of debounce and throttle.

But what exactly do they do? And when should you use one over the other?

Let’s break it down.

Core Differences

FeatureDebounceThrottle
BehaviorWaits until a period of inactivityEnsures function runs at most every X ms
FiresOnce, after the final triggerMany times, every X ms at most
CancelsPrevious scheduled calls on new triggersSkips extra calls during the throttle window
Use Case”Run only after typing stops""Run repeatedly, but not more than once per X”

Visual Comparison

Debounce (wait = 1000ms)


        debounced();
        debounced();
        debounced();  // ← wait 1000ms → runs once
  • It resets the timer every time you call it.
  • The function only fires once after the user has stopped triggering it.

Throttle (wait = 1000ms)


        throttled(); // ✅ runs
        throttled(); // ⛔ ignored
        throttled(); // ⛔ ignored
        // ← 1000ms passes →
        throttled(); // ✅ runs again
  • It ensures the function runs at most once per interval.

Real-World Examples

SituationUseWhy?
Search input or autocompletedebounceWait until user stops typing before API call
Scroll event (parallax, lazy load)throttlePrevent performance issues on rapid events
Window resizethrottleAvoid layout recalculations on every pixel
Drag-based animationthrottleAllow smooth, timed updates

Metaphor To help for quick recall

  • Debounce: “Wait until they stop talking before replying.”
  • Throttle: “Reply every 1 second, no matter how many times they talk.”


Summary

  • Use debounce when you want to delay execution until the noise stops.
  • Use throttle when you want to limit how often something runs.

To practice both, you can check out GreatFrontend’s excercise on implementing your own debounce and throttle.

✌🏼☕️