App is 100 times slower when NOT using cargo-flamegraph
⚓ Rust 📅 2026-03-04 👤 surdeus 👁️ 3i was running in some serious performance issues with my an app i was developing and tried using cargo-flamegraph to profile it, the thing is if i run it with that it actually runs 100 faster than my release and debug builds at least according to a couple timestamps i took in the code and i do believe the measure is accurate because the output went from visible lag to being very smooth.
here is the function that seems to be most affected 60 milliseconds in release vs 500 microseconds with cargo-flamegraph
pub fn render_ui_objects<S: Screen>(
query: Query<(
&ComputedNode,
&UiGlobalTransform,
Option<&BackgroundColor>,
Option<&TextRenderBuffer>,
Option<&CalculatedClip>,
)>,
stack: Res<UiStack>,
mut screen: NonSendMut<S>,
) {
let start = Instant::now();
let stride = screen.screen_width() as usize;
let stride = screen.screen_height() as usize;
let mut frame = screen.get_frame();
let pixels = frame.deref_mut();
for (i, (computed, transform, color, text_buffer, calculated_clip)) in
query.iter_many(stack.uinodes.iter().copied()).enumerate()
{
let region = Rect::from_center_size(transform.translation, computed.size());
let clipped = if let Some(c_c) = calculated_clip {
let clipped = region.intersect(c_c.clip);
if clipped.is_empty() {
continue;
}
clipped
} else {
region
};
let y_offset = (clipped.min.y - region.min.y) as usize;
let region = Rectangle::from_rect(clipped);
if let Some(color) = color {
let u32_color: U32Color = color.0.to_srgba().into();
for y in region.min_y as usize..region.max_y as usize {
let row_start = y * stride + region.min_x as usize;
let row_end = y * stride + region.max_x as usize;
pixels[row_start..row_end].fill(u32_color);
}
}
if let Some(text) = text_buffer {
if text.pixels.len() == 0 {
continue;
}
let text_stride = text.width;
let text_pixels = &text.pixels;
for y in region.min_y as usize..region.max_y as usize {
for x in region.min_x as usize..region.max_x as usize {
pixels[y * stride + x] = U32Color::blend(
text_pixels[(y - region.min_y as usize + y_offset) * text_stride
+ (x - region.min_x as usize)],
pixels[y * stride + x],
);
}
}
}
}
let time = Instant::now() - start;
println!("render_time:{:?}", time);
}```
2 posts - 2 participants
🏷️ Rust_feed