Skip to content

Commit 8673323

Browse files
committed
perf!: replace rayon with orx-parallel
Resolves #305
1 parent b95c593 commit 8673323

File tree

11 files changed

+178
-45
lines changed

11 files changed

+178
-45
lines changed

Cargo.lock

Lines changed: 127 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ derive_setters = "0.1.8"
5959
fmt-iter = "0.2.1"
6060
into-sorted = "0.0.3"
6161
itertools = "0.14.0"
62+
orx-parallel = "2.3.0"
6263
pipe-trait = "0.4.0"
63-
rayon = "1.10.0"
6464
rounded-div = "0.1.2"
6565
serde = { version = "1.0.219", optional = true }
6666
serde_json = { version = "1.0.141", optional = true }
@@ -77,3 +77,4 @@ maplit = "1.0.2"
7777
normalize-path = "0.2.1"
7878
pretty_assertions = "1.4.1"
7979
rand = "0.9.2"
80+
rayon = "1.10.0" # TODO: replace this with orx-parallel

src/app.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl App {
6767
.map_err(RuntimeError::DeserializationFailure)?
6868
.body;
6969

70-
trait VisualizeJsonTree: size::Size + Into<u64> + Send {
70+
trait VisualizeJsonTree: size::Size + Into<u64> + Send + Sync {
7171
fn visualize_json_tree(
7272
tree: JsonTree<Self>,
7373
bytes_format: Self::DisplayFormat,
@@ -103,7 +103,7 @@ impl App {
103103
}
104104
}
105105

106-
impl<Size: size::Size + Into<u64> + Send> VisualizeJsonTree for Size {}
106+
impl<Size: size::Size + Into<u64> + Send + Sync> VisualizeJsonTree for Size {}
107107

108108
macro_rules! visualize {
109109
($tree:expr, $bytes_format:expr) => {
@@ -149,10 +149,7 @@ impl App {
149149
};
150150

151151
if let Some(threads) = threads {
152-
rayon::ThreadPoolBuilder::new()
153-
.num_threads(threads)
154-
.build_global()
155-
.unwrap_or_else(|_| eprintln!("warning: Failed to set thread limit to {threads}"));
152+
todo!("Set number of threads to {threads}");
156153
}
157154

158155
if cfg!(unix) && self.args.deduplicate_hardlinks && self.args.files.len() > 1 {

src/data_tree/hardlink.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use super::DataTree;
22
use crate::size;
33
use assert_cmp::debug_assert_op;
4-
use rayon::prelude::*;
4+
use orx_parallel::*;
55
use std::{ffi::OsStr, path::Path};
66

77
impl<Name, Size> DataTree<Name, Size>
88
where
9-
Self: Send,
9+
Self: Send + Sync,
1010
Name: AsRef<OsStr>,
1111
Size: size::Size + Sync,
1212
{
@@ -39,7 +39,8 @@ where
3939
}
4040

4141
self.children
42-
.par_iter_mut()
42+
.iter_mut() // TODO: request orx-parallel to add par_mut
43+
.iter_into_par()
4344
.for_each(|child| child.par_deduplicate_hardlinks(&sub_hardlink_info))
4445
}
4546
}

src/data_tree/reflection/par_methods.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use super::{ConversionError, Reflection};
22
use crate::{data_tree::DataTree, size};
3-
use rayon::prelude::*;
3+
use orx_parallel::*;
44
use std::{ffi::OsStr, iter::once};
55

66
impl<Name, Size> Reflection<Name, Size>
77
where
8-
Name: Send,
9-
Size: size::Size + Send,
8+
Name: Send + Sync,
9+
Size: size::Size + Send + Sync,
1010
{
1111
/// Attempting to convert a [`Reflection`] into a valid [`DataTree`].
1212
pub fn par_try_into_tree(self) -> Result<DataTree<Name, Size>, ConversionError<Name, Size>> {
@@ -25,8 +25,10 @@ where
2525
return Err(ConversionError::ExcessiveChildren { path, size, child });
2626
}
2727
let children: Result<Vec<_>, _> = children
28-
.into_par_iter()
28+
.into_par()
2929
.map(Self::par_try_into_tree)
30+
.collect::<Vec<Result<_, _>>>() // TODO: request orx-parallel to make collecting Result possible
31+
.into_iter()
3032
.collect();
3133
let children = match children {
3234
Ok(children) => children,
@@ -52,9 +54,9 @@ where
5254
transform: Transform,
5355
) -> Result<Reflection<TargetName, TargetSize>, Error>
5456
where
55-
TargetName: Send,
57+
TargetName: Send + Sync,
5658
TargetSize: size::Size + Send + Sync,
57-
Error: Send,
59+
Error: Send + Sync,
5860
Transform: Fn(Name, Size) -> Result<(TargetName, TargetSize), Error> + Copy + Sync,
5961
{
6062
let Reflection {
@@ -63,8 +65,10 @@ where
6365
children,
6466
} = self;
6567
let children = children
66-
.into_par_iter()
68+
.into_par()
6769
.map(|child| child.par_try_map(transform))
70+
.collect::<Vec<Result<_, _>>>() // TODO: request orx-parallel to make collecting Result possible
71+
.into_iter()
6872
.collect::<Result<Vec<_>, _>>()?;
6973
let (name, size) = transform(name, size)?;
7074
Ok(Reflection {

src/data_tree/retain.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use super::DataTree;
22
use crate::size;
3-
use rayon::prelude::*;
3+
use orx_parallel::*;
44

55
impl<Name, Size> DataTree<Name, Size>
66
where
7-
Self: Send,
7+
Self: Send + Sync,
88
Size: size::Size,
99
{
1010
/// Internal function to be used by [`Self::par_retain`].
@@ -17,7 +17,8 @@ where
1717
.retain(|child| predicate(child, current_depth));
1818
let next_depth = current_depth + 1;
1919
self.children
20-
.par_iter_mut()
20+
.iter_mut() // TODO: request orx-parallel to add par_mut
21+
.iter_into_par()
2122
.for_each(|child| child.par_retain_with_depth(next_depth, predicate))
2223
}
2324

src/data_tree/sort.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
use super::DataTree;
22
use crate::size;
3-
use rayon::prelude::*;
3+
use orx_parallel::*;
44
use std::cmp::Ordering;
55

66
impl<Name, Size> DataTree<Name, Size>
77
where
8-
Self: Send,
8+
Self: Send + Sync,
99
Size: size::Size,
1010
{
1111
/// Sort all descendants recursively, in parallel.
1212
pub fn par_sort_by(&mut self, compare: impl Fn(&Self, &Self) -> Ordering + Copy + Sync) {
1313
self.children
14-
.par_iter_mut()
14+
.iter_mut() // TODO: request orx-parallel to add par_mut
15+
.iter_into_par()
1516
.for_each(|child| child.par_sort_by(compare));
1617
self.children.sort_unstable_by(compare);
1718
}

src/tree_builder.rs

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

55
use super::{data_tree::DataTree, size};
6-
use rayon::prelude::*;
6+
use orx_parallel::*;
77

88
/// Collection of functions and starting points in order to build a [`DataTree`] with [`From`] or [`Into`].
99
#[derive(Debug)]
@@ -34,7 +34,7 @@ where
3434
Name: Send + Sync,
3535
GetInfo: Fn(&Path) -> Info<Name, Size> + Copy + Send + Sync,
3636
JoinPath: Fn(&Path, &Name) -> Path + Copy + Send + Sync,
37-
Size: size::Size + Send,
37+
Size: size::Size + Send + Sync,
3838
{
3939
/// Create a [`DataTree`] from a [`TreeBuilder`].
4040
fn from(builder: TreeBuilder<Path, Name, Size, GetInfo, JoinPath>) -> Self {
@@ -50,7 +50,7 @@ where
5050
let max_depth = max_depth.saturating_sub(1);
5151

5252
let children = children
53-
.into_par_iter()
53+
.into_par()
5454
.map(|name| TreeBuilder {
5555
path: join_path(&path, &name),
5656
name,

0 commit comments

Comments
 (0)