perf: refactor to reduce memory allocations and cpu work

This commit is contained in:
Cheong Lau 2025-10-05 16:36:59 +10:00 • committed by Michael Murphy
parent 0c3e3c8629
commit dd0158d8f0
24 changed files with 234 additions and 242 deletions

View file

@ -154,8 +154,7 @@ impl CosmicBatteryApplet {
}
} else {
"off"
}
.to_string();
};
self.display_icon_name =
format!("cosmic-applet-battery-display-brightness-{screen_brightness}-symbolic",);
@ -219,7 +218,7 @@ impl cosmic::Application for CosmicBatteryApplet {
..Default::default()
},
Task::batch(vec![zbus_session_cmd, init_charging_limit_cmd]),
Task::batch([zbus_session_cmd, init_charging_limit_cmd]),
)
}
@ -508,10 +507,10 @@ impl cosmic::Application for CosmicBatteryApplet {
.into();
match self.core.applet.anchor {
PanelAnchor::Left | PanelAnchor::Right => Column::with_children(vec![btn, dot])
PanelAnchor::Left | PanelAnchor::Right => Column::with_children([btn, dot])
.align_x(Alignment::Center)
.into(),
PanelAnchor::Top | PanelAnchor::Bottom => Row::with_children(vec![btn, dot])
PanelAnchor::Top | PanelAnchor::Bottom => Row::with_children([btn, dot])
.align_y(Alignment::Center)
.into(),
}

View file

@ -205,17 +205,17 @@ impl Gpu {
// figure out bus path for calling nvidia-smi
let mut sys_path = PathBuf::from("/sys/class/drm");
sys_path.push(self.path.components().next_back()?.as_os_str());
let buslink = std::fs::read_link(sys_path)
.ok()?
.components()
.rev()
.nth(2)?
.as_os_str()
.to_string_lossy()
.into_owned();
let buslink = std::fs::read_link(sys_path).ok()?;
let buslink = buslink.components().nth_back(2)?.as_os_str();
let smi_output = match tokio::process::Command::new("nvidia-smi")
.args(["pmon", "--id", &buslink, "--count", "1"])
.args([
"pmon".as_ref(),
"--id".as_ref(),
buslink,
"--count".as_ref(),
"1".as_ref(),
])
.output()
.await
{