From 352095a3b8ebedeb3810f5ed6a609cfc313e3fd2 Mon Sep 17 00:00:00 2001 From: Devyn Cairns Date: Wed, 12 Jun 2024 02:47:01 -0700 Subject: [PATCH] trying a little bit of preemptive optimization --- crates/nu-engine/src/eval_ir.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/crates/nu-engine/src/eval_ir.rs b/crates/nu-engine/src/eval_ir.rs index 45fa12e375..f6bfbcb4d9 100644 --- a/crates/nu-engine/src/eval_ir.rs +++ b/crates/nu-engine/src/eval_ir.rs @@ -23,17 +23,18 @@ pub fn eval_ir_block( // // Keep in mind that there is some code generated for each variant; at least at the moment // it doesn't seem like LLVM is able to optimize this away - let result = match ir_block.register_count { - 0..=4 => { + // + // This is organized like a tree to try to make sure we do the fewest number of branches + let result = if ir_block.register_count <= 8 { + if ir_block.register_count <= 4 { eval_ir_block_static::(engine_state, stack, &block_span, ir_block, input) - } - 5..=8 => { + } else { eval_ir_block_static::(engine_state, stack, &block_span, ir_block, input) } - 9..=16 => { - eval_ir_block_static::(engine_state, stack, &block_span, ir_block, input) - } - _ => eval_ir_block_dynamic::(engine_state, stack, &block_span, ir_block, input), + } else if ir_block.register_count <= 16 { + eval_ir_block_static::(engine_state, stack, &block_span, ir_block, input) + } else { + eval_ir_block_dynamic::(engine_state, stack, &block_span, ir_block, input) }; D::leave_block(engine_state, block);