From 6c0be6913dd0bcbb7e17a3e2a4daa45fcc8f5103 Mon Sep 17 00:00:00 2001 From: mat Date: Fri, 30 Jan 2026 00:02:36 +0500 Subject: warn if pathfinder is running without optimizations, and other minor fixes --- azalea/build.rs | 11 +++++++++++ azalea/src/pathfinder/mod.rs | 12 +++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'azalea') diff --git a/azalea/build.rs b/azalea/build.rs index faed1365..9dd6b738 100644 --- a/azalea/build.rs +++ b/azalea/build.rs @@ -1,6 +1,17 @@ use std::{env, process::Command}; fn main() { + check_nightly(); + + // save the optimization level, used by the pathfinder to warn if optimizations + // are off + println!( + "cargo::rustc-env=OPT_LEVEL={}", + env::var("OPT_LEVEL").unwrap() + ); +} + +fn check_nightly() { // If using `rustup`, check the toolchain via `RUSTUP_TOOLCHAIN` if let Ok(toolchain) = env::var("RUSTUP_TOOLCHAIN") { if toolchain.contains("nightly") { diff --git a/azalea/src/pathfinder/mod.rs b/azalea/src/pathfinder/mod.rs index 8df04b14..6f1a0d8a 100644 --- a/azalea/src/pathfinder/mod.rs +++ b/azalea/src/pathfinder/mod.rs @@ -32,7 +32,7 @@ use std::{ collections::VecDeque, sync::{ Arc, - atomic::{self, AtomicUsize}, + atomic::{self, AtomicBool, AtomicUsize}, }, thread, time::{Duration, Instant}, @@ -306,6 +306,16 @@ pub fn goto_listener( continue; }; + // this env variable is set from the build.rs + if env!("OPT_LEVEL") == "0" { + static WARNED: AtomicBool = AtomicBool::new(false); + if !WARNED.swap(true, atomic::Ordering::Relaxed) { + warn!( + "Azalea was compiled with no optimizations, which may result in significantly reduced pathfinding performance. Consider following the steps at https://azalea.matdoes.dev/azalea/#optimization for faster performance in debug mode." + ) + } + } + let cur_pos = player_pos_to_block_pos(**position); if event.goal.success(cur_pos) { -- cgit v1.2.3