Discussion about this post

User's avatar
Fayaz Bin Salam's avatar

Nice to see debounce and throttle treated as two different tools rather than interchangeable magic delays, which is how they usually get copy-pasted in. The leading vs trailing edge distinction alone explains about half the "why did my search fire twice" bugs I've seen. It's the same story with every other micro-utility we all rewrite badly at 2am — string templating being my personal offender, which is why I eventually stopped rewriting it and just made https://github.com/p32929/str_template.

Fayaz Bin Salam's avatar

Good roundup — the leading/trailing edge distinction in particular is the one that quietly breaks search boxes everywhere, and it's nice to see it spelled out rather than assumed. What I'd add is that debounce and throttle answer "how often does this run", and the companion question nobody profiles is "how expensive is one run". Half the time the reason a handler needed rate-limiting at all was some innocent-looking string building doing chained replaces and a fresh regex per call. Worth measuring before reaching for a timer — and if templating is the hot part, a small dedicated one helps: https://github.com/p32929/str_template (tiny, TypeScript, client or server). Sometimes the fix is fewer calls; sometimes it's just a cheaper call.

No posts

Ready for more?