From 2d8e5d861d5712b48ba1e5b27de92234ef268f98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=88=B1=E7=89=B9=E6=AF=8F=E7=BE=8A=E9=98=9F?= Date: Tue, 30 Jun 2026 20:04:37 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E7=A7=BB=E9=99=A4=20JsString=20?= =?UTF-8?q?=E6=AD=BB=E5=93=88=E5=B8=8C=E5=AD=97=E6=AE=B5=EF=BC=8C=E6=B6=88?= =?UTF-8?q?=E9=99=A4=E6=AF=8F=E6=AC=A1=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E7=9A=84=20O(n)=20FxHash=20=E5=BC=80=E9=94=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/oxide_runtime_api/src/lib.rs | 2 +- crates/oxide_types/src/object.rs | 18 +++++------------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/crates/oxide_runtime_api/src/lib.rs b/crates/oxide_runtime_api/src/lib.rs index 2bb3b30..113b421 100644 --- a/crates/oxide_runtime_api/src/lib.rs +++ b/crates/oxide_runtime_api/src/lib.rs @@ -147,7 +147,7 @@ pub fn string_value_eq(a: JsValue, b: JsValue) -> bool { } let sa = unsafe { &*a.as_string_ptr() }; let sb = unsafe { &*b.as_string_ptr() }; - sa.hash == sb.hash && sa.data == sb.data + sa.data == sb.data } pub fn to_number(val: JsValue) -> f64 { diff --git a/crates/oxide_types/src/object.rs b/crates/oxide_types/src/object.rs index ba6d025..0c324d3 100644 --- a/crates/oxide_types/src/object.rs +++ b/crates/oxide_types/src/object.rs @@ -1,27 +1,17 @@ -use std::hash::{Hash, Hasher}; - -use rustc_hash::FxHasher; - use crate::value::JsValue; /// Heap-allocated JS string value. /// /// String *values* are NaN-boxed as 48-bit pointers to a `JsString` (see -/// `JsValue::string`), replacing the old interner `(index, hash16)` pair. `hash` -/// is a full 64-bit FxHash computed once at construction and used as a fast -/// inequality reject before content comparison. +/// `JsValue::string`). #[derive(Debug)] pub struct JsString { pub data: String, - pub hash: u64, } impl JsString { pub fn new(data: String) -> Self { - let mut h = FxHasher::default(); - data.hash(&mut h); - let hash = h.finish(); - Self { data, hash } + Self { data } } pub fn len(&self) -> usize { @@ -484,7 +474,9 @@ impl JsObject { pub fn set_upvalues(&mut self, v: Box>) { if !self.upvalues.is_null() { - unsafe { drop(Box::from_raw(self.upvalues as *mut Vec<*mut Cell>)); } + unsafe { + drop(Box::from_raw(self.upvalues as *mut Vec<*mut Cell>)); + } } self.upvalues = Box::into_raw(v) as *mut u8; }