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 #1410

Merged
merged 2 commits into from
Oct 28, 2023

Conversation

tmccombs
Copy link
Collaborator

I think this might help startup time a little bit, since it looks like on linux at least the std implementation uses syscalls to determine the parallelism, whereas num_cpus was processing the /proc/cpuinfo file.

It also removes another dependency.

I think this might help startup time a little bit, since it looks like
on linux at least the std implementation uses syscalls to determine the
parallelism, whereas num_cpus was processing the /proc/cpuinfo file.

It also removes another dependency.
@tavianator tavianator changed the title Replace num_cpus with std::thread::available_parallelism Replace num_cpus with std::thread::available_parallelism Oct 25, 2023
fn default_num_threads() -> usize {
// If we can't get the amount of parallelism for some reason, then
// default to a single thread, because that is safe.
const FALLBACK_PARALLELISM: NonZeroUsize = NonZeroUsize::MIN;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a long-winded way of writing 1, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. Maybe it would be more readable if I changed this to just 1, and used a pattern match?

I debated having the threads method return a NonZeroUsize, but wasn't sure if there was any benefit.

@tmccombs tmccombs mentioned this pull request Oct 26, 2023
Copy link
Owner

@sharkdp sharkdp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

@tmccombs tmccombs merged commit c96b1af into sharkdp:master Oct 28, 2023
15 checks passed
@tmccombs tmccombs deleted the available-parallelism branch October 28, 2023 05:25
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.

3 participants