⚡ Bolt: [performance improvement] Eliminate Vector Reallocation in Scheduler Fast Path - #81
Conversation
In the `enforce_concurrency_limits` fast path, an incoming `Vec` was being filtered via `into_iter().enumerate().filter().collect()`. Since we already own the input vector, we can use `.retain()` to filter elements in-place without triggering memory reallocation for a new `Vec`. Additionally, added a `.dedup()` call on the exclusion slice immediately after `.sort_unstable()` to slightly optimize `.binary_search` lookups inside the hot loop. Co-authored-by: ovasylenko <3797513+ovasylenko@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. |
Applies cargo fmt to resolve formatting issues that caused CI failure. Co-authored-by: ovasylenko <3797513+ovasylenko@users.noreply.github.com>
In the `enforce_concurrency_limits` fast path, an incoming `Vec` was being filtered via `into_iter().enumerate().filter().collect()`. Since we already own the input vector, we can use `.retain()` to filter elements in-place without triggering memory reallocation for a new `Vec`. Additionally, added a `.dedup()` call on the exclusion slice immediately after `.sort_unstable()` to slightly optimize `.binary_search` lookups inside the hot loop. This commit also fixes an unrelated formatting issue in `orch8-api/src/instances.rs` that was failing CI. Co-authored-by: ovasylenko <3797513+ovasylenko@users.noreply.github.com>
In the `enforce_concurrency_limits` fast path, an incoming `Vec` was being filtered via `into_iter().enumerate().filter().collect()`. Since we already own the input vector, we can use `.retain()` to filter elements in-place without triggering memory reallocation for a new `Vec`. Additionally, added a `.dedup()` call on the exclusion slice immediately after `.sort_unstable()` to slightly optimize `.binary_search` lookups inside the hot loop. This commit also fixes an unrelated formatting issue in `orch8-api/src/instances.rs` that was failing CI. Co-authored-by: ovasylenko <3797513+ovasylenko@users.noreply.github.com>
💡 What: Replaced
into_iter().enumerate().filter(...).collect()with.retain(...)inenforce_concurrency_limits, and added.dedup()after.sort_unstable().🎯 Why:
collect()forces an unnecessary memory allocation of a newVec, consuming resources under heavy load on the scheduler fast path.📊 Impact: Eliminates a memory allocation per batch when concurrency limits are enforced, reducing GC pressure and execution time.
🔬 Measurement: Validated correctness with
cargo test -p orch8-engine --lib scheduler::tests, ran format and clippy.PR created automatically by Jules for task 9903002544254924122 started by @ovasylenko