Skip to content

Commit

Permalink
Remove parallel iterators in attribute processors (#4999)
Browse files Browse the repository at this point in the history
At least on my machine, the parallel iterators that were recently added
to the attribute processing methods result in at least an order of
magnitude performance loss.

With `par_iter`:

![image](https://github.com/rerun-io/rerun/assets/2910679/f2bbcace-2965-4ecf-b35d-ff565c6b0d98)


Without `par_iter`:

![image](https://github.com/rerun-io/rerun/assets/2910679/2eda2b43-4ab9-418e-a596-3d36ebb03027)

(Screenshots taken from #5000)
  • Loading branch information
teh-cmc authored Feb 1, 2024
1 parent 09782e6 commit 4897b93
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions crates/re_space_view_spatial/src/visualizers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ pub fn process_color_slice<'a>(
) -> Vec<egui::Color32> {
// This can be rather slow for colors with transparency, since we need to pre-multiply the alpha.
re_tracing::profile_function!();
use rayon::prelude::*;

let default_color = DefaultColor::EntityPath(ent_path);

Expand All @@ -146,7 +145,7 @@ pub fn process_color_slice<'a>(
(None, ResolvedAnnotationInfos::Many(annotation_infos)) => {
re_tracing::profile_scope!("no-colors, many annotations");
annotation_infos
.par_iter()
.iter()
.map(|annotation_info| annotation_info.color(None, default_color))
.collect()
}
Expand All @@ -155,16 +154,16 @@ pub fn process_color_slice<'a>(
re_tracing::profile_scope!("many-colors, same annotation");
debug_assert_eq!(colors.len(), *count);
colors
.par_iter()
.iter()
.map(|color| annotation_info.color(color.map(|c| c.to_array()), default_color))
.collect()
}

(Some(colors), ResolvedAnnotationInfos::Many(annotation_infos)) => {
re_tracing::profile_scope!("many-colors, many annotations");
colors
.par_iter()
.zip(annotation_infos.par_iter())
.iter()
.zip(annotation_infos.iter())
.map(move |(color, annotation_info)| {
annotation_info.color(color.map(|c| c.to_array()), default_color)
})
Expand Down Expand Up @@ -209,16 +208,14 @@ pub fn process_radius_slice(
ent_path: &EntityPath,
) -> Vec<re_renderer::Size> {
re_tracing::profile_function!();
use rayon::prelude::*;

let ent_path = ent_path.clone();

match radii {
None => {
vec![re_renderer::Size::AUTO; default_len]
}
Some(radii) => radii
.par_iter()
.iter()
.map(|radius| process_radius(&ent_path, radius))
.collect(),
}
Expand Down

0 comments on commit 4897b93

Please sign in to comment.