perf: upvalue 读取缓存 callee 切片指针省解引用链

This commit is contained in:
2026-09-26 20:30:53 +00:00
parent bf19cf112b
commit 717960a9e8
7 changed files with 59 additions and 19 deletions
+2
View File
@@ -317,6 +317,8 @@ impl Vm {
strict: sub_is_strict,
continuation,
});
// 压帧后 callee 换为被调函数:失效 upvalue 切片缓存。
self.upvalue_cache = None;
self.pc = 0;
self.bytecode = sub_bytecode;
+2
View File
@@ -40,6 +40,8 @@ pub(crate) struct InlineSyncState {
pub(crate) spill_stack: Vec<JsValue>,
pub(crate) cell_stack: Vec<Vec<*mut Cell>>,
pub(crate) inline_callee: Option<JsValue>,
/// upvalue 切片指针缓存(与 `inline_callee` 同生命周期,随本快照保存/恢复)。
pub(crate) upvalue_cache: Option<(JsValue, *const [*mut Cell])>,
/// 三个内嵌 dispatch 调度标志(`Vm::generator_dispatch` / `async_dispatch` /
/// `construct_dispatch`)的属主快照。save 时记录外层值并清零 VM 侧、restore
/// 时写回:嵌套 state-swap 调用不得继承外层调度上下文,否则其内部构造帧
+5
View File
@@ -255,6 +255,11 @@ pub struct Vm {
/// frames 为空(inline 隔离状态)时由此取闭包 upvalues。嵌套 inline 由
/// InlineSyncState 保存/恢复。
pub(crate) inline_callee: Option<JsValue>,
/// upvalue 切片指针缓存:键 = 当前 callee 值(位级相等),值 = 该 callee 的
/// `upvalues` 切片指针(含空切片情形)。LOAD_UPVALUE 命中时省 `is_object` +
/// 对象解引用 + 切片解引用。压帧/弹帧/挂起/run 边界失效;键匹配期间指针恒
/// 有效——callee 对象是 GC 根,`upvalues` Box 创建后不替换。
pub(crate) upvalue_cache: Option<(JsValue, *const [*mut Cell])>,
/// inline 目标函数的严格模式标志(与 `inline_callee` 同生命周期,
/// InlineSyncState 保存/恢复):内联执行期间帧表被隔离,写路径的
/// strict/sloppy 判定取此值而非帧标志。