Skip to content

Commit d81be04

Browse files
committed
perf: eagerly process each 64 tasks
1 parent 84b2321 commit d81be04

1 file changed

Lines changed: 22 additions & 10 deletions

File tree

src/tree_builder.rs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pub mod info;
33
pub use info::Info;
44

55
use super::{data_tree::DataTree, size};
6+
use itertools::Itertools;
67
use rayon::prelude::*;
78

89
/// Collection of functions and starting points in order to build a [`DataTree`] with [`From`] or [`Into`].
@@ -55,20 +56,31 @@ where
5556

5657
let children = children
5758
.into_iter()
58-
.par_bridge()
59-
.map(|name| TreeBuilder {
60-
path: join_path(&path, &name),
61-
name,
62-
get_info,
63-
join_path,
64-
max_depth,
59+
.chunks(64)
60+
.into_iter()
61+
.map(Vec::<NameIter::Item>::from_iter)
62+
.map(|names| -> Vec<_> {
63+
names
64+
.into_par_iter()
65+
.map(|name| TreeBuilder {
66+
path: join_path(&path, &name),
67+
name,
68+
get_info,
69+
join_path,
70+
max_depth,
71+
})
72+
.map(Self::from)
73+
.collect()
6574
})
66-
.map(Self::from);
75+
.fold(Vec::new(), |mut a, b| {
76+
a.extend(b);
77+
a
78+
});
6779

6880
if max_depth > 0 {
69-
DataTree::dir(name, size, children.collect())
81+
DataTree::dir(name, size, children)
7082
} else {
71-
let size = size + children.map(|child| child.size()).sum();
83+
let size = size + children.into_iter().map(|child| child.size()).sum();
7284
DataTree::dir(name, size, Vec::new())
7385
}
7486
}

0 commit comments

Comments
 (0)