Use Arc<[PathBuf]> to reduce cloning overhead for shared path lists#299
Use Arc<[PathBuf]> to reduce cloning overhead for shared path lists#299karthiknadig merged 3 commits intomainfrom
Conversation
- Convert environment_directories and global_env_search_paths to Arc<[PathBuf]> for O(1) cloning in thread spawns instead of O(n) Vec cloning - Update find_python_environments and find_python_environments_in_paths_with_locators to accept &[PathBuf] slices instead of owned Vec<PathBuf> - Properly clone Arc references before move closures to maintain thread safety Co-authored-by: karthiknadig <3840081+karthiknadig@users.noreply.github.com>
find_executables accepts T: AsRef<Path>, so we can pass the reference directly without cloning Co-authored-by: karthiknadig <3840081+karthiknadig@users.noreply.github.com>
PR Reviewcc @copilot SummaryThe PR correctly reduces cloning overhead in What's Good
Concerns
VerdictLooks good overall. The implementation achieves the goal of reducing allocation overhead for the hot path (multiple workspace folders / PATH entries). Consider addressing the |
The Regarding the trade-off in |
Path lists are frequently cloned when passed to threads during environment discovery. Since these paths are immutable once created,
Arc<[PathBuf]>provides O(1) cloning via atomic increment instead of O(n) deep copies.Changes
Convert shared path lists to
Arc<[PathBuf]>environment_directoriesconverted before thread spawnsglobal_env_search_pathsconverted in workspace directory loopUpdate function signatures to accept
&[PathBuf]find_python_environmentsfind_python_environments_in_paths_with_locatorsRemove unnecessary clones
find_executablesacceptsAsRef<Path>, no clone requiredBefore/After
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.