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

Multithreaded component refresh #1232

Merged
merged 6 commits into from
Mar 20, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3822,9 +3822,19 @@ impl Components {
/// components.refresh();
/// ```
pub fn refresh(&mut self) {
for component in self.list_mut() {
component.refresh();
#[cfg(feature = "multithread")]
Copy link
Owner

Choose a reason for hiding this comment

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

Instead of doing it like this, could you instead create an iter_mut() function into utils.rs (which would be the same as into_iter except it would call par_iter_mut/iter_mut) please? The idea is to prevent the duplication of .for_each(|component| component.refresh()). It might seem super small but it's easy to lose track of such things quite easily.

{
use rayon::iter::IntoParallelRefMutIterator;
use rayon::iter::ParallelIterator;
self.list_mut()
.par_iter_mut()
.for_each(|component| component.refresh());
}

#[cfg(not(feature = "multithread"))]
self.list_mut()
.iter_mut()
.for_each(|component| component.refresh());
}

/// The component list will be emptied then completely recomputed.
Expand Down