perf(vm): eliminate recurring stack and return allocations
This commit is contained in:
@@ -46,21 +46,13 @@ impl VirtualMachine {
|
||||
)
|
||||
.map_err(|(_, error)| self.value_trap(error, opcode, pc))?;
|
||||
|
||||
// Copy return values (preserving order: pop return_slots values, then reverse to push back)
|
||||
let mut return_vals = BudgetVec::new(&self.budget, RuntimeResource::TemporaryBytes);
|
||||
return_vals.reserve(return_slots).map_err(|e| self.resource_trap(e, opcode, pc))?;
|
||||
for _ in 0..return_slots {
|
||||
return_vals
|
||||
.push(self.pop().map_err(LogicalFrameEndingReason::Panic)?)
|
||||
.map_err(|e| self.resource_trap(e, opcode, pc))?;
|
||||
// Validation is complete. Move the ordered result suffix ahead of this
|
||||
// frame's parameters/locals without cloning owners or reserving scratch.
|
||||
if return_slots != 0 {
|
||||
self.operand_stack[frame.stack_base..].rotate_right(return_slots);
|
||||
}
|
||||
return_vals.reverse();
|
||||
|
||||
self.operand_stack.truncate(frame.stack_base + return_slots);
|
||||
self.call_stack.pop();
|
||||
self.operand_stack.truncate(frame.stack_base);
|
||||
for val in return_vals.drain(..) {
|
||||
self.push_trap(val, opcode, pc)?;
|
||||
}
|
||||
self.pc = frame.return_pc as usize;
|
||||
if self.call_stack.is_empty() {
|
||||
self.handle_safepoint().map_err(|e| self.resource_trap(e, opcode, pc))?;
|
||||
|
||||
Reference in New Issue
Block a user