From 5b0affe065076545d284cf705f9753e80302a961 Mon Sep 17 00:00:00 2001 From: pjh456 <147148383@qq.com> Date: Fri, 11 Sep 2026 20:20:00 +0000 Subject: [PATCH] =?UTF-8?q?perf:=20PermEntry=20=E7=98=A6=E8=BA=AB=E2=80=94?= =?UTF-8?q?=E2=80=94=E5=88=A0=E5=AD=98=E5=82=A8=E4=BE=A7=E9=9B=B6=E6=B6=88?= =?UTF-8?q?=E8=B4=B9=E7=9A=84=208B=20hash=20=E5=AD=97=E6=AE=B5=EF=BC=8824B?= =?UTF-8?q?=E2=86=9216B=EF=BC=8C=E9=94=AE=E5=AF=BB=E5=9D=80=E4=BB=8D?= =?UTF-8?q?=E7=BB=8F=20DashMap=20=E5=93=88=E5=B8=8C=E9=94=AE=EF=BC=8C?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E4=BF=9D=E7=95=99=E5=AD=98=E5=82=A8=E5=88=A0?= =?UTF-8?q?=E9=99=A4=EF=BC=89=EF=BC=8Cget=5Fhash=20=E9=9A=8F=E4=B9=8B?= =?UTF-8?q?=E5=88=A0=E9=99=A4=EF=BC=8C=E5=B8=83=E5=B1=80=E4=BB=A5=E5=B0=BA?= =?UTF-8?q?=E5=AF=B8=20const=20=E6=96=AD=E8=A8=80=E9=92=89=E6=AD=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/oxide_kernel/src/string_forge.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/crates/oxide_kernel/src/string_forge.rs b/crates/oxide_kernel/src/string_forge.rs index fe3e7185..f2d6df9f 100644 --- a/crates/oxide_kernel/src/string_forge.rs +++ b/crates/oxide_kernel/src/string_forge.rs @@ -16,13 +16,16 @@ fn hash64(s: &str) -> u64 { } /// 一条 intern 过的键。`data` 是泄漏的 `&'static str`——永久键从不释放 -/// (按设计 append-only),所以泄漏即存储模型,而非 bug。 +/// (按设计 append-only),所以泄漏即存储模型,而非 bug。键 id 与 64 位 +/// 哈希经 `DashMap` 的哈希键→候选 id 表寻址,条目自身不存哈希。 #[derive(Clone, Copy)] struct PermEntry { data: &'static str, - hash: u64, } +// 布局钉:条目仅泄漏指针 + 长度(16B);布局漂移即编译失败。 +const _: () = assert!(std::mem::size_of::() == 16); + /// 所有 VM 共享的 append-only、永不移动、读无锁的键 interner。 /// /// 取代旧的引用计数 `StringForge`(及其有缺陷的 `maybe_sweep` 重编号路径)。 @@ -81,7 +84,7 @@ impl PermInterner { } let id = entries.len() as u32; let leaked: &'static str = Box::leak(s.to_string().into_boxed_str()); - entries.push(PermEntry { data: leaked, hash }); + entries.push(PermEntry { data: leaked }); let entry_count = entries.len(); drop(entries); self.hash_map.entry(hash).or_default().push(id); @@ -99,12 +102,6 @@ impl PermInterner { entries.get(id as usize).map(|e| e.data) } - /// 键 id 的完整 64 位哈希。 - pub fn get_hash(&self, id: u32) -> Option { - let entries = self.entries.read().unwrap(); - entries.get(id as usize).map(|e| e.hash) - } - /// 全部唯一 intern 键的数量。 pub fn entry_count(&self) -> u32 { self.entries.read().unwrap().len() as u32