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

Speed up tidy #105829

Merged
merged 3 commits into from
Dec 18, 2022
Merged
Changes from 1 commit
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
22 changes: 16 additions & 6 deletions src/tools/tidy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,26 @@ fn main() {

let bad = std::sync::Arc::new(AtomicBool::new(false));

let drain_handles = |handles: &mut VecDeque<ScopedJoinHandle<'_, ()>>| {
// poll all threads for completion before awaiting the oldest one
for i in (0..handles.len()).rev() {
if handles[i].is_finished() {
handles.swap_remove_back(i).unwrap().join().unwrap();
}
}
Comment on lines +38 to +44
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this useful? Does it run any faster or is it just releasing the resources earlier?

Oh, I guess removing a handle means you have more space in the queue to add more jobs? I'm a little confused why you would only run this once instead of putting it in the loop below ... maybe we should use rayon::ParallelIterator instead so we always join the first job to finish? All the custom concurrency code is a little hard to maintain in general.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is called every time in the check macro when a task is added to make room for the next task.

When I originally wrote this code (before is_finished existed) I think I wanted to add rayon but someone said it's better to keep the number of dependencies low so it's faster when one doesn't have tidy compiled.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, the only place I see rayon mentioned in the original PR is #81833 (comment) - do you remember why you made that change?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, looks like #81833 (comment). Ok, we don't need to revisit that here.


while handles.len() >= concurrency.get() {
handles.pop_front().unwrap().join().unwrap();
}
};

scope(|s| {
let mut handles: VecDeque<ScopedJoinHandle<'_, ()>> =
VecDeque::with_capacity(concurrency.get());

macro_rules! check {
($p:ident $(, $args:expr)* ) => {
while handles.len() >= concurrency.get() {
handles.pop_front().unwrap().join().unwrap();
}
drain_handles(&mut handles);

let handle = s.spawn(|| {
let mut flag = false;
Expand Down Expand Up @@ -97,9 +108,8 @@ fn main() {
check!(alphabetical, &library_path);

let collected = {
while handles.len() >= concurrency.get() {
handles.pop_front().unwrap().join().unwrap();
}
drain_handles(&mut handles);

let mut flag = false;
let r = features::check(&src_path, &compiler_path, &library_path, &mut flag, verbose);
if flag {
Expand Down