Refactor: Replace unbounded thread spawning with rayon parallel iterators#300
Refactor: Replace unbounded thread spawning with rayon parallel iterators#300karthiknadig merged 2 commits intomainfrom
Conversation
…tors - Add rayon 1.11.0 dependency to pet-conda and pet-homebrew crates - Refactor get_conda_environments() in lib.rs to use par_iter() - Refactor get_conda_environment_paths() in environment_locations.rs to use par_iter() - Refactor get_known_symlinks() in sym_links.rs to use par_iter() This provides controlled parallelism based on CPU count, better resource management, and avoids potential thread exhaustion on systems with hundreds of Python environments. Co-authored-by: karthiknadig <3840081+karthiknadig@users.noreply.github.com>
PR Review: Replace unbounded thread spawning with rayoncc @copilot Overall Assessment: Positive with minor observationsThe PR correctly addresses a legitimate issue—unbounded thread spawning can cause thread exhaustion on systems with many conda environments (hundreds is common for data scientists). Strengths
Observations
Verification// Before (environment_locations.rs)
threads.push(thread::spawn(move || get_environments(&path)));
// After
.flat_map(|path| get_environments(path))Semantically correct— RecommendationLooks good to merge once CI passes. The dependency addition (rayon 1.11) is reasonable and the refactoring is sound. |
Several locations spawn unbounded threads during environment discovery, which can cause thread exhaustion on systems with many conda environments or symlinks.
Changes
get_conda_environments()now usespar_iter()instead of spawning one thread per pathget_conda_environment_paths()usespar_iter()for environment enumerationget_known_symlinks()usespar_iter()for symlink resolutionAdded
rayon = "1.11.0"to both crates.Before/After
crates/pet/src/find.rsleft unchanged—it usesthread::scopewith a fixed number of locators/directories, which is already bounded.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.