timer drift
The growing gap between when a timer was asked to fire and when it actually fires, caused by a busy thread or scheduling delays.
In more detail
Timers never fire early but can fire late, and with repeated timers the lateness adds up. Measuring the actual time with performance.now() and shortening the next delay compensates for it.
Related terms
- setTimeout — A JavaScript function that runs a callback once after at least the given number of milliseconds, unless clearTimeout cancels it first.
- setInterval() — A JavaScript function that runs a callback repeatedly, roughly every given number of milliseconds, until clearInterval stops it.
- performance.now() — A function that returns a high-resolution timestamp in milliseconds, with fractions, for measuring how long something takes.
Taught in
- Timers Phase: setTimeout, Min-Heap Scheduling & Drift — Node.js Internals & Backend Services