Skip to content

Commit 5af022c

Browse files
committed
feat(simulation): add Python allocator opt-out
Add an experimental flag that unsets PYTHONMALLOC for simulation runs, allowing integrations to validate workloads without the forced malloc allocator before it becomes the default behavior.
1 parent 8ef1514 commit 5af022c

5 files changed

Lines changed: 30 additions & 1 deletion

File tree

‎src/cli/exec/mod.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ fn build_orchestrator_config(
9494
exclude_allocations: args.shared.exclude_allocations,
9595
simulation_track_subprocess: args.shared.simulation_track_subprocess,
9696
memory_track_physical: args.shared.experimental.experimental_memory_track_physical,
97+
disable_pythonmalloc_override: args
98+
.shared
99+
.experimental
100+
.experimental_disable_pythonmalloc_override,
97101
})
98102
}
99103

‎src/cli/experimental.rs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ pub struct ExperimentalArgs {
2727
)]
2828
pub experimental_memory_track_physical: bool,
2929

30+
/// Do not set PYTHONMALLOC for simulation runs.
31+
#[arg(
32+
long,
33+
default_value_t = false,
34+
help_heading = "Experimental",
35+
env = "CODSPEED_EXPERIMENTAL_DISABLE_PYTHONMALLOC_OVERRIDE"
36+
)]
37+
pub experimental_disable_pythonmalloc_override: bool,
38+
3039
/// Deprecated: cycle estimation is enabled by default and this flag has no effect.
3140
#[arg(long, hide = true, env = "CODSPEED_EXPERIMENTAL_CYCLE_ESTIMATION")]
3241
pub experimental_cycle_estimation: bool,
@@ -46,6 +55,9 @@ impl ExperimentalArgs {
4655
if self.experimental_memory_track_physical {
4756
flags.push("--experimental-memory-track-physical");
4857
}
58+
if self.experimental_disable_pythonmalloc_override {
59+
flags.push("--experimental-disable-pythonmalloc-override");
60+
}
4961
flags
5062
}
5163

‎src/cli/run/mod.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ impl RunArgs {
8484
experimental_cycle_estimation: false,
8585
experimental_exclude_allocations: false,
8686
experimental_memory_track_physical: false,
87+
experimental_disable_pythonmalloc_override: false,
8788
},
8889
},
8990
instruments: vec![],
@@ -137,6 +138,10 @@ fn build_orchestrator_config(
137138
exclude_allocations: args.shared.exclude_allocations,
138139
simulation_track_subprocess: args.shared.simulation_track_subprocess,
139140
memory_track_physical: args.shared.experimental.experimental_memory_track_physical,
141+
disable_pythonmalloc_override: args
142+
.shared
143+
.experimental
144+
.experimental_disable_pythonmalloc_override,
140145
})
141146
}
142147

‎src/executor/config.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ pub struct OrchestratorConfig {
100100
pub simulation_track_subprocess: bool,
101101
/// Enable physical (resident) memory tracking in memory mode.
102102
pub memory_track_physical: bool,
103+
/// Do not set PYTHONMALLOC for simulation runs.
104+
pub disable_pythonmalloc_override: bool,
103105
}
104106

105107
/// Per-execution configuration passed to executors.
@@ -145,6 +147,8 @@ pub struct ExecutorConfig {
145147
/// Only read by the memory executor, which is Linux-only.
146148
#[cfg_attr(not(target_os = "linux"), allow(dead_code))]
147149
pub memory_track_physical: bool,
150+
/// Do not set PYTHONMALLOC for simulation runs.
151+
pub disable_pythonmalloc_override: bool,
148152
}
149153

150154
#[derive(Debug, Clone, PartialEq)]
@@ -218,6 +222,7 @@ impl OrchestratorConfig {
218222
exclude_allocations: self.exclude_allocations,
219223
simulation_track_subprocess: self.simulation_track_subprocess,
220224
memory_track_physical: self.memory_track_physical,
225+
disable_pythonmalloc_override: self.disable_pythonmalloc_override,
221226
}
222227
}
223228
}
@@ -254,6 +259,7 @@ impl OrchestratorConfig {
254259
exclude_allocations: false,
255260
simulation_track_subprocess: false,
256261
memory_track_physical: false,
262+
disable_pythonmalloc_override: false,
257263
}
258264
}
259265
}

‎src/executor/valgrind/measure.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ pub async fn measure(
140140

141141
// Free-threaded Python (GIL disabled) does not support PYTHONMALLOC=malloc
142142
// and refuses to start with it set.
143-
if !is_free_threaded_python(config.working_directory.as_deref().map(Path::new)) {
143+
if !config.disable_pythonmalloc_override
144+
&& !is_free_threaded_python(config.working_directory.as_deref().map(Path::new))
145+
{
144146
cmd.env("PYTHONMALLOC", "malloc");
145147
}
146148

0 commit comments

Comments
 (0)