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

Reduce default thread count #99

Merged
merged 1 commit into from
Mar 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions src/render/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ pub struct Context {
#[arg(short = 'S', long)]
pub follow_links: bool,

/// Number of threads to use; defaults to number of logical cores available
#[arg(short, long, default_value_t = Context::default_threads())]
/// Number of threads to use
#[arg(short, long, default_value_t = 3)]
pub threads: usize,

/// Omit disk usage from output; disabled by default
Expand Down Expand Up @@ -181,12 +181,6 @@ impl Context {
Context::from_arg_matches(&user_args).map_err(|e| Error::ArgParse(e))
}

fn default_threads() -> usize {
available_parallelism()
.unwrap_or_else(|_| NonZeroUsize::new(1).unwrap())
.get()
}

/// Returns reference to the path of the root directory to be traversed.
pub fn dir(&self) -> &Path {
self.dir
Expand Down
9 changes: 3 additions & 6 deletions src/render/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,12 @@ impl Tree {
/// parallel traversal; post-processing post-processing of all directory entries should
/// be completely CPU-bound.
fn traverse(ctx: &Context) -> TreeResult<(Arena<Node>, NodeId)> {
let walker = WalkParallel::try_from(ctx)?;
let (tx, rx) = channel::unbounded::<TraversalState>();

thread::scope(|s| {
let mut tree = Arena::new();

let res = s.spawn(|| {
// Key represents path of parent directory and values represent children.
let mut tree = Arena::new();
let mut branches: HashMap<PathBuf, Vec<NodeId>> = HashMap::new();

// Set used to prevent double counting hard-links in the same file-tree hiearchy.
let mut inodes = HashSet::new();

let mut root_id = None;
Expand Down Expand Up @@ -135,6 +130,8 @@ impl Tree {

let mut visitor_builder = BranchVisitorBuilder::new(ctx, Sender::clone(&tx));

let walker = WalkParallel::try_from(ctx)?;

walker.visit(&mut visitor_builder);

tx.send(TraversalState::Done).unwrap();
Expand Down