From 9df40a79bff159ced072214907e68165f4c4795c Mon Sep 17 00:00:00 2001 From: "hinto.janai" Date: Thu, 28 Dec 2023 10:41:42 -0500 Subject: [PATCH] update inlines --- external/egui | 2 +- src/free.rs | 3 +- src/gupax.rs | 19 ++++++++- src/helper.rs | 41 ++++++++++++++++++++ src/human.rs | 53 +++++++++++++------------ src/main.rs | 105 +++++++++++++++++++++++++------------------------- src/node.rs | 6 +++ src/p2pool.rs | 17 +++++++- src/panic.rs | 2 + src/regex.rs | 5 +++ src/status.rs | 19 ++++++++- src/sudo.rs | 10 +++++ src/update.rs | 18 +++++++++ src/xmrig.rs | 14 ++++++- 14 files changed, 225 insertions(+), 89 deletions(-) diff --git a/external/egui b/external/egui index 62b4d42..9cf535b 160000 --- a/external/egui +++ b/external/egui @@ -1 +1 @@ -Subproject commit 62b4d427c01201898914594a9d00d1576bc23432 +Subproject commit 9cf535bd50b2602b0bce45c718d164bae2b4ed77 diff --git a/src/free.rs b/src/free.rs index e0e58a2..2f20b2b 100644 --- a/src/free.rs +++ b/src/free.rs @@ -4,7 +4,8 @@ use crate::constants::*; //---------------------------------------------------------------------------------------------------- -#[inline] +#[cold] +#[inline(never)] // Clamp the scaling resolution `f32` to a known good `f32`. pub fn clamp_scale(scale: f32) -> f32 { // Make sure it is finite. diff --git a/src/gupax.rs b/src/gupax.rs index ea75333..e746b31 100644 --- a/src/gupax.rs +++ b/src/gupax.rs @@ -82,8 +82,21 @@ pub enum Ratio { //---------------------------------------------------------------------------------------------------- Gupax impl crate::disk::Gupax { - #[inline(always)] - pub fn show(&mut self, og: &Arc>, state_path: &Path, update: &Arc>, file_window: &Arc>, error_state: &mut ErrorState, restart: &Arc>, width: f32, height: f32, frame: &mut eframe::Frame, _ctx: &egui::Context, ui: &mut egui::Ui) { + #[inline(always)] // called once + pub fn show( + &mut self, + og: &Arc>, + state_path: &Path, + update: &Arc>, + file_window: &Arc>, + error_state: &mut ErrorState, + restart: &Arc>, + width: f32, + height: f32, + frame: &mut eframe::Frame, + _ctx: &egui::Context, + ui: &mut egui::Ui + ) { // Update button + Progress bar debug!("Gupax Tab | Rendering [Update] button + progress bar"); ui.group(|ui| { @@ -273,6 +286,8 @@ impl crate::disk::Gupax { } } + #[cold] + #[inline(never)] fn spawn_file_window_thread(file_window: &Arc>, file_type: FileType) { use FileType::*; let name = match file_type { diff --git a/src/helper.rs b/src/helper.rs index 4a6b6bc..f8cb68d 100644 --- a/src/helper.rs +++ b/src/helper.rs @@ -177,10 +177,12 @@ impl Process { } // Borrow a [&str], return an owned split collection + #[inline] pub fn parse_args(args: &str) -> Vec { args.split_whitespace().map(|s| s.to_owned()).collect() } + #[inline] // Convenience functions pub fn is_alive(&self) -> bool { self.state == ProcessState::Alive || @@ -189,14 +191,17 @@ impl Process { self.state == ProcessState::NotMining } + #[inline] pub fn is_waiting(&self) -> bool { self.state == ProcessState::Middle || self.state == ProcessState::Waiting } + #[inline] pub fn is_syncing(&self) -> bool { self.state == ProcessState::Syncing } + #[inline] pub fn is_not_mining(&self) -> bool { self.state == ProcessState::NotMining } @@ -268,6 +273,8 @@ impl Helper { } } + #[cold] + #[inline(never)] fn read_pty_xmrig(output_parse: Arc>, output_pub: Arc>, reader: Box) { use std::io::BufRead; let mut stdout = std::io::BufReader::new(reader).lines(); @@ -293,6 +300,8 @@ impl Helper { } } + #[cold] + #[inline(never)] fn read_pty_p2pool(output_parse: Arc>, output_pub: Arc>, reader: Box, gupax_p2pool_api: Arc>) { use std::io::BufRead; let mut stdout = std::io::BufReader::new(reader).lines(); @@ -349,6 +358,8 @@ impl Helper { } //---------------------------------------------------------------------------------------------------- P2Pool specific + #[cold] + #[inline(never)] // Just sets some signals for the watchdog thread to pick up on. pub fn stop_p2pool(helper: &Arc>) { info!("P2Pool | Attempting to stop..."); @@ -356,6 +367,8 @@ impl Helper { lock2!(helper,p2pool).state = ProcessState::Middle; } + #[cold] + #[inline(never)] // The "restart frontend" to a "frontend" function. // Basically calls to kill the current p2pool, waits a little, then starts the below function in a a new thread, then exit. pub fn restart_p2pool(helper: &Arc>, state: &crate::disk::P2pool, path: &std::path::PathBuf, backup_hosts: Option>) { @@ -379,6 +392,8 @@ impl Helper { info!("P2Pool | Restart ... OK"); } + #[cold] + #[inline(never)] // The "frontend" function that parses the arguments, and spawns either the [Simple] or [Advanced] P2Pool watchdog thread. pub fn start_p2pool( helper: &Arc>, @@ -419,6 +434,8 @@ impl Helper { head.to_owned() + "..." + tail } + #[cold] + #[inline(never)] // Takes in some [State/P2pool] and parses it to build the actual command arguments. // Returns the [Vec] of actual arguments, and mutates the [ImgP2pool] for the main GUI thread // It returns a value... and mutates a deeply nested passed argument... this is some pretty bad code... @@ -543,6 +560,8 @@ impl Helper { (args, api_path_local, api_path_network, api_path_pool) } + #[cold] + #[inline(never)] // The P2Pool watchdog. Spawns 1 OS thread for reading a PTY (STDOUT+STDERR), and combines the [Child] with a PTY so STDIN actually works. fn spawn_p2pool_watchdog(process: Arc>, gui_api: Arc>, pub_api: Arc>, args: Vec, path: std::path::PathBuf, api_path_local: std::path::PathBuf, api_path_network: std::path::PathBuf, api_path_pool: std::path::PathBuf, gupax_p2pool_api: Arc>) { // 1a. Create PTY @@ -772,6 +791,8 @@ impl Helper { } //---------------------------------------------------------------------------------------------------- XMRig specific, most functions are very similar to P2Pool's + #[cold] + #[inline(never)] // If processes are started with [sudo] on macOS, they must also // be killed with [sudo] (even if I have a direct handle to it as the // parent process...!). This is only needed on macOS, not Linux. @@ -791,6 +812,8 @@ impl Helper { child.wait().unwrap().success() } + #[cold] + #[inline(never)] // Just sets some signals for the watchdog thread to pick up on. pub fn stop_xmrig(helper: &Arc>) { info!("XMRig | Attempting to stop..."); @@ -798,6 +821,8 @@ impl Helper { lock2!(helper,xmrig).state = ProcessState::Middle; } + #[cold] + #[inline(never)] // The "restart frontend" to a "frontend" function. // Basically calls to kill the current xmrig, waits a little, then starts the below function in a a new thread, then exit. pub fn restart_xmrig(helper: &Arc>, state: &crate::disk::Xmrig, path: &std::path::PathBuf, sudo: Arc>) { @@ -821,6 +846,8 @@ impl Helper { info!("XMRig | Restart ... OK"); } + #[cold] + #[inline(never)] pub fn start_xmrig(helper: &Arc>, state: &crate::disk::Xmrig, path: &std::path::PathBuf, sudo: Arc>) { lock2!(helper,xmrig).state = ProcessState::Middle; @@ -840,6 +867,8 @@ impl Helper { }); } + #[cold] + #[inline(never)] // Takes in some [State/Xmrig] and parses it to build the actual command arguments. // Returns the [Vec] of actual arguments, and mutates the [ImgXmrig] for the main GUI thread // It returns a value... and mutates a deeply nested passed argument... this is some pretty bad code... @@ -940,6 +969,8 @@ impl Helper { cmd } + #[cold] + #[inline(never)] // The XMRig watchdog. Spawns 1 OS thread for reading a PTY (STDOUT+STDERR), and combines the [Child] with a PTY so STDIN actually works. // This isn't actually async, a tokio runtime is unfortunately needed because [Hyper] is an async library (HTTP API calls) #[tokio::main] @@ -1151,6 +1182,7 @@ impl Helper { } //---------------------------------------------------------------------------------------------------- The "helper" + #[inline(always)] // called once fn update_pub_sys_from_sysinfo(sysinfo: &sysinfo::System, pub_sys: &mut Sys, pid: &sysinfo::Pid, helper: &Helper, max_threads: usize) { let gupax_uptime = helper.uptime.to_string(); let cpu = &sysinfo.cpus()[0]; @@ -1180,6 +1212,8 @@ impl Helper { }; } + #[cold] + #[inline(never)] // The "helper" thread. Syncs data between threads here and the GUI. pub fn spawn_helper(helper: &Arc>, mut sysinfo: sysinfo::System, pid: sysinfo::Pid, max_threads: usize) { // The ordering of these locks is _very_ important. They MUST be in sync with how the main GUI thread locks stuff @@ -1428,6 +1462,7 @@ impl PubP2poolApi { } } + #[inline] // The issue with just doing [gui_api = pub_api] is that values get overwritten. // This doesn't matter for any of the values EXCEPT for the output, so we must // manually append it instead of overwriting. @@ -1443,6 +1478,7 @@ impl PubP2poolApi { }; } + #[inline] // Essentially greps the output for [x.xxxxxxxxxxxx XMR] where x = a number. // It sums each match and counts along the way, handling an error by not adding and printing to console. fn calc_payouts_and_xmr(output: &str) -> (u128 /* payout count */, f64 /* total xmr */) { @@ -1607,6 +1643,7 @@ impl PubP2poolApi { }; } + #[inline] pub fn calculate_share_or_block_time(hashrate: u64, difficulty: u64) -> HumanTime { if hashrate == 0 { HumanTime::new() @@ -1615,6 +1652,7 @@ impl PubP2poolApi { } } + #[inline] pub fn calculate_dominance(my_hashrate: u64, global_hashrate: u64) -> HumanNumber { if global_hashrate == 0 { HumanNumber::unknown() @@ -1854,6 +1892,7 @@ impl PubXmrigApi { } } + #[inline] fn combine_gui_pub_api(gui_api: &mut Self, pub_api: &mut Self) { let output = std::mem::take(&mut gui_api.output); let buf = std::mem::take(&mut pub_api.output); @@ -1938,6 +1977,8 @@ impl PrivXmrigApi { hashrate: Hashrate::new(), } } + + #[inline] // Send an HTTP request to XMRig's API, serialize it into [Self] and return it async fn request_xmrig_api(client: hyper::Client, api_uri: &str) -> std::result::Result { let request = hyper::Request::builder() diff --git a/src/human.rs b/src/human.rs index ab39611..118b6e2 100644 --- a/src/human.rs +++ b/src/human.rs @@ -36,22 +36,21 @@ impl Default for HumanTime { } impl HumanTime { - #[inline(always)] + #[inline] pub const fn new() -> HumanTime { HumanTime(ZERO_SECONDS) } - #[inline(always)] + #[inline] pub const fn into_human(d: Duration) -> HumanTime { HumanTime(d) } - #[inline(always)] + #[inline] pub const fn from_u64(u: u64) -> HumanTime { HumanTime(Duration::from_secs(u)) } - #[inline(always)] fn plural(f: &mut std::fmt::Formatter, started: &mut bool, name: &str, value: u64) -> std::fmt::Result { if value > 0 { if *started { @@ -114,19 +113,19 @@ impl std::fmt::Display for HumanNumber { } impl HumanNumber { - #[inline(always)] + #[inline] pub fn unknown() -> Self { Self("???".to_string()) } - #[inline(always)] + #[inline] pub fn from_str(s: &str) -> Self { Self(s.to_string()) } - #[inline(always)] + #[inline] pub fn to_hashrate(f: f32) -> Self { Self(format!("{} H/s", Self::from_f32(f))) } - #[inline(always)] + #[inline] pub fn to_percent(f: f32) -> Self { if f < 0.01 { Self("0%".to_string()) @@ -134,67 +133,67 @@ impl HumanNumber { Self(format!("{:.2}%", f)) } } - #[inline(always)] + #[inline] pub fn to_percent_3_point(f: f32) -> Self { Self(format!("{:.3}%", f)) } - #[inline(always)] + #[inline] pub fn to_percent_no_fmt(f: f32) -> Self { Self(format!("{}%", f)) } - #[inline(always)] + #[inline] pub fn from_f64_to_percent_3_point(f: f64) -> Self { Self(format!("{:.3}%", f)) } - #[inline(always)] + #[inline] pub fn from_f64_to_percent_6_point(f: f64) -> Self { Self(format!("{:.6}%", f)) } - #[inline(always)] + #[inline] pub fn from_f64_to_percent_9_point(f: f64) -> Self { Self(format!("{:.9}%", f)) } - #[inline(always)] + #[inline] pub fn from_f64_to_percent_no_fmt(f: f64) -> Self { Self(format!("{}%", f)) } - #[inline(always)] + #[inline] pub fn from_f32(f: f32) -> Self { let mut buf = num_format::Buffer::new(); buf.write_formatted(&(f as u64), &LOCALE); Self(buf.as_str().to_string()) } - #[inline(always)] + #[inline] pub fn from_f64(f: f64) -> Self { let mut buf = num_format::Buffer::new(); buf.write_formatted(&(f as u128), &LOCALE); Self(buf.as_str().to_string()) } - #[inline(always)] + #[inline] pub fn from_u16(u: u16) -> Self { let mut buf = num_format::Buffer::new(); buf.write_formatted(&u, &LOCALE); Self(buf.as_str().to_string()) } - #[inline(always)] + #[inline] pub fn from_u32(u: u32) -> Self { let mut buf = num_format::Buffer::new(); buf.write_formatted(&u, &LOCALE); Self(buf.as_str().to_string()) } - #[inline(always)] + #[inline] pub fn from_u64(u: u64) -> Self { let mut buf = num_format::Buffer::new(); buf.write_formatted(&u, &LOCALE); Self(buf.as_str().to_string()) } - #[inline(always)] + #[inline] pub fn from_u128(u: u128) -> Self { let mut buf = num_format::Buffer::new(); buf.write_formatted(&u, &LOCALE); Self(buf.as_str().to_string()) } - #[inline(always)] + #[inline] pub fn from_hashrate(array: [Option; 3]) -> Self { let mut string = "[".to_string(); let mut buf = num_format::Buffer::new(); @@ -221,7 +220,7 @@ impl HumanNumber { Self(string) } - #[inline(always)] + #[inline] pub fn from_load(array: [Option; 3]) -> Self { let mut string = "[".to_string(); let mut n = 0; @@ -241,30 +240,30 @@ impl HumanNumber { Self(string) } // [1_000_000] -> [1.000 MH/s] - #[inline(always)] + #[inline] pub fn from_u64_to_megahash_3_point(hash: u64) -> Self { let hash = (hash as f64)/1_000_000.0; let hash = format!("{:.3} MH/s", hash); Self(hash) } // [1_000_000_000] -> [1.000 GH/s] - #[inline(always)] + #[inline] pub fn from_u64_to_gigahash_3_point(hash: u64) -> Self { let hash = (hash as f64)/1_000_000_000.0; let hash = format!("{:.3} GH/s", hash); Self(hash) } - #[inline(always)] + #[inline] pub fn from_f64_12_point(f: f64) -> Self { let f = format!("{:.12}", f); Self(f) } - #[inline(always)] + #[inline] pub fn from_f64_no_fmt(f: f64) -> Self { let f = format!("{}", f); Self(f) } - #[inline(always)] + #[inline] pub fn as_str(&self) -> &str { self.0.as_str() } diff --git a/src/main.rs b/src/main.rs index 2a7a1da..1b8c200 100644 --- a/src/main.rs +++ b/src/main.rs @@ -174,6 +174,8 @@ pub struct App { } impl App { + #[cold] + #[inline(never)] fn cc(cc: &eframe::CreationContext<'_>, app: Self) -> Self { let resolution = cc.integration_info.window_info.size; init_text_styles(&cc.egui_ctx, resolution[0], crate::free::clamp_scale(app.state.gupax.selected_scale)); @@ -184,12 +186,16 @@ impl App { } } + #[cold] + #[inline(never)] fn save_before_quit(&mut self) { if let Err(e) = State::save(&mut self.state, &self.state_path) { error!("State file: {}", e); } if let Err(e) = Node::save(&self.node_vec, &self.node_path) { error!("Node list: {}", e); } if let Err(e) = Pool::save(&self.pool_vec, &self.pool_path) { error!("Pool list: {}", e); } } + #[cold] + #[inline(never)] fn new(now: Instant) -> Self { info!("Initializing App Struct..."); info!("App Init | P2Pool & XMRig processes..."); @@ -533,6 +539,8 @@ impl App { app } + #[cold] + #[inline(never)] pub fn gather_backup_hosts(&self) -> Option> { if !self.state.p2pool.backup_host { return None; @@ -733,6 +741,8 @@ struct Images { } impl Images { + #[cold] + #[inline(never)] fn new() -> Self { Self { banner: RetainedImage::from_image_bytes("banner.png", BYTES_BANNER).unwrap(), @@ -771,46 +781,23 @@ enum KeyPressed { } impl KeyPressed { - fn is_f11(&self) -> bool { - *self == Self::F11 - } - fn is_z(&self) -> bool { - *self == Self::Z - } - fn is_x(&self) -> bool { - *self == Self::X - } - fn is_up(&self) -> bool { - *self == Self::Up - } - fn is_down(&self) -> bool { - *self == Self::Down - } - fn is_esc(&self) -> bool { - *self == Self::Esc - } - fn is_s(&self) -> bool { - *self == Self::S - } - fn is_r(&self) -> bool { - *self == Self::R - } - fn is_d(&self) -> bool { - *self == Self::D - } - fn is_c(&self) -> bool { - *self == Self::C - } - fn is_v(&self) -> bool { - *self == Self::V - } - fn is_none(&self) -> bool { - *self == Self::None - } + #[inline] fn is_f11(&self) -> bool { *self == Self::F11 } + #[inline] fn is_z(&self) -> bool { *self == Self::Z } + #[inline] fn is_x(&self) -> bool { *self == Self::X } + #[inline] fn is_up(&self) -> bool { *self == Self::Up } + #[inline] fn is_down(&self) -> bool { *self == Self::Down } + #[inline] fn is_esc(&self) -> bool { *self == Self::Esc } + #[inline] fn is_s(&self) -> bool { *self == Self::S } + #[inline] fn is_r(&self) -> bool { *self == Self::R } + #[inline] fn is_d(&self) -> bool { *self == Self::D } + #[inline] fn is_c(&self) -> bool { *self == Self::C } + #[inline] fn is_v(&self) -> bool { *self == Self::V } + #[inline] fn is_none(&self) -> bool { *self == Self::None } } //---------------------------------------------------------------------------------------------------- Init functions -#[inline(always)] +#[cold] +#[inline(never)] fn init_text_styles(ctx: &egui::Context, width: f32, pixels_per_point: f32) { let scale = width / 30.0; let mut style = (*ctx.style()).clone(); @@ -836,7 +823,8 @@ fn init_text_styles(ctx: &egui::Context, width: f32, pixels_per_point: f32) { ctx.request_repaint(); } -#[inline(always)] +#[cold] +#[inline(never)] fn init_logger(now: Instant) { use env_logger::fmt::Color; let filter_env = std::env::var("RUST_LOG").unwrap_or_else(|_| "INFO".to_string()); @@ -872,7 +860,8 @@ fn init_logger(now: Instant) { info!("Log level ... {}", filter); } -#[inline(always)] +#[cold] +#[inline(never)] fn init_options(initial_window_size: Option) -> NativeOptions { let mut options = eframe::NativeOptions::default(); options.min_window_size = Some(Vec2::new(APP_MIN_WIDTH, APP_MIN_HEIGHT)); @@ -891,7 +880,8 @@ fn init_options(initial_window_size: Option) -> NativeOptions { options } -#[inline(always)] +#[cold] +#[inline(never)] fn init_auto(app: &mut App) { // Return early if [--no-startup] was not passed if app.no_startup { @@ -953,6 +943,8 @@ fn init_auto(app: &mut App) { } //---------------------------------------------------------------------------------------------------- Reset functions +#[cold] +#[inline(never)] fn reset_state(path: &PathBuf) -> Result<(), TomlError> { match State::create_new(path) { Ok(_) => { info!("Resetting [state.toml] ... OK"); Ok(()) }, @@ -960,7 +952,8 @@ fn reset_state(path: &PathBuf) -> Result<(), TomlError> { } } -#[inline(always)] +#[cold] +#[inline(never)] fn reset_nodes(path: &PathBuf) -> Result<(), TomlError> { match Node::create_new(path) { Ok(_) => { info!("Resetting [node.toml] ... OK"); Ok(()) }, @@ -968,7 +961,8 @@ fn reset_nodes(path: &PathBuf) -> Result<(), TomlError> { } } -#[inline(always)] +#[cold] +#[inline(never)] fn reset_pools(path: &PathBuf) -> Result<(), TomlError> { match Pool::create_new(path) { Ok(_) => { info!("Resetting [pool.toml] ... OK"); Ok(()) }, @@ -976,7 +970,8 @@ fn reset_pools(path: &PathBuf) -> Result<(), TomlError> { } } -#[inline(always)] +#[cold] +#[inline(never)] fn reset_gupax_p2pool_api(path: &PathBuf) -> Result<(), TomlError> { match GupaxP2poolApi::create_new(path) { Ok(_) => { info!("Resetting GupaxP2poolApi ... OK"); Ok(()) }, @@ -984,7 +979,8 @@ fn reset_gupax_p2pool_api(path: &PathBuf) -> Result<(), TomlError> { } } -#[inline(always)] +#[cold] +#[inline(never)] fn reset(path: &PathBuf, state: &PathBuf, node: &PathBuf, pool: &PathBuf, gupax_p2pool_api: &PathBuf) { let mut code = 0; // Attempt to remove directory first @@ -1021,7 +1017,8 @@ fn reset(path: &PathBuf, state: &PathBuf, node: &PathBuf, pool: &PathBuf, gupax_ } //---------------------------------------------------------------------------------------------------- Misc functions -#[inline(always)] +#[cold] +#[inline(never)] fn parse_args>(mut app: App, panic: S) -> App { info!("Parsing CLI arguments..."); let mut args: Vec = env::args().collect(); @@ -1064,7 +1061,8 @@ fn parse_args>(mut app: App, panic: S) -> App { } // Get absolute [Gupax] binary path -#[inline(always)] +#[cold] +#[inline(never)] pub fn get_exe() -> Result { match std::env::current_exe() { Ok(path) => { Ok(path.display().to_string()) }, @@ -1073,7 +1071,8 @@ pub fn get_exe() -> Result { } // Get absolute [Gupax] directory path -#[inline(always)] +#[cold] +#[inline(never)] pub fn get_exe_dir() -> Result { match std::env::current_exe() { Ok(mut path) => { path.pop(); Ok(path.display().to_string()) }, @@ -1083,7 +1082,8 @@ pub fn get_exe_dir() -> Result { // Clean any [gupax_update_.*] directories // The trailing random bits must be exactly 10 alphanumeric characters -#[inline(always)] +#[cold] +#[inline(never)] pub fn clean_dir() -> Result<(), anyhow::Error> { let regex = Regex::new("^gupax_update_[A-Za-z0-9]{10}$").unwrap(); for entry in std::fs::read_dir(get_exe_dir()?)? { @@ -1101,7 +1101,8 @@ pub fn clean_dir() -> Result<(), anyhow::Error> { } // Print disk files to console -#[inline(always)] +#[cold] +#[inline(never)] fn print_disk_file(path: &PathBuf) { match std::fs::read_to_string(path) { Ok(string) => { print!("{}", string); exit(0); }, @@ -1110,7 +1111,8 @@ fn print_disk_file(path: &PathBuf) { } // Prints the GupaxP2PoolApi files. -#[inline(always)] +#[cold] +#[inline(never)] fn print_gupax_p2pool_api(gupax_p2pool_api: &Arc>) { let api = lock!(gupax_p2pool_api); let log = match std::fs::read_to_string(&api.path_log) { @@ -1133,7 +1135,7 @@ fn print_gupax_p2pool_api(gupax_p2pool_api: &Arc>) { exit(0); } -#[inline(always)] +#[inline] fn cmp_f64(a: f64, b: f64) -> std::cmp::Ordering { match (a <= b, a >= b) { (false, true) => std::cmp::Ordering::Greater, @@ -1198,7 +1200,6 @@ impl eframe::App for App { } } - #[inline(always)] fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) { // *-------* // | DEBUG | diff --git a/src/node.rs b/src/node.rs index bd95bb8..8cc59d3 100644 --- a/src/node.rs +++ b/src/node.rs @@ -291,6 +291,8 @@ impl Ping { } //---------------------------------------------------------------------------------------------------- Main Ping function + #[cold] + #[inline(never)] // Intermediate function for spawning thread pub fn spawn_thread(ping: &Arc>) { info!("Spawning ping thread..."); @@ -333,6 +335,8 @@ impl Ping { // >500ms = RED // timeout = BLACK // default = GRAY + #[cold] + #[inline(never)] #[tokio::main] pub async fn ping(ping: &Arc>) -> Result { // Start ping @@ -384,6 +388,8 @@ impl Ping { Ok(fastest_info) } + #[cold] + #[inline(never)] async fn response( client: Client, request: Request, diff --git a/src/p2pool.rs b/src/p2pool.rs index 49c08df..848e74b 100644 --- a/src/p2pool.rs +++ b/src/p2pool.rs @@ -36,8 +36,21 @@ use crate::regex::{ }; impl crate::disk::P2pool { - #[inline(always)] - pub fn show(&mut self, node_vec: &mut Vec<(String, Node)>, _og: &Arc>, ping: &Arc>, process: &Arc>, api: &Arc>, buffer: &mut String, width: f32, height: f32, _ctx: &egui::Context, ui: &mut egui::Ui) { +#[inline(always)] // called once +pub fn show( + &mut self, + node_vec: &mut Vec<(String, + Node)>, + _og: &Arc>, + ping: &Arc>, + process: &Arc>, + api: &Arc>, + buffer: &mut String, + width: f32, + height: f32, + _ctx: &egui::Context, + ui: &mut egui::Ui +) { let text_edit = height / 25.0; //---------------------------------------------------------------------------------------------------- [Simple] Console debug!("P2Pool Tab | Rendering [Console]"); diff --git a/src/panic.rs b/src/panic.rs index 6a6dfce..30f4dcd 100644 --- a/src/panic.rs +++ b/src/panic.rs @@ -8,6 +8,8 @@ use crate::constants::{ }; //---------------------------------------------------------------------------------------------------- +#[cold] +#[inline(never)] /// Set custom panic hook. pub(crate) fn set_panic_hook(now: std::time::Instant) { std::panic::set_hook(Box::new(move |panic_info| { diff --git a/src/regex.rs b/src/regex.rs index 7866a17..85b3fbf 100644 --- a/src/regex.rs +++ b/src/regex.rs @@ -37,6 +37,8 @@ pub struct Regexes { } impl Regexes { + #[cold] + #[inline(never)] fn new() -> Self { Self { name: Regex::new("^[A-Za-z0-9-_.]+( [A-Za-z0-9-_.]+)*$").unwrap(), @@ -47,6 +49,7 @@ impl Regexes { } } + #[inline] // Check if a Monero address is correct. // This actually only checks for length & Base58, and doesn't do any checksum validation // (the last few bytes of a Monero address are a Keccak hash checksum) so some invalid addresses can trick this function. @@ -85,6 +88,8 @@ pub struct P2poolRegex { } impl P2poolRegex { + #[cold] + #[inline(never)] fn new() -> Self { Self { date: Regex::new("[0-9]+-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+.[0-9]+").unwrap(), diff --git a/src/status.rs b/src/status.rs index 9dcc3f1..76e9065 100644 --- a/src/status.rs +++ b/src/status.rs @@ -42,8 +42,23 @@ use egui::{ }; impl crate::disk::Status { -#[inline(always)] -pub fn show(&mut self, sys: &Arc>, p2pool_api: &Arc>, xmrig_api: &Arc>, p2pool_img: &Arc>, xmrig_img: &Arc>, p2pool_alive: bool, xmrig_alive: bool, max_threads: usize, gupax_p2pool_api: &Arc>, benchmarks: &[Benchmark], width: f32, height: f32, _ctx: &egui::Context, ui: &mut egui::Ui) { +#[inline(always)] // called once +pub fn show(&mut self, + sys: &Arc>, + p2pool_api: &Arc>, + xmrig_api: &Arc>, + p2pool_img: &Arc>, + xmrig_img: &Arc>, + p2pool_alive: bool, + xmrig_alive: bool, + max_threads: usize, + gupax_p2pool_api: &Arc>, + benchmarks: &[Benchmark], + width: f32, + height: f32, + _ctx: &egui::Context, + ui: &mut egui::Ui +) { //---------------------------------------------------------------------------------------------------- [Processes] if self.submenu == Submenu::Processes { let width = (width/3.0)-(SPACE*1.666); diff --git a/src/sudo.rs b/src/sudo.rs index a2b9a7b..42eaef9 100644 --- a/src/sudo.rs +++ b/src/sudo.rs @@ -54,6 +54,8 @@ impl Default for SudoState { } impl SudoState { + #[cold] + #[inline(never)] #[cfg(target_os = "windows")] pub fn new() -> Self { Self { @@ -66,6 +68,8 @@ impl SudoState { signal: ProcessSignal::None, } } + #[cold] + #[inline(never)] #[cfg(target_family = "unix")] pub fn new() -> Self { Self { @@ -79,6 +83,8 @@ impl SudoState { } } + #[cold] + #[inline(never)] // Resets the state. pub fn reset(state: &Arc>) { Self::wipe(state); @@ -88,6 +94,8 @@ impl SudoState { // state.signal = ProcessSignal::None; } + #[cold] + #[inline(never)] // Swaps the pass with another 256-capacity String, // zeroizes the old and drops it. pub fn wipe(state: &Arc>) { @@ -100,6 +108,8 @@ impl SudoState { info!("Sudo | Password wipe with 0's ... OK"); } + #[cold] + #[inline(never)] // Spawns a thread and tests sudo with the provided password. // Sudo takes the password through STDIN via [--stdin]. // Sets the appropriate state fields on success/failure. diff --git a/src/update.rs b/src/update.rs index 7c10f32..147f539 100644 --- a/src/update.rs +++ b/src/update.rs @@ -286,6 +286,8 @@ impl Update { Ok(tmp_dir) } + #[cold] + #[inline(never)] // Get an HTTPS client. Uses [Arti] if Tor is enabled. // The base type looks something like [hyper::Client<...>]. // This is then wrapped with the custom [ClientEnum] type to implement @@ -319,6 +321,8 @@ impl Update { } } + #[cold] + #[inline(never)] // Intermediate function that spawns a new thread // which starts the async [start()] function that // actually contains the code. This is so that everytime @@ -422,6 +426,8 @@ impl Update { }); } + #[cold] + #[inline(never)] // Download process: // 0. setup tor, client, http, etc // 1. fill vector with all enums @@ -791,6 +797,8 @@ pub struct Pkg { } impl Pkg { + #[cold] + #[inline(never)] pub fn new(name: Name) -> Self { let link_metadata = match name { Gupax => GUPAX_METADATA, @@ -824,6 +832,8 @@ impl Pkg { } //---------------------------------------------------------------------------------------------------- Pkg functions + #[cold] + #[inline(never)] // Generate fake [User-Agent] HTTP header pub fn get_user_agent() -> &'static str { let index = FAKE_USER_AGENT.len() - 1; @@ -834,6 +844,8 @@ impl Pkg { user_agent } + #[cold] + #[inline(never)] // Generate GET request based off input URI + fake user agent fn get_request(link: String, user_agent: &'static str) -> Result, anyhow::Error> { let request = Request::builder() @@ -844,6 +856,8 @@ impl Pkg { Ok(request) } + #[cold] + #[inline(never)] // Get metadata using [Generic hyper::client] & [Request] // and change [version, prog] under an Arc async fn get_metadata(new_ver: Arc>, client: Client, link: String, user_agent: &'static str) -> Result<(), Error> @@ -856,6 +870,8 @@ impl Pkg { Ok(()) } + #[cold] + #[inline(never)] // Takes a [Request], fills the appropriate [Pkg] // [bytes] field with the [Archive/Standalone] async fn get_bytes(bytes: Arc>, client: Client, link: String, user_agent: &'static str) -> Result<(), anyhow::Error> @@ -874,6 +890,8 @@ impl Pkg { Ok(()) } + #[cold] + #[inline(never)] // Take in a [Name] and [Vec] of [Pkg]s, find // that [Name]'s corresponding new version. fn get_new_pkg_version(name: Name, vec: &[&Pkg]) -> Result { diff --git a/src/xmrig.rs b/src/xmrig.rs index 74e5103..3df5fba 100644 --- a/src/xmrig.rs +++ b/src/xmrig.rs @@ -37,8 +37,18 @@ use crate::regex::{ }; impl crate::disk::Xmrig { - #[inline(always)] - pub fn show(&mut self, pool_vec: &mut Vec<(String, Pool)>, process: &Arc>, api: &Arc>, buffer: &mut String, width: f32, height: f32, _ctx: &egui::Context, ui: &mut egui::Ui) { +#[inline(always)] // called once +pub fn show( + &mut self, + pool_vec: &mut Vec<(String, Pool)>, + process: &Arc>, + api: &Arc>, + buffer: &mut String, + width: f32, + height: f32, + _ctx: &egui::Context, + ui: &mut egui::Ui +) { let text_edit = height / 25.0; //---------------------------------------------------------------------------------------------------- [Simple] Console debug!("XMRig Tab | Rendering [Console]");