Skip to content

Remove AsThreadPool generic trait; take &RayonThreadPool directly#906

Open
Copilot wants to merge 4 commits intomainfrom
copilot/whittle-down-scope-of-rayon-utils
Open

Remove AsThreadPool generic trait; take &RayonThreadPool directly#906
Copilot wants to merge 4 commits intomainfrom
copilot/whittle-down-scope-of-rayon-utils

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 6, 2026

  • Remove AsThreadPool generic trait, replace with direct &RayonThreadPool parameters
  • Update all callers across workspace (18 files, 4 crates)
  • Merge latest main to resolve conflict (accepted main's deletion of normalizing_util.rs)
  • Verified: cargo check --workspace --all-targets passes
  • Verified: cargo clippy --workspace --all-targets -- -D warnings passes

Copilot AI and others added 2 commits April 6, 2026 20:54
…er args

The train_pq function signature changed from taking a generic
AsThreadPool parameter to taking &RayonThreadPool. Update all call
sites that passed integer values (1usize, 1, 2) to instead create
a RayonThreadPool via create_thread_pool() and pass a reference.

Files updated:
- diskann_async.rs: 12 call sites
- debug_provider.rs: 3 call sites
- wrapped_async.rs: 1 call site
- index_storage.rs: 1 call site

Co-authored-by: Copilot <[email protected]>

Co-authored-by: harsha-simhadri <[email protected]>
…ool parameters

Remove the AsThreadPool trait, sealed module, forward_threadpool! macro,
and execute_with_rayon function. Replace all generic Pool: AsThreadPool
parameters with concrete &RayonThreadPool references across the codebase.

Co-authored-by: Copilot <[email protected]>

Co-authored-by: harsha-simhadri <[email protected]>
Copilot AI changed the title [WIP] Refactor rayon_util to reduce generics usage Remove AsThreadPool generic trait; take &RayonThreadPool directly Apr 6, 2026
Copilot AI requested a review from harsha-simhadri April 6, 2026 21:16
…scope-of-rayon-utils

# Conflicts:
#	diskann-providers/src/utils/normalizing_util.rs

Co-authored-by: harsha-simhadri <[email protected]>
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 7, 2026

Codecov Report

❌ Patch coverage is 93.42105% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.34%. Comparing base (de98ea6) to head (b54ae16).

Files with missing lines Patch % Lines
diskann-tools/src/utils/build_pq.rs 0.00% 4 Missing ⚠️
diskann-disk/src/build/builder/quantizer.rs 75.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #906   +/-   ##
=======================================
  Coverage   89.34%   89.34%           
=======================================
  Files         444      444           
  Lines       83986    83913   -73     
=======================================
- Hits        75036    74971   -65     
+ Misses       8950     8942    -8     
Flag Coverage Δ
miri 89.34% <93.42%> (+<0.01%) ⬆️
unittests 89.18% <93.42%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
diskann-benchmark/src/backend/index/product.rs 100.00% <ø> (ø)
diskann-disk/src/build/builder/build.rs 94.16% <100.00%> (ø)
diskann-disk/src/build/builder/core.rs 95.25% <100.00%> (ø)
diskann-disk/src/storage/quant/generator.rs 92.67% <100.00%> (-0.06%) ⬇️
diskann-disk/src/storage/quant/pq/pq_generation.rs 93.22% <100.00%> (-0.12%) ⬇️
diskann-disk/src/utils/partition.rs 92.51% <100.00%> (-0.04%) ⬇️
diskann-providers/src/index/diskann_async.rs 96.40% <100.00%> (+0.02%) ⬆️
diskann-providers/src/index/wrapped_async.rs 46.17% <100.00%> (+0.31%) ⬆️
.../src/model/graph/provider/async_/debug_provider.rs 84.99% <100.00%> (+0.05%) ⬆️
diskann-providers/src/model/pq/pq_construction.rs 92.03% <100.00%> (-0.12%) ⬇️
... and 6 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@harsha-simhadri harsha-simhadri marked this pull request as ready for review April 7, 2026 00:55
@harsha-simhadri harsha-simhadri requested review from a team and Copilot April 7, 2026 00:55
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 removes the AsThreadPool abstraction and updates the workspace to pass &RayonThreadPool explicitly, simplifying thread-pool handling across PQ training, k-means utilities, disk build workflows, and benchmarks.

Changes:

  • Removed AsThreadPool and the forward_threadpool macro; APIs now take &RayonThreadPool directly.
  • Updated PQ/k-means/math utilities and all call sites (including tests) to create and pass a RayonThreadPool reference.
  • Adjusted generic signatures in PQ construction functions to drop the former thread-pool type parameter.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated no comments.

Show a summary per file
File Description
diskann-tools/src/utils/build_pq.rs Creates a thread pool once and passes &RayonThreadPool into PQ pivot/data generation.
diskann-providers/src/utils/rayon_util.rs Removes AsThreadPool + macro; keeps RayonThreadPool helpers and in-pool parallel iterator extensions.
diskann-providers/src/utils/mod.rs Stops re-exporting removed thread-pool abstractions/utilities.
diskann-providers/src/utils/math_util.rs Updates math helpers to accept &RayonThreadPool directly.
diskann-providers/src/utils/kmeans.rs Updates k-means entrypoints to accept &RayonThreadPool directly.
diskann-providers/src/storage/index_storage.rs Updates tests to pass a &RayonThreadPool into train_pq.
diskann-providers/src/model/pq/pq_construction.rs Removes thread-pool generic type parameters and accepts &RayonThreadPool.
diskann-providers/src/model/graph/provider/async_/debug_provider.rs Updates tests to create/pass &RayonThreadPool to PQ training.
diskann-providers/src/model/graph/provider/async_/caching/example.rs Updates tests to create/pass &RayonThreadPool to PQ training.
diskann-providers/src/index/wrapped_async.rs Updates tests to create/pass &RayonThreadPool to PQ training.
diskann-providers/src/index/diskann_async.rs train_pq now takes &RayonThreadPool; updates all internal tests/callers.
diskann-disk/src/utils/partition.rs Partitioning now takes &RayonThreadPool directly and threads it through helpers.
diskann-disk/src/storage/quant/pq/pq_generation.rs PQ generation context/compressor updated to store/pass &RayonThreadPool.
diskann-disk/src/storage/quant/generator.rs Quant data generator now takes &RayonThreadPool directly.
diskann-disk/src/build/builder/quantizer.rs Creates a pool and passes &RayonThreadPool into PQ training during quantizer training.
diskann-disk/src/build/builder/core.rs Updates partition call to match new partitioning signature.
diskann-disk/src/build/builder/build.rs Updates quant data generation pipeline to pass &RayonThreadPool directly.
diskann-benchmark/src/backend/index/product.rs Benchmark build path now creates a pool and passes &RayonThreadPool to PQ training.
Comments suppressed due to low confidence (1)

diskann-providers/src/utils/rayon_util.rs:15

  • create_thread_pool is documented to treat num_threads == 0 as “default to logical CPUs”, but the implementation always calls ThreadPoolBuilder::num_threads(num_threads). This makes the behavior for 0 rely on Rayon internals and can fail (or at least be ambiguous), and there are callers in the workspace that pass 0. Consider handling num_threads == 0 explicitly (e.g., skip num_threads(...) / use available_parallelism, or clamp to >= 1) so the documented contract is enforced deterministically.
/// Creates a new thread pool with the specified number of threads.
/// If `num_threads` is 0, it defaults to the number of logical CPUs.
pub fn create_thread_pool(num_threads: usize) -> ANNResult<RayonThreadPool> {
    let pool = rayon::ThreadPoolBuilder::new()
        .num_threads(num_threads)
        .build()
        .map_err(|err| ANNError::log_thread_pool_error(err.to_string()))?;
    Ok(RayonThreadPool(pool))

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

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.

whittle down scope of rayon_utils.rs

4 participants