Skip to content

Commit f3e7b3c

Browse files
perf: faster execution ctx and no opt (#7597)
Makes the `ExecutionCtx` faster to create and destroy. Remove unconditional optimize from execute Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
1 parent bfb5dba commit f3e7b3c

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

vortex-array/src/executor.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use std::env::VarError;
2121
use std::fmt;
2222
use std::fmt::Display;
2323
use std::sync::LazyLock;
24-
use std::sync::atomic::AtomicUsize;
2524

2625
use vortex_error::VortexExpect;
2726
use vortex_error::VortexResult;
@@ -107,7 +106,7 @@ impl ArrayRef {
107106
/// For safety, we will error when the number of execution iterations reaches a configurable
108107
/// maximum (default 128, override with `VORTEX_MAX_ITERATIONS`).
109108
pub fn execute_until<M: Matcher>(self, ctx: &mut ExecutionCtx) -> VortexResult<ArrayRef> {
110-
let mut current = self.optimize()?;
109+
let mut current = self;
111110
let mut stack: Vec<StackFrame> = Vec::new();
112111

113112
for _ in 0..max_iterations() {
@@ -221,19 +220,25 @@ impl StackFrame {
221220
/// Execution context for batch CPU compute.
222221
#[derive(Debug, Clone)]
223222
pub struct ExecutionCtx {
224-
id: usize,
225223
session: VortexSession,
224+
#[cfg(debug_assertions)]
225+
id: usize,
226+
#[cfg(debug_assertions)]
226227
ops: Vec<String>,
227228
}
228229

229230
impl ExecutionCtx {
230231
/// Create a new execution context with the given session.
231232
pub fn new(session: VortexSession) -> Self {
232-
static EXEC_CTX_ID: AtomicUsize = AtomicUsize::new(0);
233-
let id = EXEC_CTX_ID.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
234233
Self {
235234
session,
236-
id,
235+
#[cfg(debug_assertions)]
236+
id: {
237+
static EXEC_CTX_ID: std::sync::atomic::AtomicUsize =
238+
std::sync::atomic::AtomicUsize::new(0);
239+
EXEC_CTX_ID.fetch_add(1, std::sync::atomic::Ordering::Relaxed)
240+
},
241+
#[cfg(debug_assertions)]
237242
ops: Vec::new(),
238243
}
239244
}
@@ -255,20 +260,26 @@ impl ExecutionCtx {
255260
///
256261
/// Use the [`format_args!`] macro to create the `msg` argument.
257262
pub fn log(&mut self, msg: fmt::Arguments<'_>) {
263+
#[cfg(debug_assertions)]
258264
if tracing::enabled!(tracing::Level::DEBUG) {
259265
let formatted = format!(" - {msg}");
260266
tracing::trace!("exec[{}]: {formatted}", self.id);
261267
self.ops.push(formatted);
262268
}
269+
let _ = msg;
263270
}
264271
}
265272

266273
impl Display for ExecutionCtx {
267274
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
268-
write!(f, "exec[{}]", self.id)
275+
#[cfg(debug_assertions)]
276+
return write!(f, "exec[{}]", self.id);
277+
#[cfg(not(debug_assertions))]
278+
write!(f, "exec")
269279
}
270280
}
271281

282+
#[cfg(debug_assertions)]
272283
impl Drop for ExecutionCtx {
273284
fn drop(&mut self) {
274285
if !self.ops.is_empty() && tracing::enabled!(tracing::Level::DEBUG) {

0 commit comments

Comments
 (0)