Repository navigation
util: fix debounce/throttle abort listener leak - #66839
vedchaudhari wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #66839 +/- ##
========================================
Coverage 90.49% 90.49%
========================================
Files 797 797
Lines 277780 278249 +469
Branches 53360 53465 +105
========================================
+ Hits 251388 251813 +425
- Misses 16791 16806 +15
- Partials 9601 9630 +29
🚀 New features to boost your workflow:
|
|
The |
debounce() and throttle() added an abort listener to the signal when they were created and never removed it, so a long-lived signal kept every debounced or throttled function, and its data, in memory. Only listen for abort while calls are pending. Calls made after the signal is aborted still reject, since each call checks signal.aborted. Assisted-by: a closed-source coding agent Signed-off-by: vedchaudhari <vedc2853@gmail.com>
7b08eab to
9d4466e
Compare
Thanks, good point. Switched to |
|
@cjihrig would you have a moment to take a look? It removes the abort listener that |
util.debounce()andutil.throttle()add an abort listener tooptions.signalwhen they're created and never remove it, so a long-lived signal keeps every function created with it in memory:This only keeps the listener while calls are pending, and removes it with the
Symbol.disposemethod thataddAbortListener()returns. Calls after an abort still reject, since every call already checkssignal.aborted.All functions share one long-lived
AbortSignal:mainNormal calls take the same time as before. Creating a debounced function with a
signalis about 20% faster, andabort()with 5,000 idle functions takes 0.2 ms instead of 9.4 ms. The only extra cost is under 1 µs when a call starts waiting, to add and remove the listener.Performance numbers
Median of 9 runs, old and new code on the same build, Windows x64:
mainsignalabort()with 5,000 idle functionsflush()every time, with asignalsignalAdded tests; they fail on
mainand pass with this change.Refs: #65899
Assisted-by: Claude Code. I reproduced the leak on
main, reviewed every change, and ran the debounce/throttle tests and lint myself.