Skip to content

Commit 29995b3

Browse files
authored
perf: Don't inline slow OOC memory drift path (#29745)
1 parent 8399cf6 commit 29995b3

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

‎crates/polars-ooc/src/global_alloc.rs‎

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,24 @@ thread_local! {
2929
fn update_alloc_size(bytes: i64) {
3030
LOCAL_ALLOC_DRIFT.with(|drift| {
3131
let new = drift.get().wrapping_add(bytes);
32-
if new.unsigned_abs() <= polars_config::get_ooc_drift_threshold() {
33-
drift.set(new);
34-
} else {
35-
let old = GLOBAL_ALLOC_SIZE.fetch_add(new as u64, Ordering::AcqRel);
36-
drift.set(0);
37-
let total = old.wrapping_add(new as u64);
38-
if total <= i64::MAX as u64 && total > polars_config::get_oomkill_threshold_bytes() {
39-
oomkill();
40-
}
32+
drift.set(new);
33+
if new.unsigned_abs() > polars_config::get_ooc_drift_threshold() {
34+
flush_local_drift();
35+
}
36+
})
37+
}
38+
39+
#[cold]
40+
#[inline(never)]
41+
fn flush_local_drift() {
42+
LOCAL_ALLOC_DRIFT.with(|drift| {
43+
let drift_bytes = drift.get();
44+
let old = GLOBAL_ALLOC_SIZE.fetch_add(drift_bytes as u64, Ordering::AcqRel);
45+
drift.set(0);
46+
47+
let total = old.wrapping_add(drift_bytes as u64);
48+
if total <= i64::MAX as u64 && total > polars_config::get_oomkill_threshold_bytes() {
49+
oomkill();
4150
}
4251
})
4352
}

0 commit comments

Comments
 (0)