Skip to content

Commit

Permalink
Merge pull request #99 from solidiquis/default-thread-count
Browse files Browse the repository at this point in the history
Reduce default thread count
  • Loading branch information
solidiquis authored Mar 25, 2023
2 parents e118046 + 300c61b commit 82c192e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
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

0 comments on commit 82c192e

Please sign in to comment.