Skip to content

fix: bound component operation concurrency and pre-allocate future buffers#81

Merged
bashandbone merged 2 commits into
optimize-component-upserts-10693844638826288617from
copilot/sub-pr-79
Mar 13, 2026
Merged

fix: bound component operation concurrency and pre-allocate future buffers#81
bashandbone merged 2 commits into
optimize-component-upserts-10693844638826288617from
copilot/sub-pr-79

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 13, 2026

The previous try_join_all approach launched all delete/upsert futures simultaneously — unbounded concurrency that can saturate a DB connection pool at scale, with no protection against partial application on error.

Changes

  • Bounded concurrency: replaced try_join_all with buffer_unordered(COMPONENT_CONCURRENCY_LIMIT) + try_collect, capping simultaneous in-flight DB/network ops at 16
  • Named constant: COMPONENT_CONCURRENCY_LIMIT: usize = 16 with doc comment — visible and tunable relative to connection pool size
  • Pre-allocated buffers: Vec::with_capacity sized from upfront sum of all change counts, eliminating incremental reallocations
// Before — unbounded, all futures in flight at once
futures::future::try_join_all(delete_futures).await?;

// After — at most COMPONENT_CONCURRENCY_LIMIT concurrent ops
futures::stream::iter(delete_futures)
    .buffer_unordered(COMPONENT_CONCURRENCY_LIMIT)
    .try_collect::<Vec<_>>()
    .await?;

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

… pre-allocate Vec capacity

Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com>
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Mar 13, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
recoco-docs 8ee551b Commit Preview URL

Branch Preview URL
Mar 13 2026, 03:36 AM

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 13, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • test
    • Triggering command: /home/REDACTED/work/recoco/recoco/target/debug/deps/recoco_core-b2f1c4eca26c649c /home/REDACTED/work/recoco/recoco/target/debug/deps/recoco_core-b2f1c4eca26c649c /home/REDACTED/.rustup/toolchains/stable-x86_64-REDACTED-linux-gnu/lib/rustlib/x86_-z /home/REDACTED/.rustup/toolchains/stable-x86_64-REDACTED-linux-gnu/lib/rustlib/x86_relro /home/REDACTED/.rustup/toolchains/stable-x86_64-REDACTED-linux-gnu/lib/rustlib/x86_-o /home/REDACTED/.rustup/toolchains/stable-x86_64-REDACTED-linux-gnu/lib/rustlib/x86_/home/REDACTED/work/recoco/recoco/target/debug/deps/libasync_openai_macros-8c90bed4ec19328a.so /home/REDACTED/.rustup/toolchains/stable-x86_64-REDACTED-linux-gnu/lib/rustlib/x86_/usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/crti.o /home/REDACTED/.rustup/toolchains/stable-x86_64-REDACTED-linux-gnu/lib/rustlib/x86_/usr/lib/gcc/x86_64-linux-gnu/13/crtbeginS.o ream-0.2.3/src/lib.rs /home/REDACTED/.rustup/toolchains/stable-x86_64-REDACTED-linux-gnu/lib/rustlib/x86_-L/home/REDACTED/.rustup/toolchains/stable-x86_64-REDACTED-linux-gnu/lib/rustlib/x86_64-REDACTED-linux-gnu/lib /home/REDACTED/.rustup/toolchains/stable-x86_64-REDACTED-linux-gnu/lib/rustlib/x86_64-u�� /home/REDACTED/.rustup/toolchains/stable-x86_64-REDACTED-linux-gnu/lib/rustlib/x86_64-REDACTED-linux-gnu/lib/librustc_std_workspace_alloc-93ecc7719c6b3845.rlib /home/REDACTED/.rustup/toolchains/stable-x86_64-REDACTED-linux-gnu/lib/rustlib/x86_64-REDACTED-linux-gnu/lib/libminiz_oxide-ec844042f1e20091.rlib 1e30�� 1e30de32dcf689.a--error-format=json 1e30de32dcf689.a--json=diagnostic-rendered-ansi,artifacts,future-incompat bin/rustc 1e30de32dcf689.acc 1e30de32dcf689.a-m64 1e30de32dcf689.a/tmp/rustcIXdbCq/symbols.o bin/rustc (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] [1069384] Optimize component upsert to execute asynchronously fix: bound component operation concurrency and pre-allocate future buffers Mar 13, 2026
Copilot AI requested a review from bashandbone March 13, 2026 03:36
@bashandbone bashandbone marked this pull request as ready for review March 13, 2026 03:57
Copilot AI review requested due to automatic review settings March 13, 2026 03:57
@bashandbone bashandbone merged commit 86fd98e into optimize-component-upserts-10693844638826288617 Mar 13, 2026
4 checks passed
@bashandbone bashandbone deleted the copilot/sub-pr-79 branch March 13, 2026 03:57
@github-project-automation github-project-automation Bot moved this from Backlog to Done in Recoco v1.0.0 Mar 13, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR bounds concurrency for component delete/upsert operations and reduces allocation churn when applying many component changes.

Changes:

  • Replace unbounded try_join_all with buffer_unordered(COMPONENT_CONCURRENCY_LIMIT) to cap in-flight operations.
  • Introduce COMPONENT_CONCURRENCY_LIMIT constant (16) with documentation.
  • Pre-allocate the futures vectors using upfront totals to avoid repeated reallocations.
Comments suppressed due to low confidence (1)

crates/recoco-core/src/setup/components.rs:1

  • buffer_unordered bounds execution, but this still eagerly allocates and builds a Vec containing all delete/upsert futures up front, and then try_collect::<Vec<_>>() allocates a second Vec of results that is immediately discarded. For large change sets, this can be a significant memory spike and delays starting IO until the vectors are fully built. Consider switching to a lazy stream + try_for_each_concurrent(COMPONENT_CONCURRENCY_LIMIT, ...) (and ideally avoid the intermediate Vec entirely by streaming over keys/states directly) so work starts immediately and no result vector is allocated.
// Recoco is a Rust-only fork of CocoIndex, by [CocoIndex](https://CocoIndex)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

bashandbone added a commit that referenced this pull request Mar 13, 2026
…all (#79)

* Optimize component upsert to execute asynchronously using try_join_all

Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com>

* Optimize component upsert to execute asynchronously using try_join_all

Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com>

* fix: bound component operation concurrency and pre-allocate future buffers (#81)

* Initial plan

* fix: replace unbounded try_join_all with bounded buffer_unordered and pre-allocate Vec capacity

Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com>

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants