mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-25 19:21:11 +08:00
perf: GC 字节账目补齐 + is_epoch_ptr O(1) + 分配热路径触发
This commit is contained in:
@@ -952,8 +952,8 @@ pub(crate) fn clone_async_generator_native_with_rewrite(
|
||||
new.set_native_data(Box::into_raw(Box::new(cloned)) as *mut u8);
|
||||
}
|
||||
|
||||
/// 释放异步生成器状态盒(对象被 GC 回收时),返回释放字节数。
|
||||
pub(crate) fn drop_async_generator_native(obj: &JsObject) -> u64 {
|
||||
/// 只读核算异步生成器状态盒字节(不释放),供 GC 账目核算。
|
||||
pub(crate) fn async_generator_native_size(obj: &JsObject) -> u64 {
|
||||
if !obj.is_async_generator_obj() {
|
||||
return 0;
|
||||
}
|
||||
@@ -961,9 +961,22 @@ pub(crate) fn drop_async_generator_native(obj: &JsObject) -> u64 {
|
||||
if ptr.is_null() {
|
||||
return 0;
|
||||
}
|
||||
// SAFETY: 指针来自 create_async_generator_object 的 Box::into_raw,只在 GC 回收时释放一次。
|
||||
let state = unsafe { Box::from_raw(ptr) };
|
||||
std::mem::size_of::<AsyncGeneratorState>() as u64
|
||||
+ state.suspended.heap_bytes()
|
||||
+ state.args.capacity() as u64 * std::mem::size_of::<JsValue>() as u64
|
||||
unsafe {
|
||||
std::mem::size_of::<AsyncGeneratorState>() as u64
|
||||
+ (*ptr).suspended.heap_bytes()
|
||||
+ (*ptr).args.capacity() as u64 * std::mem::size_of::<JsValue>() as u64
|
||||
}
|
||||
}
|
||||
|
||||
/// 释放异步生成器状态盒(对象被 GC 回收时),返回释放字节数。
|
||||
pub(crate) fn drop_async_generator_native(obj: &JsObject) -> u64 {
|
||||
let bytes = async_generator_native_size(obj);
|
||||
if bytes == 0 {
|
||||
return 0;
|
||||
}
|
||||
let ptr = obj.native_data() as *mut AsyncGeneratorState;
|
||||
// SAFETY: ptr 非空(async_generator_native_size 已验证),Box::from_raw 恰好释放一次。
|
||||
let state = unsafe { Box::from_raw(ptr) };
|
||||
drop(state);
|
||||
bytes
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user