Skip to content

Commit

Permalink
hack
Browse files Browse the repository at this point in the history
  • Loading branch information
bootandy committed Dec 11, 2023
1 parent 09c6ff4 commit eb9f370
Showing 1 changed file with 21 additions and 24 deletions.
45 changes: 21 additions & 24 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,27 @@ fn main() {
follow_links,
progress_data: indicator.data.clone(),
};

let custom_stack_size = config.get_custom_stack_size(&options);
let result = panic::catch_unwind(|| init_rayon(custom_stack_size));
let stack_size = config.get_custom_stack_size(&options);
let result = panic::catch_unwind(|| {
match stack_size {
Some(n) => rayon::ThreadPoolBuilder::new().stack_size(n).build_global(),
None => {
let large_stack = usize::pow(1024, 3);
let mut s = System::new();
s.refresh_memory();
let available = s.available_memory();

if available > large_stack.try_into().unwrap() {
// Larger stack size to handle cases with lots of nested directories
rayon::ThreadPoolBuilder::new()
.stack_size(large_stack)
.build_global()
} else {
rayon::ThreadPoolBuilder::new().build_global()
}
}
}
});
if result.is_err() {
eprintln!("Problem initializing rayon, try: export RAYON_NUM_THREADS=1")
}
Expand Down Expand Up @@ -227,24 +245,3 @@ fn main() {
)
}
}

fn init_rayon(custom_stack_size: Option<usize>) -> Result<(), ThreadPoolBuildError> {
match custom_stack_size {
Some(n) => rayon::ThreadPoolBuilder::new().stack_size(n).build_global(),
None => {
let large_stack = usize::pow(1024, 3);
let mut s = System::new();
s.refresh_memory();
let available = s.available_memory();

if available > large_stack.try_into().unwrap() {
// Larger stack size to handle cases with lots of nested directories
rayon::ThreadPoolBuilder::new()
.stack_size(large_stack)
.build_global()
} else {
rayon::ThreadPoolBuilder::new().build_global()
}
}
}
}

0 comments on commit eb9f370

Please sign in to comment.