From 6a9ae54e5d0ebb6f09f2056c94ccc5b7158e9c37 Mon Sep 17 00:00:00 2001 From: pjh456 <147148383@qq.com> Date: Sat, 26 Sep 2026 16:58:12 +0000 Subject: [PATCH] =?UTF-8?q?perf:=20native=20=E5=90=8C=E6=AD=A5=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E5=AE=9E=E5=8F=82=E6=89=93=E5=8C=85=E6=94=B9=E6=A0=88?= =?UTF-8?q?=E5=86=85=20SmallVec=20=E5=85=8D=E5=A0=86=E5=88=86=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/oxide_vm/src/vm/call.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/oxide_vm/src/vm/call.rs b/crates/oxide_vm/src/vm/call.rs index bec3a5dc..ce105e25 100644 --- a/crates/oxide_vm/src/vm/call.rs +++ b/crates/oxide_vm/src/vm/call.rs @@ -6,6 +6,7 @@ use std::sync::Arc; use oxide_runtime_api::NativeResult; use oxide_types::object::JsObject; use oxide_types::value::JsValue; +use smallvec::SmallVec; use super::frames::{CallFrame, FrameArgs, FrameContinuation}; use super::{native_fn_ptr_to_fn, Vm}; @@ -13,11 +14,14 @@ use crate::native::NativeFn; use crate::{vm_debug, vm_trace}; impl Vm { - fn pack_sync_native_call_args(&mut self, receiver: JsValue, callee: JsValue, args: &[JsValue]) -> Vec { + fn pack_sync_native_call_args( + &mut self, receiver: JsValue, callee: JsValue, args: &[JsValue], + ) -> SmallVec<[u8; 256]> { self.regs[253] = receiver; self.regs[254] = callee; - let mut arg_regs = Vec::with_capacity(args.len() + 1); + // 实参寄存器号列表容量恒 ≤ 254(253 实参 + receiver),栈内缓冲免每次 native 调用堆分配。 + let mut arg_regs = SmallVec::new(); arg_regs.push(253); for (idx, arg) in args.iter().enumerate() { let reg = (Self::SYNC_NATIVE_ARG_BASE + idx) as u8;