Skip to content

Commit 5369b4e

Browse files
authored
perf: use rustc-hash for HashMap and HashSet
1 parent 4dae457 commit 5369b4e

File tree

17 files changed

+46
-26
lines changed

17 files changed

+46
-26
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ libcosmic = { git = "https://github.com/pop-os/libcosmic", default-features = fa
5454
] }
5555
rust-embed = "8.7.2"
5656
rust-embed-utils = "8.7.2"
57+
rustc-hash = "2.1"
5758
rustix = { version = "1.1", features = ["fs", "process"] }
5859
zbus = { version = "5.11.0", default-features = false, features = ["tokio"] }
5960
tracing = "0.1"

cosmic-app-list/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ memmap2 = "0.9.8"
1919
fastrand = "2.3.0"
2020
rust-embed.workspace = true
2121
rustix.workspace = true
22+
rustc-hash.workspace = true
2223
switcheroo-control = { git = "https://github.com/pop-os/dbus-settings-bindings" }
2324
tokio.workspace = true
2425
tracing-log.workspace = true

cosmic-app-list/src/app.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ use cosmic_app_list_config::{APP_ID, AppListConfig};
5353
use cosmic_protocols::toplevel_info::v1::client::zcosmic_toplevel_handle_v1::State;
5454
use futures::future::pending;
5555
use iced::{Alignment, Background, Length};
56-
use std::{borrow::Cow, collections::HashMap, path::PathBuf, rc::Rc, str::FromStr, time::Duration};
56+
use rustc_hash::FxHashMap;
57+
use std::{borrow::Cow, path::PathBuf, rc::Rc, str::FromStr, time::Duration};
5758
use switcheroo_control::Gpu;
5859
use tokio::time::sleep;
5960
use url::Url;
@@ -327,12 +328,12 @@ struct CosmicAppList {
327328
wayland_sender: Option<Sender<WaylandRequest>>,
328329
seat: Option<WlSeat>,
329330
rectangle_tracker: Option<RectangleTracker<DockItemId>>,
330-
rectangles: HashMap<DockItemId, iced::Rectangle>,
331+
rectangles: FxHashMap<DockItemId, iced::Rectangle>,
331332
dnd_offer: Option<DndOffer>,
332333
is_listening_for_dnd: bool,
333334
gpus: Option<Vec<Gpu>>,
334335
active_workspaces: Vec<ExtWorkspaceHandleV1>,
335-
output_list: HashMap<WlOutput, OutputInfo>,
336+
output_list: FxHashMap<WlOutput, OutputInfo>,
336337
locales: Vec<String>,
337338
overflow_favorites_popup: Option<window::Id>,
338339
overflow_active_popup: Option<window::Id>,

cosmic-applet-battery/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ i18n-embed-fl.workspace = true
1717
i18n-embed.workspace = true
1818
libcosmic.workspace = true
1919
rust-embed.workspace = true
20+
rustc-hash.workspace = true
2021
tokio.workspace = true
2122
tracing-log.workspace = true
2223
tracing-subscriber.workspace = true

cosmic-applet-battery/src/app.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ use cosmic_settings_subscriptions::{
4040
};
4141
use cosmic_time::{Instant, Timeline, anim, chain, id};
4242

43-
use std::{collections::HashMap, path::PathBuf, sync::LazyLock, time::Duration};
43+
use rustc_hash::FxHashMap;
44+
use std::{path::PathBuf, sync::LazyLock, time::Duration};
4445
use tokio::sync::mpsc::UnboundedSender;
4546

4647
// XXX improve
@@ -80,7 +81,7 @@ struct CosmicBatteryApplet {
8081
charging_limit: Option<bool>,
8182
battery_percent: f64,
8283
on_battery: bool,
83-
gpus: HashMap<PathBuf, GPUData>,
84+
gpus: FxHashMap<PathBuf, GPUData>,
8485
update_trigger: Option<UnboundedSender<()>>,
8586
time_remaining: Duration,
8687
max_kbd_brightness: Option<i32>,

cosmic-applet-bluetooth/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ i18n-embed.workspace = true
1414
libcosmic.workspace = true
1515
fastrand = "2.3.0"
1616
rust-embed.workspace = true
17+
rustc-hash.workspace = true
1718
tokio.workspace = true
1819
tracing-log.workspace = true
1920
tracing-subscriber.workspace = true

cosmic-applet-bluetooth/src/bluetooth.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// Copyright 2023 System76 <[email protected]>
22
// SPDX-License-Identifier: GPL-3.0-only
33

4+
use rustc_hash::FxHashMap;
5+
46
use std::{
5-
collections::{HashMap, HashSet},
67
fmt::Debug,
78
hash::Hash,
89
mem,
@@ -357,7 +358,7 @@ pub struct BluerSessionState {
357358
wake_up_discover_tx: Sender<()>,
358359
wake_up_discover_rx: Option<Receiver<()>>,
359360
tx: Sender<BluerSessionEvent>,
360-
active_requests: Arc<Mutex<HashMap<BluerRequest, JoinHandle<anyhow::Result<()>>>>>,
361+
active_requests: Arc<Mutex<FxHashMap<BluerRequest, JoinHandle<anyhow::Result<()>>>>>,
361362
}
362363

363364
impl BluerSessionState {
@@ -540,7 +541,7 @@ impl BluerSessionState {
540541
wake_up_discover_rx: Some(wake_up_discover_rx),
541542
wake_up_discover_tx,
542543
tx,
543-
active_requests: Arc::new(Mutex::new(HashMap::new())),
544+
active_requests: Default::default(),
544545
};
545546
self_.process_requests(req_rx);
546547
self_.process_changes();

cosmic-applet-network/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ libcosmic = { workspace = true, features = [
2121
"desktop",
2222
] }
2323
rust-embed.workspace = true
24+
rustc-hash.workspace = true
2425
tokio.workspace = true
2526
tracing-log.workspace = true
2627
tracing-subscriber.workspace = true

cosmic-applet-network/src/app.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::collections::HashSet;
1+
use rustc_hash::FxHashSet;
22
use std::sync::LazyLock;
33

44
use cosmic::{
@@ -107,7 +107,7 @@ struct CosmicNetworkApplet {
107107
timeline: Timeline,
108108
toggle_wifi_ctr: u128,
109109
token_tx: Option<calloop::channel::Sender<TokenRequest>>,
110-
failed_known_ssids: HashSet<String>,
110+
failed_known_ssids: FxHashSet<String>,
111111
hw_device_to_show: Option<HwAddress>,
112112
}
113113

0 commit comments

Comments
 (0)