From 153f04b72ac68cce45374f724455683802eca74e Mon Sep 17 00:00:00 2001 From: Skgland Date: Sat, 21 Mar 2026 14:20:11 +0100 Subject: [PATCH] adjust interrupt handling we used to spend ~5.8% of the time on getting the next value of the 0..INSTRUCTIONS_PER_INTERRUPT_POLL iterator increment on Wrapping now only takes ~0.58 of the time --- src/machine/dispatch.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/machine/dispatch.rs b/src/machine/dispatch.rs index 33e9db1a..20ec38cb 100644 --- a/src/machine/dispatch.rs +++ b/src/machine/dispatch.rs @@ -77,8 +77,6 @@ macro_rules! push_cell { }}; } -static INSTRUCTIONS_PER_INTERRUPT_POLL: usize = 256; - impl MachineState { #[inline(always)] fn compare(&mut self) -> CallResult { @@ -1541,8 +1539,13 @@ impl Machine { } fn verify_attr_dispatch_loop(&mut self) -> Option { + let mut interrupt_counter = std::num::Wrapping(0u8); 'outer: loop { - for _ in 0..INSTRUCTIONS_PER_INTERRUPT_POLL { + loop { + interrupt_counter += 1; + if interrupt_counter.0 == 0 { + break; + } match self.code[self.machine_st.p] { Instruction::BreakFromDispatchLoop => { break 'outer; @@ -1611,8 +1614,14 @@ impl Machine { } pub(super) fn dispatch_loop(&mut self) -> std::process::ExitCode { + let mut interrupt_counter = std::num::Wrapping(0u8); 'outer: loop { - for _ in 0..INSTRUCTIONS_PER_INTERRUPT_POLL { + loop { + interrupt_counter += 1; + if interrupt_counter.0 == 0 { + break; + } + match &self.code[self.machine_st.p] { &Instruction::BreakFromDispatchLoop => { break 'outer; -- 2.54.0