Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: skip reading backend-meta files if they do not exist #2941

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ path = "src/main.rs"
inherits = "release"
lto = true

[profile.dev.package.backtrace]
opt-level = 3

[dependencies]
base64 = "0.22"
calm_io = "0.1"
Expand Down
1 change: 1 addition & 0 deletions e2e/run_test
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ within_isolated_env() {
MISE_LOG_LEVEL="${MISE_LOG_LEVEL:-}" \
MISE_STATE_DIR="$MISE_STATE_DIR" \
MISE_SYSTEM_DIR="$MISE_SYSTEM_DIR" \
MISE_TIMINGS="${MISE_TIMINGS:-0}" \
MISE_TMP_DIR="$TEST_TMPDIR" \
MISE_TRACE="${MISE_TRACE:-0}" \
MISE_TRUSTED_CONFIG_PATHS="$TEST_ISOLATED_DIR" \
Expand Down
9 changes: 7 additions & 2 deletions src/backend/backend_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ pub const FORGE_META_FILENAME: &str = ".mise.backend.json";
impl BackendMeta {
pub fn read(dirname: &str) -> BackendMeta {
let meta_path = &dirs::INSTALLS.join(dirname).join(FORGE_META_FILENAME);
let json = file::read_to_string(meta_path).unwrap_or_default();
serde_json::from_str(&json).unwrap_or(Self::default_meta(dirname))
if meta_path.exists() {
let json = file::read_to_string(meta_path).unwrap_or_default();
if let Ok(meta) = serde_json::from_str(&json) {
return meta;
}
}
Self::default_meta(dirname)
}

pub fn write(fa: &BackendArg) -> eyre::Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub static MISE_BIN: Lazy<PathBuf> = Lazy::new(|| {
.unwrap_or_else(|| "mise".into())
});
#[cfg(feature = "timings")]
pub static MISE_TIMINGS: Lazy<bool> = Lazy::new(|| var_is_true("MISE_TIMINGS"));
pub static MISE_TIMINGS: Lazy<Option<String>> = Lazy::new(|| var("MISE_TIMINGS").ok());
pub static MISE_PID: Lazy<String> = Lazy::new(|| process::id().to_string());
pub static __MISE_SCRIPT: Lazy<bool> = Lazy::new(|| var_is_true("__MISE_SCRIPT"));
pub static __MISE_DIFF: Lazy<EnvDiff> = Lazy::new(get_env_diff);
Expand Down
17 changes: 13 additions & 4 deletions src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,24 @@ macro_rules! info {

#[cfg(feature = "timings")]
pub fn get_time_diff(module: &str) -> String {
static START: std::sync::Mutex<Option<std::time::Instant>> = std::sync::Mutex::new(None);
static PREV: std::sync::Mutex<Option<std::time::Instant>> = std::sync::Mutex::new(None);
let now = std::time::Instant::now();
if PREV.lock().unwrap().is_none() {
*START.lock().unwrap() = Some(std::time::Instant::now());
*PREV.lock().unwrap() = Some(std::time::Instant::now());
}
let mut prev = PREV.lock().unwrap();
let diff = now.duration_since(prev.unwrap());
*prev = Some(now);
let diff_str = crate::ui::time::format_duration(diff);
let diff_str = if crate::env::MISE_TIMINGS.as_ref().is_some_and(|s| s == "2") {
let relative = crate::ui::time::format_duration(diff);
let from_start =
crate::ui::time::format_duration(now.duration_since(START.lock().unwrap().unwrap()));
format!("{relative} {from_start}")
} else {
crate::ui::time::format_duration(diff)
};
let thread_id = crate::logger::thread_id();
let out = format!("[TIME] {thread_id} {module} {diff_str}")
.trim()
Expand All @@ -132,18 +141,18 @@ pub fn get_time_diff(module: &str) -> String {
#[cfg(feature = "timings")]
macro_rules! time {
() => {{
if *$crate::env::MISE_TIMINGS {
if $crate::env::MISE_TIMINGS.as_ref().is_some_and(|s| s != "0") {
eprintln!("{}", $crate::output::get_time_diff(module_path!()));
}
}};
($fn:expr) => {{
if *$crate::env::MISE_TIMINGS {
if $crate::env::MISE_TIMINGS.as_ref().is_some_and(|s| s != "0") {
let module = format!("{}::{}", module_path!(), format!($fn));
eprintln!("{}", $crate::output::get_time_diff(&module));
}
}};
($fn:expr, $($arg:tt)+) => {{
if *$crate::env::MISE_TIMINGS {
if $crate::env::MISE_TIMINGS.as_ref().is_some_and(|s| s != "0") {
let module = format!("{}::{}", module_path!(), format!($fn, $($arg)+));
eprintln!("{}", $crate::output::get_time_diff(&module));
}
Expand Down
Loading