Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace num_cpus with std::thread::available_parallelism. #912

Merged
merged 3 commits into from
Jan 24, 2024

Conversation

partim
Copy link
Member

@partim partim commented Dec 1, 2023

This PR removes the dependency on the num_cpus crate by using the standard library’s std::thread::available_parallelism instead.

Fixes #902.

@partim partim requested a review from a team December 1, 2023 15:42
@partim partim changed the title Replace num_cpus with std::thread::available_parallelism. Replace num_cpus with std::thread::available_parallelism. Dec 1, 2023
@ximon18
Copy link
Member

ximon18 commented Jan 3, 2024

LGTM, the fns called by both the old and the new code seem to query for some number of "logical" CPUs so that's consistent. One minor point: I did wonder whether it would make sense to extract this repeated code fragment into a helper fn:

available_parallelism().map(|x| x.get()).unwrap_or(1)

@partim
Copy link
Member Author

partim commented Jan 24, 2024

Sounds like a good idea, indeed. Done!

@partim partim merged commit 44c763b into main Jan 24, 2024
10 checks passed
@partim partim deleted the available-parallelism branch January 24, 2024 16:12
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.

Use std lib instead of num_cpus
2 participants