refactor: 扁平化对象属性存储并优化常量池与 IC 热路径

This commit is contained in:
爱特每羊队
2026-06-13 23:59:47 +08:00
parent dcc7db2575
commit bf74adf7f5
26 changed files with 307 additions and 87 deletions
+5 -5
View File
@@ -26,19 +26,19 @@ fn bind_error_subtype_constructor(
let ctor_shape1 = sh.make_shape(EMPTY_SHAPE_ID, si_prototype);
let ctor_shape2 = sh.make_shape(ctor_shape1, si_name);
ctor.set_shape_id(ctor_shape2);
ctor.ensure_hash_props().push(Box::new(JsValue::from_js_object(proto_ptr)));
ctor.ensure_hash_props().push(Box::new(JsValue::string(name_si, 0)));
ctor.ensure_hash_props().push(JsValue::from_js_object(proto_ptr));
ctor.ensure_hash_props().push(JsValue::string(name_si, 0));
let ctor_ptr = Box::into_raw(ctor);
let proto = unsafe { &mut *proto_ptr };
let proto_ctor_shape = sh.make_shape(proto.shape_id(), sf.intern("constructor").0);
proto.set_shape_id(proto_ctor_shape);
proto.ensure_hash_props().push(Box::new(JsValue::from_js_object(ctor_ptr)));
proto.ensure_hash_props().push(JsValue::from_js_object(ctor_ptr));
let global_shape = sh.make_shape(global.shape_id(), name_si);
global.set_shape_id(global_shape);
global.ensure_hash_props().push(Box::new(JsValue::from_js_object(ctor_ptr)));
global.ensure_hash_props().push(JsValue::from_js_object(ctor_ptr));
global.bump_generation();
}
@@ -64,7 +64,7 @@ pub fn bind_error(kernel: &Arc<OxideKernel>, global: &mut JsObject) {
let err_shape = kernel.shape_forge().make_shape(global.shape_id(), si_err);
let err_val = JsValue::from_js_object(kernel.builtin_world().error_constructor.as_ptr() as *mut JsObject);
global.set_shape_id(err_shape);
global.ensure_hash_props().push(Box::new(err_val));
global.ensure_hash_props().push(err_val);
global.bump_generation();
bind_error_subtype_constructor(
+2 -2
View File
@@ -68,13 +68,13 @@ pub fn bind_math(kernel: &Arc<OxideKernel>, global: &mut JsObject) {
let si = kernel.string_forge().as_ref().intern(name).0;
let sh_c = kernel.shape_forge().as_ref().make_shape(math.shape_id(), si);
math.set_shape_id(sh_c);
math.ensure_hash_props().push(Box::new(JsValue::float(val)));
math.ensure_hash_props().push(JsValue::float(val));
}
let si_m = kernel.string_forge().intern("Math").0;
let m_shape = kernel.shape_forge().make_shape(global.shape_id(), si_m);
let m_val = JsValue::from_js_object(kernel.builtin_world().math_object.as_ptr() as *mut JsObject);
global.set_shape_id(m_shape);
global.ensure_hash_props().push(Box::new(m_val));
global.ensure_hash_props().push(m_val);
global.bump_generation();
}
+2 -2
View File
@@ -30,7 +30,7 @@ pub fn bind_number(kernel: &Arc<OxideKernel>, global: &mut JsObject) {
let num_shape = kernel.shape_forge().make_shape(global.shape_id(), si_num);
let num_val = JsValue::from_js_object(kernel.builtin_world().number_constructor.as_ptr() as *mut JsObject);
global.set_shape_id(num_shape);
global.ensure_hash_props().push(Box::new(num_val));
global.ensure_hash_props().push(num_val);
global.bump_generation();
{
@@ -52,7 +52,7 @@ pub fn bind_number(kernel: &Arc<OxideKernel>, global: &mut JsObject) {
("NEGATIVE_INFINITY", JsValue::float(f64::NEG_INFINITY)),
("POSITIVE_INFINITY", JsValue::float(f64::INFINITY)),
] {
num_ctor.ensure_hash_props().push(Box::new(value));
num_ctor.ensure_hash_props().push(value);
let prop_si = kernel.string_forge().intern(name).0;
let next_shape = kernel.shape_forge().make_shape(num_ctor.shape_id(), prop_si);
num_ctor.set_shape_id(next_shape);
+1 -1
View File
@@ -44,6 +44,6 @@ pub fn bind_string(kernel: &Arc<OxideKernel>, global: &mut JsObject) {
let str_shape = kernel.shape_forge().make_shape(global.shape_id(), si_str);
let str_val = JsValue::from_js_object(kernel.builtin_world().string_constructor.as_ptr() as *mut JsObject);
global.set_shape_id(str_shape);
global.ensure_hash_props().push(Box::new(str_val));
global.ensure_hash_props().push(str_val);
global.bump_generation();
}
+1 -1
View File
@@ -54,6 +54,6 @@ fn bind_well_known_symbol(kernel: &Arc<OxideKernel>, ctor: &mut JsObject, name:
let si = kernel.string_forge().intern(name).0;
let shape_id = kernel.shape_forge().make_shape(ctor.shape_id(), si);
ctor.set_shape_id(shape_id);
ctor.ensure_hash_props().push(Box::new(val));
ctor.ensure_hash_props().push(val);
ctor.bump_generation();
}
+2 -2
View File
@@ -42,7 +42,7 @@ macro_rules! bind_constructor_hash {
let shape = $kernel.shape_forge().make_shape($global.shape_id(), si);
let val = $crate::JsValue::from_js_object($ctor_ptr);
$global.set_shape_id(shape);
$global.ensure_hash_props().push(Box::new(val));
$global.ensure_hash_props().push(val);
$global.bump_generation();
let ctor = unsafe { &mut *$ctor_ptr };
// SAFETY: $ctor_fn is a fn-item expression; casting to *const () preserves validity.
@@ -73,7 +73,7 @@ pub(crate) fn bind_global_value(kernel: &Arc<OxideKernel>, global: &mut JsObject
let si = kernel.string_forge().intern(name).0;
let shape = kernel.shape_forge().make_shape(global.shape_id(), si);
global.set_shape_id(shape);
global.ensure_hash_props().push(Box::new(value));
global.ensure_hash_props().push(value);
global.bump_generation();
}