mirror of
https://github.com/arabianq/pipewire-soundpad.git
synced 2026-04-28 06:21:23 +00:00
perf: cache and sort microphone inputs once instead of every frame (#27)
In `draw_footer`, the `all_inputs` HashMap was being collected into a Vec and sorted on every single UI frame (~60 FPS). This caused unnecessary overhead and allocations. This commit introduces a cached `all_inputs_sorted` vector in the `AudioPlayerState` which is populated only when the inputs map changes during the state sync. `draw_footer` now loops over this pre-sorted vector directly. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
968eba80e6
commit
077518019f
+2
-4
@@ -498,9 +498,7 @@ impl SoundpadGui {
|
||||
ui.add_space(5.0);
|
||||
ui.horizontal(|ui| {
|
||||
// ---------- Microphone selection ----------
|
||||
let mut mics: Vec<(&String, &String)> =
|
||||
self.audio_player_state.all_inputs.iter().collect();
|
||||
mics.sort_by_key(|(k, _)| *k);
|
||||
let mics = &self.audio_player_state.all_inputs_sorted;
|
||||
|
||||
let mut selected_input = self.audio_player_state.current_input.to_owned();
|
||||
let prev_input = selected_input.to_owned();
|
||||
@@ -514,7 +512,7 @@ impl SoundpadGui {
|
||||
)
|
||||
.show_ui(ui, |ui| {
|
||||
for (name, nick) in mics {
|
||||
ui.selectable_value(&mut selected_input, name.to_owned(), nick);
|
||||
ui.selectable_value(&mut selected_input, name.clone(), nick);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -55,6 +55,7 @@ pub struct AudioPlayerState {
|
||||
|
||||
pub current_input: String,
|
||||
pub all_inputs: HashMap<String, String>,
|
||||
pub all_inputs_sorted: Vec<(String, String)>,
|
||||
|
||||
pub is_daemon_running: bool,
|
||||
}
|
||||
|
||||
+12
-1
@@ -90,7 +90,18 @@ pub fn start_app_state_thread(audio_player_state_shared: Arc<Mutex<AudioPlayerSt
|
||||
.next()
|
||||
.unwrap_or_default()
|
||||
.to_string();
|
||||
guard.all_inputs = full_state.all_inputs;
|
||||
|
||||
if guard.all_inputs != full_state.all_inputs {
|
||||
guard.all_inputs = full_state.all_inputs;
|
||||
let mut sorted: Vec<(String, String)> = guard
|
||||
.all_inputs
|
||||
.iter()
|
||||
.map(|(k, v)| (k.clone(), v.clone()))
|
||||
.collect();
|
||||
sorted.sort_by(|a, b| a.0.cmp(&b.0));
|
||||
guard.all_inputs_sorted = sorted;
|
||||
}
|
||||
|
||||
guard.is_daemon_running = true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user