Skip to content

Commit 3d52024

Browse files
committed
reduce check_singals frequency
1 parent 85fa157 commit 3d52024

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

vm/src/frame.rs

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -488,8 +488,6 @@ impl ExecutingFrame<'_> {
488488
extend_arg: &mut bool,
489489
vm: &VirtualMachine,
490490
) -> FrameResult {
491-
vm.check_signals()?;
492-
493491
flame_guard!(format!(
494492
"Frame::execute_instruction({})",
495493
instruction.display(arg, &self.code.code).to_string()
@@ -807,6 +805,7 @@ impl ExecutingFrame<'_> {
807805
self.unwind_blocks(vm, UnwindReason::Returning { value })
808806
}
809807
bytecode::Instruction::YieldValue => {
808+
vm.check_signals()?;
810809
let value = self.pop_value();
811810
let value = if self.code.flags.contains(bytecode::CodeFlags::IS_COROUTINE) {
812811
PyAsyncGenWrappedValue(value).into_pyobject(vm)
@@ -815,7 +814,10 @@ impl ExecutingFrame<'_> {
815814
};
816815
Ok(Some(ExecutionResult::Yield(value)))
817816
}
818-
bytecode::Instruction::YieldFrom => self.execute_yield_from(vm),
817+
bytecode::Instruction::YieldFrom => {
818+
vm.check_signals()?;
819+
self.execute_yield_from(vm)
820+
}
819821
bytecode::Instruction::SetupAnnotation => self.setup_annotations(vm),
820822
bytecode::Instruction::SetupLoop => {
821823
self.push_block(BlockType::Loop);
@@ -942,6 +944,7 @@ impl ExecutingFrame<'_> {
942944
Ok(None)
943945
}
944946
bytecode::Instruction::WithCleanupFinish => {
947+
vm.check_signals()?;
945948
let block = self.pop_block();
946949
let (reason, prev_exc) = match block.typ {
947950
BlockType::FinallyHandler { reason, prev_exc } => (reason, prev_exc),
@@ -961,6 +964,7 @@ impl ExecutingFrame<'_> {
961964
}
962965
}
963966
bytecode::Instruction::PopBlock => {
967+
vm.check_signals()?;
964968
self.pop_block();
965969
Ok(None)
966970
}
@@ -1042,6 +1046,7 @@ impl ExecutingFrame<'_> {
10421046
Ok(None)
10431047
}
10441048
bytecode::Instruction::EndAsyncFor => {
1049+
vm.check_signals()?;
10451050
let exc = self.pop_value();
10461051
let except_block = self.pop_block(); // pushed by TryExcept unwind
10471052
debug_assert_eq!(except_block.level, self.state.stack.len());
@@ -1097,11 +1102,16 @@ impl ExecutingFrame<'_> {
10971102
self.execute_method_call(args, vm)
10981103
}
10991104
bytecode::Instruction::Jump { target } => {
1105+
vm.check_signals()?;
11001106
self.jump(target.get(arg));
11011107
Ok(None)
11021108
}
1103-
bytecode::Instruction::JumpIfTrue { target } => self.jump_if(vm, target.get(arg), true),
1109+
bytecode::Instruction::JumpIfTrue { target } => {
1110+
vm.check_signals()?;
1111+
self.jump_if(vm, target.get(arg), true)
1112+
}
11041113
bytecode::Instruction::JumpIfFalse { target } => {
1114+
vm.check_signals()?;
11051115
self.jump_if(vm, target.get(arg), false)
11061116
}
11071117
bytecode::Instruction::JumpIfTrueOrPop { target } => {
@@ -1111,20 +1121,26 @@ impl ExecutingFrame<'_> {
11111121
self.jump_if_or_pop(vm, target.get(arg), false)
11121122
}
11131123

1114-
bytecode::Instruction::Raise { kind } => self.execute_raise(vm, kind.get(arg)),
1124+
bytecode::Instruction::Raise { kind } => {
1125+
vm.check_signals()?;
1126+
self.execute_raise(vm, kind.get(arg))
1127+
}
11151128

11161129
bytecode::Instruction::Break { target } => self.unwind_blocks(
11171130
vm,
11181131
UnwindReason::Break {
11191132
target: target.get(arg),
11201133
},
11211134
),
1122-
bytecode::Instruction::Continue { target } => self.unwind_blocks(
1123-
vm,
1124-
UnwindReason::Continue {
1125-
target: target.get(arg),
1126-
},
1127-
),
1135+
bytecode::Instruction::Continue { target } => {
1136+
vm.check_signals()?;
1137+
self.unwind_blocks(
1138+
vm,
1139+
UnwindReason::Continue {
1140+
target: target.get(arg),
1141+
},
1142+
)
1143+
}
11281144
bytecode::Instruction::PrintExpr => self.print_expr(vm),
11291145
bytecode::Instruction::LoadBuildClass => {
11301146
self.push_value(vm.builtins.get_attr(identifier!(vm, __build_class__), vm)?);

0 commit comments

Comments
 (0)