Skip to content

⚡ concurrent execution of async disposers in DisposableBag - #29

Merged
esenmx merged 4 commits into
masterfrom
perf/concurrent-disposers-disposable-bag-1763264514431639548
Aug 23, 2026
Merged

esenmx merged 4 commits into
masterfrom
perf/concurrent-disposers-disposable-bag-1763264514431639548

Conversation

@esenmx

@esenmx esenmx commented Aug 22, 2026

Copy link
Copy Markdown
Owner

💡 What:

Optimized DisposableBag.dispose to collect Futures returned by async disposers and await them concurrently using Future.wait(futures), capturing both synchronous and asynchronous errors into DisposableBagException.

🎯 Why:

Previously, DisposableBag.dispose awaited each asynchronous disposer sequentially in a for loop. If multiple disposers contained asynchronous work (e.g. flushing streams, closing network connections, finishing timers), each disposer had to wait for the previous one to complete, resulting in total disposal duration equal to the sum of all disposer execution times ($O(\sum t_i)$). Executing them concurrently reduces total disposal time to the duration of the slowest disposer ($\max(t_i)$).

📊 Measured Improvement:

  • Benchmark setup: Disposing a DisposableBag with 10 asynchronous disposers delaying 10ms each.
  • Baseline duration: ~112 ms (sequential execution).
  • Optimized duration: ~13 ms (concurrent execution).
  • Speedup: ~8.6x faster (~88% latency reduction).

PR created automatically by Jules for task 1763264514431639548 started by @esenmx

@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

google-labs-jules Bot and others added 4 commits August 23, 2026 16:52
Updates DisposableBag.dispose to collect futures returned by disposers and await them concurrently using Future.wait, rather than sequentially awaiting each async disposer. Exception handling is maintained by attaching onError callbacks to record any async errors before throwing DisposableBagException.

Co-authored-by: esenmx <43244505+esenmx@users.noreply.github.com>
…ndexing

Drop the nullable futures juggling, record each disposer's error in a
slot keyed by its registration index so DisposableBagException.errors
stays in registration order, and document the invoke-in-order /
await-together contract in the class and dispose() dartdoc.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…oracles

Cover concurrent start, every-async-error collection, and mixed
sync/async error ordering deterministically.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@esenmx
esenmx force-pushed the perf/concurrent-disposers-disposable-bag-1763264514431639548 branch from 0eb65e9 to 261ec3e Compare August 23, 2026 13:54
@esenmx
esenmx merged commit 21c6537 into master Aug 23, 2026
6 checks passed
@esenmx
esenmx deleted the perf/concurrent-disposers-disposable-bag-1763264514431639548 branch August 23, 2026 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant