perf: for-of 内置迭代器快路径直步,跳过 native 调用帧

This commit is contained in:
2026-09-26 19:59:23 +00:00
parent 80ce45d54c
commit bf19cf112b
8 changed files with 187 additions and 20 deletions
+11 -2
View File
@@ -15,6 +15,7 @@ use rustc_hash::FxBuildHasher;
use crate::session_gc::SessionGc;
use crate::vm::ForInIter;
use oxide_builtins::iterator::BuiltinIterKind;
use oxide_types::object::{Cell as UpvalueCell, JsObject, JsString};
use oxide_types::private_key::WELL_KNOWN_SYMBOL_COUNT;
use oxide_types::value::JsValue;
@@ -165,6 +166,11 @@ pub(crate) struct ForOfEntry {
/// promise(独立异步机制),同步逃出路径(break/continue/return 计数关闭)
/// 不得同步调用其 return()。
pub(crate) is_async: bool,
/// 内置包装器快路径:迭代器为 Array/String/TA/Map/Set 内置包装器时非 None,
/// DONE/NEXT 直步不经 native 调用;kind 失配清标志回落慢路径。
pub(crate) fast: Option<BuiltinIterKind>,
/// 快路径本迭代产出的元素值(仅 DONE→NEXT 之间有效,不跨迭代)。
pub(crate) fast_value: JsValue,
}
/// for-in / for-of 的活跃迭代器状态。
@@ -192,12 +198,15 @@ impl IterState {
}
/// 压入新迭代器条目:`last_result` 初始为 undefined(尚未执行任何 next())。
/// `is_async` 标记 for-await-of 的异步迭代器(异步逃出关闭走独立机制)。
pub(crate) fn push_for_of(&mut self, iterator: JsValue, is_async: bool) {
/// `is_async` 标记 for-await-of 的异步迭代器(异步逃出关闭走独立机制);
/// `fast` 为内置包装器种类(None = 慢路径)。
pub(crate) fn push_for_of(&mut self, iterator: JsValue, is_async: bool, fast: Option<BuiltinIterKind>) {
self.for_of_iters.push(ForOfEntry {
iterator,
last_result: JsValue::undefined(),
is_async,
fast,
fast_value: JsValue::undefined(),
});
}