comphead commented on code in PR #27932:
URL: https://github.com/apache/datafusion/pull/27932#discussion_r4805886316
##########
benchmarks/interleave.py:
##########
@@ -179,6 +182,13 @@ def run_query(args, a, b, query, states):
spent = 0.0
pairs = 0
active = [side for side in (a, b) if states[side.name] == "ready"]
+ warmed = set()
+ if len(active) == 2:
+ for side in (a, b):
+ if side.run_one() is None:
+ active.remove(side)
+ else:
+ warmed.add(side.name)
Review Comment:
With A warmed up first, pair 0's A follows B's warm-up. Over 4 pairs, A's
iterations then follow the other side 3 times and the same side once, while B's
are 2 and 2. The docstring relies on each ABBA block balancing that, and
warming up B first restores it. https://github.com/apache/datafusion/pull/27811
found the gap mostly goes away without purging, so this is cheap insurance.
Warming up every ready side here also drops `warmed` and the `range(1 if ...
else 2)` at line 209, with the same number of runs in every case:
```python
for side in (b, a): # B first, so pair 0's A also follows an A
if side in active and side.run_one() is None:
active.remove(side)
```
The fallback at lines 208-212 then goes back to a single `run_one()`.
##########
benchmarks/src/util/sampler.rs:
##########
@@ -16,8 +16,9 @@
//! baseline and a branch process side by side and alternates their
//! iterations. See [`Lockstep`].
//!
-//! There is no warmup. A warmup run of a slow query costs as much as a
-//! measured run, and the convergence check already absorbs a slow first run.
+//! Each query runs one warm-up iteration first, which no statistic or results
+//! file includes. The first iteration of a query allocates memory that later
+//! iterations reuse, so it measures a state that the others do not.
Review Comment:
Worth mirroring in the `--iterations` and `--max-time` help in
`util/options.rs`, which is what users see. Neither mentions the extra
iteration, and the `--max-time` budget now excludes it.
##########
benchmarks/src/util/memory.rs:
##########
@@ -4,6 +4,24 @@
use datafusion::execution::memory_pool::{MemoryPool, PeakRecordingPool};
+/// Stops mimalloc from returning freed memory to the OS. Call it first in
+/// each benchmark binary's `main`.
Review Comment:
`benches/sql.rs` installs mimalloc too (lines 24-26) but never calls this.
`bench.sh` runs several suites through it (`SQL_CARGO_COMMAND`: the SQL TPC-H
variants, h2o, `predicate_eval` and others), so those keep the purge timer. One
`configure_allocator()` call at the top of `sql()` would cover them.
Nit on line 10: the default delay is 1000 ms in the vendored v3
(`options.c`), which is why it collides with iterations of about a second.
##########
benchmarks/src/util/memory.rs:
##########
@@ -66,3 +84,13 @@ fn print_allocator_stats() {
);
}
}
+
+#[cfg(all(test, feature = "mimalloc", not(feature = "snmalloc")))]
+mod tests {
+ #[test]
+ fn configure_allocator_disables_purging() {
+ super::configure_allocator();
+ // SAFETY: reading a mimalloc option has no preconditions.
+ assert_eq!(unsafe { libmimalloc_sys::mi_option_get(15) }, -1);
Review Comment:
This reads back the index it just wrote, so it passes for any valid option.
Asserting the default first ties `15` to `purge_delay` (1000 in the vendored
v3, unless `MIMALLOC_PURGE_DELAY` is set). Moving the constant to module level
also avoids the second literal:
```rust
let purge_delay = || unsafe {
libmimalloc_sys::mi_option_get(MI_OPTION_PURGE_DELAY) };
assert_eq!(purge_delay(), 1000);
super::configure_allocator();
assert_eq!(purge_delay(), -1);
```
##########
benchmarks/Cargo.toml:
##########
@@ -23,6 +23,7 @@ workspace = true
[features]
ci = []
default = ["mimalloc"]
+mimalloc = ["dep:mimalloc", "dep:libmimalloc-sys", "libmimalloc-sys/extended"]
snmalloc = ["snmalloc-rs"]
mimalloc_extended = ["libmimalloc-sys/extended"]
Review Comment:
`mimalloc` now enables `libmimalloc-sys/extended` itself, so this only gates
`print_allocator_stats`. `mimalloc_extended = ["mimalloc"]` would say that.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]