Skip to content

Commit

Permalink
fix(rust): don't return NaN as available memory fraction
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteNybbler committed Jan 19, 2024
1 parent 62ecdd3 commit d6b3e91
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions crates/polars-pipe/src/executors/sinks/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,15 @@ impl MemTracker {
}

pub(super) fn free_memory_fraction_since_start(&self) -> f64 {
// we divide first to reduce the precision loss in floats
let available_at_start = (self.available_at_start / TO_MB) as f64;
let available = (self.get_available() / TO_MB) as f64;
available / available_at_start
if self.available_at_start == 0 {
// This branch exists to prevent division by 0 so we don't return NaN.
0.0
} else {
// We divide first to reduce the precision loss in floats.
let available_at_start = (self.available_at_start / TO_MB) as f64;
let available = (self.get_available() / TO_MB) as f64;
available / available_at_start
}
}

/// Increment the used memory and return the previous value.
Expand Down

0 comments on commit d6b3e91

Please sign in to comment.