Similarweb search and filter surfaces should avoid processing every keystroke. Implement a debounce simulation that executes only the most recent event after no newer event has arrived for wait time units.
Each event is represented as [timestamp, value], where timestamps are strictly increasing. When an event arrives, it cancels the previously scheduled execution and schedules the new value for timestamp + wait. If the next event arrives at or after the scheduled time, execute the pending event first. After all input events are processed, execute any remaining pending event.
Implement debounce_events(events, wait).
events, a list of [int, str] pairs sorted by strictly increasing timestamp, and wait, a positive integer.[execution_timestamp, value] pairs in execution order.def debounce_events(events, wait):