perf: String() 有限 double 转串加 16 槽 last-value 缓存

This commit is contained in:
2026-10-05 07:36:12 +00:00
parent 1dc9f41618
commit bfbab9431a
9 changed files with 145 additions and 21 deletions
+6
View File
@@ -76,6 +76,12 @@ impl Vm {
for &cached in self.template_objects.values() {
f(cached);
}
// f64→string 缓存槽值是 session 串,是 GC 根(漏根 → 串清扫释放 → 命中悬垂)。
for &v in &self.number_to_string_cache_vals {
if v.is_string() {
f(v);
}
}
for &entry in &self.iters.for_of_iters {
f(entry.iterator);
f(entry.last_result);
+6
View File
@@ -183,6 +183,12 @@ pub struct Vm {
/// (发射层字符串常量统一经 perm_string 物化),指针相等即键为 "length",
/// 入口快判只比指针免键解析。PermInterner 追加式、指针唯一,永不失效。
pub(crate) length_perm_ptr: *const JsString,
/// f64→string 十六槽 last-value 缓存的键(double 位模式)。空槽判定用
/// 对应值非字符串:键 0 是 +0.0 的合法位模式,不得作空标记。
pub(crate) number_to_string_cache_keys: [u64; 16],
/// f64→string 十六槽 last-value 缓存的值(session 串,经 `for_each_value`
/// 登记为 GC 根;`full_reset` 在 session 串释放前清空)。
pub(crate) number_to_string_cache_vals: [JsValue; 16],
pub object_prototype: P<JsObject>,
/// `%GeneratorPrototype%`:生成器实例的原型(next/return/throw 方法挂此)。
pub generator_proto: P<JsObject>,
+3
View File
@@ -33,6 +33,9 @@ impl oxide_runtime_api::VmHost for Vm {
fn new_string_owned(&mut self, s: String) -> JsValue {
Vm::new_string_owned(self, s)
}
fn number_to_string_cached(&mut self, d: f64) -> JsValue {
Vm::number_to_string_cached(self, d)
}
fn new_bigint(&mut self, v: num_bigint::BigInt) -> JsValue {
Vm::new_bigint(self, v)
}