From d2e080427f47d3104310e878d4c3e7aef7c9a687 Mon Sep 17 00:00:00 2001 From: Cheong Lau <234708519+Cheong-Lau@users.noreply.github.com> Date: Fri, 3 Oct 2025 23:25:51 +1000 Subject: [PATCH] perf: replace `rand` with `fastrand` --- Cargo.lock | 4 ++-- cosmic-app-list/Cargo.toml | 2 +- cosmic-app-list/src/app.rs | 4 +--- cosmic-applet-bluetooth/Cargo.toml | 2 +- cosmic-applet-bluetooth/src/bluetooth.rs | 7 ++----- 5 files changed, 7 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ef50f73b..1d46f8a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1133,6 +1133,7 @@ dependencies = [ "cosmic-app-list-config", "cosmic-client-toolkit", "cosmic-protocols", + "fastrand 2.3.0", "futures", "i18n-embed", "i18n-embed-fl", @@ -1140,7 +1141,6 @@ dependencies = [ "itertools 0.14.0", "libcosmic", "memmap2 0.9.8", - "rand 0.9.2", "rust-embed", "rustix 1.1.2", "switcheroo-control", @@ -1229,11 +1229,11 @@ dependencies = [ "anyhow", "bluer", "cosmic-time", + "fastrand 2.3.0", "futures", "i18n-embed", "i18n-embed-fl", "libcosmic", - "rand 0.9.2", "rust-embed", "tokio", "tracing", diff --git a/cosmic-app-list/Cargo.toml b/cosmic-app-list/Cargo.toml index 24d78f97..ead0dff4 100644 --- a/cosmic-app-list/Cargo.toml +++ b/cosmic-app-list/Cargo.toml @@ -16,7 +16,7 @@ image = { version = "0.25.8", default-features = false } itertools = "0.14.0" libcosmic.workspace = true memmap2 = "0.9.8" -rand = "0.9.2" +fastrand = "2.3.0" rust-embed.workspace = true rustix.workspace = true switcheroo-control = { git = "https://github.com/pop-os/dbus-settings-bindings" } diff --git a/cosmic-app-list/src/app.rs b/cosmic-app-list/src/app.rs index 75ce0a22..0cc66a0e 100755 --- a/cosmic-app-list/src/app.rs +++ b/cosmic-app-list/src/app.rs @@ -54,7 +54,6 @@ use cosmic_protocols::toplevel_info::v1::client::zcosmic_toplevel_handle_v1::Sta use futures::future::pending; use iced::{Alignment, Background, Length}; use itertools::Itertools; -use rand::{Rng, rng}; use std::{borrow::Cow, collections::HashMap, path::PathBuf, rc::Rc, str::FromStr, time::Duration}; use switcheroo_control::Gpu; use tokio::time::sleep; @@ -1084,8 +1083,7 @@ impl cosmic::Application for CosmicAppList { } self.active_list.clear(); let subscription_ctr = self.subscription_ctr; - let mut rng = rng(); - let rand_d = rng.random_range(0..100); + let rand_d = fastrand::u64(0..100); return iced::Task::perform( async move { if let Some(millis) = 2u64 diff --git a/cosmic-applet-bluetooth/Cargo.toml b/cosmic-applet-bluetooth/Cargo.toml index ca127f9f..a7d888f8 100644 --- a/cosmic-applet-bluetooth/Cargo.toml +++ b/cosmic-applet-bluetooth/Cargo.toml @@ -12,7 +12,7 @@ futures.workspace = true i18n-embed-fl.workspace = true i18n-embed.workspace = true libcosmic.workspace = true -rand = "0.9" +fastrand = "2.3.0" rust-embed.workspace = true tokio.workspace = true tracing-log.workspace = true diff --git a/cosmic-applet-bluetooth/src/bluetooth.rs b/cosmic-applet-bluetooth/src/bluetooth.rs index 5cf94b3b..5c7f8c67 100644 --- a/cosmic-applet-bluetooth/src/bluetooth.rs +++ b/cosmic-applet-bluetooth/src/bluetooth.rs @@ -24,7 +24,6 @@ use cosmic::{ }; use futures::{FutureExt, stream::FuturesUnordered}; -use rand::Rng; use tokio::{ spawn, sync::{ @@ -397,8 +396,7 @@ impl BluerSessionState { ), )) .await; - let mut rng = rand::rng(); - let pin_code = rng.random_range(0..999999); + let pin_code = fastrand::u32(0..999999); Ok(format!("{:06}", pin_code)) }) })), @@ -437,8 +435,7 @@ impl BluerSessionState { ), )) .await; - let mut rng = rand::rng(); - let pin_code = rng.random_range(0..999999); + let pin_code = fastrand::u32(0..999999); Ok(pin_code) }) })),