Skip to content
Prev Previous commit
Next Next commit
don't inline elapsed_time
  • Loading branch information
ShaharNaveh committed Jun 17, 2026
commit c8b9b0f0822cc6fa411bf326321017d69400dd49
41 changes: 20 additions & 21 deletions crates/vm/src/gc_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ use core::ptr::NonNull;
use core::sync::atomic::{AtomicBool, AtomicU32, AtomicUsize, Ordering};
use std::collections::HashSet;

#[cfg(not(target_arch = "wasm32"))]
fn elapsed_secs(start: &std::time::Instant) -> f64 {
start.elapsed().as_secs_f64()
fn elapsed_secs(
#[cfg(target_arch = "wasm32")] _start: &(),
#[cfg(not(target_arch = "wasm32"))] start: &std::time::Instant,
) -> f64 {
cfg_select! {
target_arch = "wasm32" => 0.0,
_ => start.elapsed().as_secs_f64(),
}
}

bitflags::bitflags! {
Expand Down Expand Up @@ -388,8 +393,10 @@ impl GcState {
return CollectResult::default();
};

#[cfg(not(target_arch = "wasm32"))]
let start_time = std::time::Instant::now();
let start_time = cfg_select! {
target_arch = "wasm32" => (),
_ => std::time::Instant::now(),
};

// Memory barrier to ensure visibility of all reference count updates
// from other threads before we start analyzing the object graph.
Expand Down Expand Up @@ -425,10 +432,7 @@ impl GcState {
self.generations[i].count.store(0, Ordering::SeqCst);
}

let duration = cfg_select! {
target_arch = "wasm32" => 0.0,
_ => elapsed_secs(&start_time),
};
let duration = elapsed_secs(&start_time);

self.generations[generation].update_stats(0, 0, 0, duration);
return CollectResult {
Expand Down Expand Up @@ -555,10 +559,8 @@ impl GcState {
self.generations[i].count.store(0, Ordering::SeqCst);
}

let duration = cfg_select! {
target_arch = "wasm32" => 0.0,
_ => elapsed_secs(&start_time),
};
let duration = elapsed_secs(&start_time);

self.generations[generation].update_stats(0, 0, candidates, duration);
return CollectResult {
collected: 0,
Expand All @@ -579,10 +581,9 @@ impl GcState {
for i in 0..reset_end {
self.generations[i].count.store(0, Ordering::SeqCst);
}
let duration = cfg_select! {
target_arch = "wasm32" => 0.0,
_ => elapsed_secs(&start_time),
};

let duration = elapsed_secs(&start_time);

self.generations[generation].update_stats(0, 0, candidates, duration);
return CollectResult {
collected: 0,
Expand Down Expand Up @@ -730,10 +731,8 @@ impl GcState {
self.generations[i].count.store(0, Ordering::SeqCst);
}

let duration = cfg_select! {
target_arch = "wasm32" => 0.0,
_ => elapsed_secs(&start_time),
};
let duration = elapsed_secs(&start_time);

self.generations[generation].update_stats(collected, 0, candidates, duration);

CollectResult {
Expand Down
Loading