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

Heuristics of ignore::WalkParallel's threads field: hardcoded to 2? #2854

Open
1 task done
alexpovel opened this issue Jul 16, 2024 · 2 comments · May be fixed by #2856
Open
1 task done

Heuristics of ignore::WalkParallel's threads field: hardcoded to 2? #2854

alexpovel opened this issue Jul 16, 2024 · 2 comments · May be fixed by #2856

Comments

@alexpovel
Copy link

Please tick this box to confirm you have reviewed the above.

  • I have a different issue.

What version of ripgrep are you using?

ignore = "0.4.22"

How did you install ripgrep?

n/a

What operating system are you using ripgrep on?

n/a

Describe your bug.

I'm using WalkParallel for, well, parallel, recursive directory traversal. There's a threads parameter which I left unspecified (using WalkBuilder):

threads: usize,

The docs say if left unspecified, aka at 0, the number of threads will be picked based on heuristics:

/// The default setting is `0`, which chooses the number of threads
/// automatically using heuristics.

What are the steps to reproduce the behavior?

Execute

ignore::WalkBuilder::new(&some_path)
        .build_parallel()
        .run(todo!())

What is the actual behavior?

Using these settings, I noticed my application using 200% CPU, where more cores would have been available.

What is the expected behavior?

Processing to use more threads, as determined by the heuristics.

It turns out, threads is hard-coded to 2 if unspecified:

if self.threads == 0 {
2

where for the 'heuristic', I expected something along the lines of num_cpus. I can confirm setting threads to num_cpus::get(), 12 in my case, yields results as expected.

Could/should this be used as the heuristic? It is a substantial, free win in my case.

If not, then the docs should probably be adjusted.

@BurntSushi
Copy link
Owner

It is still technically a heuristic, although not a very good one. :-)

I think I'd be okay if you copied ripgrep's heuristic to ignore:

std::thread::available_parallelism().map_or(1, |n| n.get()).min(12)

And use std, not an extra crate.

@alexpovel
Copy link
Author

Thanks for the quick reply and pointer to ripgrep's implementation! I'll get onto that.

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 a pull request may close this issue.

2 participants