⚡ Bolt: Optimize high-concurrency workflow execution#143
⚡ Bolt: Optimize high-concurrency workflow execution#143thalesraymond wants to merge 1 commit intomainfrom
Conversation
Replaces `Promise.race(executingPromises)` with a manually managed `signalPromise` in the main execution loop. This optimization eliminates the O(N^2) overhead associated with repeatedly creating race promises for a large set of executing tasks. Benchmarks show a significant performance improvement for high-concurrency scenarios: - Before: ~2258ms for 2000 concurrent tasks (simulated delay) - After: ~130ms for 2000 concurrent tasks This change ensures that the `WorkflowExecutor` scales linearly with the number of tasks, rather than quadratically. Co-authored-by: thalesraymond <32554150+thalesraymond@users.noreply.github.com>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Summary of ChangesHello @thalesraymond, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly optimizes the Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Code Review
This pull request introduces a significant performance optimization for high-concurrency workflows by replacing Promise.race with a custom signal-based mechanism. The implementation is clever and effectively addresses the O(N²) overhead issue.
My review includes a couple of suggestions to further improve the code's clarity and maintainability by removing a redundant function call and reducing code duplication. Overall, this is a great improvement.
| let resolveSignal: (() => void) | undefined; | ||
| let signalPromise = new Promise<void>((r) => (resolveSignal = r)); |
There was a problem hiding this comment.
The logic to create a new signal promise is duplicated here and again on line 97. To improve maintainability and reduce duplication, consider extracting this into a helper function. This also makes the code more self-documenting by giving a name to the operation.
You would then also replace the code on line 97 with signalPromise = createSignalPromise();.
| let resolveSignal: (() => void) | undefined; | |
| let signalPromise = new Promise<void>((r) => (resolveSignal = r)); | |
| let resolveSignal: (() => void) | undefined; | |
| const createSignalPromise = () => new Promise<void>((r) => (resolveSignal = r)); | |
| let signalPromise = createSignalPromise(); |
| } else { | ||
| // After a task finishes, check for new work | ||
| this.processLoop(executingPromises, signal); | ||
| this.processLoop(executingPromises, notify, signal); | ||
| } |
There was a problem hiding this comment.
This else block containing a call to processLoop appears to be redundant. The finally block of each task promise (lines 150-156) already calls processLoop when a task completes to immediately schedule new work. The notify() call then wakes up this main loop.
Since the work scheduling is already handled in the finally block, this second call is unnecessary. Removing this else block will simplify the logic without affecting functionality.



💡 What: Replaced the
Promise.raceloop inWorkflowExecutorwith a signal-based synchronization mechanism.🎯 Why:
Promise.raceon a largeSetof promises inside a loop causes significant O(N²) overhead as the number of concurrent tasks grows, because it re-attaches handlers to all executing promises in every iteration.📊 Impact: Reduces execution time for 2000 concurrent tasks from ~2.2s to ~0.13s (a ~17x speedup).
🔬 Measurement: Verified using a temporary benchmark (
tests/WorkflowExecutor_bench.test.ts) with 2000 tasks and random delays. Existing tests pass with 100% coverage.PR created automatically by Jules for task 9498767348345128190 started by @thalesraymond