Skip to content

Commit cae03c9

Browse files
authored
Allow benchmark allocator features together (#21905)
## Which issue does this PR close? Split from #21637. ## Rationale for this change The benchmark binaries currently reject enabling both `snmalloc` and `mimalloc`. However, workspace-wide checks such as `cargo clippy --all-targets --all-features` enable both feature flags, which makes these binaries fail before clippy can run. ## What changes are included in this PR? This PR removes the explicit compile error from the benchmark binaries and makes allocator selection deterministic: `snmalloc` is used when enabled, otherwise `mimalloc` is used when enabled. ## Are these changes tested? ## Are there any user-facing changes? No. This only affects benchmark binary feature combinations used by development checks.
1 parent a288e61 commit cae03c9

4 files changed

Lines changed: 12 additions & 24 deletions

File tree

benchmarks/benches/sql.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,13 @@ static SQL_BENCHMARK_DIRECTORY: LazyLock<String> = LazyLock::new(|| {
4343
)
4444
});
4545

46-
#[cfg(all(feature = "snmalloc", feature = "mimalloc"))]
47-
compile_error!(
48-
"feature \"snmalloc\" and feature \"mimalloc\" cannot be enabled at the same time"
49-
);
50-
5146
#[cfg(feature = "snmalloc")]
5247
#[global_allocator]
5348
static ALLOC: snmalloc_rs::SnMalloc = snmalloc_rs::SnMalloc;
5449

55-
#[cfg(feature = "mimalloc")]
50+
// `cargo clippy --all-features` enables both allocator features, so prefer
51+
// `snmalloc` in that case and fall back to `mimalloc` otherwise.
52+
#[cfg(all(not(feature = "snmalloc"), feature = "mimalloc"))]
5653
#[global_allocator]
5754
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;
5855

benchmarks/src/bin/benchmark_runner.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,13 @@
1717

1818
use datafusion_benchmarks::benchmark_runner::run_cli;
1919

20-
#[cfg(all(feature = "snmalloc", feature = "mimalloc"))]
21-
compile_error!(
22-
"feature \"snmalloc\" and feature \"mimalloc\" cannot be enabled at the same time"
23-
);
24-
2520
#[cfg(feature = "snmalloc")]
2621
#[global_allocator]
2722
static ALLOC: snmalloc_rs::SnMalloc = snmalloc_rs::SnMalloc;
2823

29-
#[cfg(feature = "mimalloc")]
24+
// `cargo clippy --all-features` enables both allocator features, so prefer
25+
// `snmalloc` in that case and fall back to `mimalloc` otherwise.
26+
#[cfg(all(not(feature = "snmalloc"), feature = "mimalloc"))]
3027
#[global_allocator]
3128
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;
3229

benchmarks/src/bin/dfbench.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,13 @@ use datafusion::error::Result;
2020

2121
use clap::{Parser, Subcommand};
2222

23-
#[cfg(all(feature = "snmalloc", feature = "mimalloc"))]
24-
compile_error!(
25-
"feature \"snmalloc\" and feature \"mimalloc\" cannot be enabled at the same time"
26-
);
27-
2823
#[cfg(feature = "snmalloc")]
2924
#[global_allocator]
3025
static ALLOC: snmalloc_rs::SnMalloc = snmalloc_rs::SnMalloc;
3126

32-
#[cfg(feature = "mimalloc")]
27+
// `cargo clippy --all-features` enables both allocator features, so prefer
28+
// `snmalloc` in that case and fall back to `mimalloc` otherwise.
29+
#[cfg(all(not(feature = "snmalloc"), feature = "mimalloc"))]
3330
#[global_allocator]
3431
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;
3532

benchmarks/src/bin/imdb.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,13 @@ use clap::{Parser, Subcommand};
2121
use datafusion::error::Result;
2222
use datafusion_benchmarks::imdb;
2323

24-
#[cfg(all(feature = "snmalloc", feature = "mimalloc"))]
25-
compile_error!(
26-
"feature \"snmalloc\" and feature \"mimalloc\" cannot be enabled at the same time"
27-
);
28-
2924
#[cfg(feature = "snmalloc")]
3025
#[global_allocator]
3126
static ALLOC: snmalloc_rs::SnMalloc = snmalloc_rs::SnMalloc;
3227

33-
#[cfg(feature = "mimalloc")]
28+
// `cargo clippy --all-features` enables both allocator features, so prefer
29+
// `snmalloc` in that case and fall back to `mimalloc` otherwise.
30+
#[cfg(all(not(feature = "snmalloc"), feature = "mimalloc"))]
3431
#[global_allocator]
3532
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;
3633

0 commit comments

Comments
 (0)