Remove AsThreadPool generic trait; take &RayonThreadPool directly#906
Open
Remove AsThreadPool generic trait; take &RayonThreadPool directly#906
Conversation
…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
…scope-of-rayon-utils # Conflicts: # diskann-providers/src/utils/normalizing_util.rs Co-authored-by: harsha-simhadri <[email protected]>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #906 +/- ##
=======================================
Coverage 89.34% 89.34%
=======================================
Files 444 444
Lines 83986 83913 -73
=======================================
- Hits 75036 74971 -65
+ Misses 8950 8942 -8
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
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
AsThreadPooland theforward_threadpoolmacro; APIs now take&RayonThreadPooldirectly. - Updated PQ/k-means/math utilities and all call sites (including tests) to create and pass a
RayonThreadPoolreference. - 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_poolis documented to treatnum_threads == 0as “default to logical CPUs”, but the implementation always callsThreadPoolBuilder::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 handlingnum_threads == 0explicitly (e.g., skipnum_threads(...)/ useavailable_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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AsThreadPoolgeneric trait, replace with direct&RayonThreadPoolparametersnormalizing_util.rs)cargo check --workspace --all-targetspassescargo clippy --workspace --all-targets -- -D warningspasses