JS Performance Engineering: Debounce, Throttle & Memory
Optimize high-frequency scroll/resize event handlers with debouncing & throttling, avoid memory leaks, and profile Garbage Collection.
Debounce vs Throttle Mechanics
### Event Optimization Patterns
- **Debounce**: Delays function execution until $N$ milliseconds have elapsed since the LAST invocation event (ideal for search input autocomplete).
- **Throttle**: Enforces a maximum execution frequency, firing at most once every $N$ milliseconds (ideal for window resize/scroll tracking).