Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
Merge pull request #2857 from CapSoftware/perf/gpui-target-thumbnails-capture
Richie McIlroyc9a917a53046
diff --cc apps/desktop-gpui/kernels/src/thumbnail.rsindex c82a93597,63a7322ef..99c9c0a99--- a/apps/desktop-gpui/kernels/src/thumbnail.rs+++ b/apps/desktop-gpui/kernels/src/thumbnail.rs@@@ -62,9 -217,23 +217,25 @@@ fn accumulate_rows_portable(columns: &m// `image::imageops::resize(.., FilterType::Lanczos3)`, so the output is// byte-identical; only the loop order changes, so whole blocks of a row stay in// registers and vectorize instead of one generic `get_pixel` per tap.+// Kept out of line so inlining it doesn't slow `fit_centered`'s no-resize paths.+#[inline(never)]fn resize_lanczos3(image: &RgbaImage, width: u32, height: u32) -> RgbaImage {+ resize_lanczos3_at(+ image,+ width,+ height,+ image.width() as f32 / width as f32,+ image.height() as f32 / height as f32,+ )+ }++ fn resize_lanczos3_at(+ image: &RgbaImage,+ width: u32,+ height: u32,+ ratio_x: f32,+ ratio_y: f32,+ ) -> RgbaImage {let source_row = image.width() as usize * 4;let mut vertical = vec![0f32; source_row * height as usize];vertical_pass(@@@ -74,37 -243,17 +245,37 @@@source_row,);- let columns = lanczos3_taps(image.width(), width);+ let columns = lanczos3_taps_at(image.width(), width, ratio_x);let mut resized = RgbaImage::new(width, height);- for (output, row) in resized- .chunks_exact_mut(width as usize * 4)- .zip(vertical.chunks_exact(source_row))+ let output_row = width as usize * 4;+ let mut outputs = resized.chunks_exact_mut(output_row * HORIZONTAL_ROWS);+ let mut inputs = vertical.chunks_exact(source_row * HORIZONTAL_ROWS);+ for (output, input) in outputs.by_ref().zip(inputs.by_ref()) {+ horizontal_pass::<HORIZONTAL_ROWS>(output, input, &columns);+ }+ for (output, input) in outputs+ .into_remainder()+ .chunks_exact_mut(output_row)+ .zip(inputs.remainder().chunks_exact(source_row)){- for (pixel, taps) in output.chunks_exact_mut(4).zip(&columns) {- let mut sum = [0f32; 4];- for (index, weight) in taps.weights.iter().enumerate() {- let start = (taps.start + index) * 4;- for (channel, &value) in sum.iter_mut().zip(&row[start..start + 4]) {+ horizontal_pass::<1>(output, input, &columns);+ }+ resized+}++// Each pixel's sum is one chain of dependent additions, so ROWS rows that+// share the same taps run side by side to keep the adders busy.+fn horizontal_pass<const ROWS: usize>(output: &mut [u8], input: &[f32], columns: &[Taps]) {+ let output_row = output.len() / ROWS;+ let source_row = input.len() / ROWS;+ let rows: [&[[f32; 4]]; ROWS] =+ std::array::from_fn(|row| input[row * source_row..][..source_row].as_chunks().0);+ for (column, taps) in columns.iter().enumerate() {+ let windows = rows.map(|row| &row[taps.start..taps.start + taps.weights.len()]);+ let mut sums = [[0f32; 4]; ROWS];+ for (index, &weight) in taps.weights.iter().enumerate() {+ for (sum, window) in sums.iter_mut().zip(&windows) {+ for (channel, &value) in sum.iter_mut().zip(&window[index]) {*channel += value * weight;}}