diff --git a/changelog.d/6802-inline-guard-per-key-c5a.md b/changelog.d/6802-inline-guard-per-key-c5a.md
new file mode 100644
index 00000000000..4ce73e728e3
--- /dev/null
+++ b/changelog.d/6802-inline-guard-per-key-c5a.md
@@ -0,0 +1 @@
+perf(runtime): #6759 C5a — the class-field inline-guard disable is now vetted per-key: a prototype-level descriptor install only flips the process-wide kill switch when its key names a declared instance field of a registered class (with a retro-check for classes that register after the install). Babel-style method installs on class prototypes no longer push every `this.field` access onto the out-of-line guard call.
diff --git a/crates/perry-runtime/src/object/alloc.rs b/crates/perry-runtime/src/object/alloc.rs
index 1550e0f2821..ccf8c41234d 100644
--- a/crates/perry-runtime/src/object/alloc.rs
+++ b/crates/perry-runtime/src/object/alloc.rs
@@ -14,14 +14,31 @@ fn remember_class_keys_array(class_id: u32, field_count: u32, keys_array: *mut A
if class_id == 0 || keys_array.is_null() {
return;
}
- let mut guard = CLASS_KEYS_BY_ID.write().unwrap();
- if guard.is_none() {
- *guard = Some(std::collections::HashMap::new());
- }
- guard
- .as_mut()
- .unwrap()
- .insert(class_id, (keys_array as usize, field_count));
+ {
+ let mut guard = CLASS_KEYS_BY_ID.write().unwrap();
+ if guard.is_none() {
+ *guard = Some(std::collections::HashMap::new());
+ }
+ guard
+ .as_mut()
+ .unwrap()
+ .insert(class_id, (keys_array as usize, field_count));
+ }
+ // #6759 C5a: harvest this class's declared instance-field names into
+ // the process-wide name-hash set the per-key inline-guard vetting
+ // consults — and retro-check them against prototype-level descriptor
+ // keys installed BEFORE this class registered (module-init ordering
+ // must not create an unsound skip).
+ unsafe {
+ let count = field_count.min(crate::array::js_array_length(keys_array)) as usize;
+ let mut sso = [0u8; crate::value::SHORT_STRING_MAX_LEN];
+ for i in 0..count {
+ let v = crate::array::js_array_get(keys_array, i as u32);
+ if let Some(b) = crate::string::js_string_key_bytes(v, &mut sso) {
+ super::descriptor_state::note_declared_instance_field_name(b);
+ }
+ }
+ }
}
pub(crate) fn registered_class_keys_array(class_id: u32) -> Option<(*mut ArrayHeader, u32)> {
diff --git a/crates/perry-runtime/src/object/descriptor_state.rs b/crates/perry-runtime/src/object/descriptor_state.rs
index ad65412d068..79191092ff7 100644
--- a/crates/perry-runtime/src/object/descriptor_state.rs
+++ b/crates/perry-runtime/src/object/descriptor_state.rs
@@ -144,6 +144,11 @@ pub(crate) fn class_field_inline_guard_enabled() -> bool {
PERRY_CLASS_FIELD_INLINE_GUARD_DISABLED.load(Ordering::Relaxed) == 0
}
+#[cfg(test)]
+pub(crate) fn test_reset_class_field_inline_guard() {
+ PERRY_CLASS_FIELD_INLINE_GUARD_DISABLED.store(0, Ordering::Relaxed);
+}
+
/// #5654: flip the process-wide inline gate only when the descriptor target can
/// intercept a `this.field` access that the inline precheck cannot reject on
/// its own. Receiver-level installs are visible to the precheck via
@@ -165,13 +170,85 @@ pub(crate) fn class_field_inline_guard_enabled() -> bool {
///
/// The prototype-registry probes scan by value (O(#classes)); descriptor
/// installs are rare and never on the hot property path, so the scan cost is
-/// acceptable. Finer granularity (flip only when the key collides with a
-/// declared field of that class hierarchy) is possible follow-up work.
-pub(crate) fn disable_class_field_inline_guard_for_target(obj: usize) {
+/// acceptable.
+///
+/// #6759 C5a — per-KEY refinement (the follow-up the paragraph above used to
+/// promise): the inline fast path only ever compiles accesses to DECLARED
+/// instance fields, so a prototype-level install whose key names no declared
+/// field of any registered class cannot affect anything the inline path
+/// handles — babel-style method installs (`defineProperty(C.prototype,
+/// "render", …)`) no longer poison the process. The vetting set holds FNV
+/// hashes of every declared field name (harvested by
+/// `remember_class_keys_array` at class registration); a collision merely
+/// disables — never skips — so it stays conservative. Module-init ordering
+/// is covered in both directions: installs that precede a class's
+/// registration are recorded in [`PROTO_DESCRIPTOR_KEY_HASHES`] and
+/// retro-checked by [`note_declared_instance_field_name`] when the class
+/// arrives.
+pub(crate) fn disable_class_field_inline_guard_for_target(obj: usize, key: &str) {
if crate::array::object_prototype_addr_matches(obj)
|| class_registry::is_registered_class_prototype_object(obj)
|| class_registry::class_id_for_decl_prototype_object(obj).is_some()
{
+ let hash = super::key_bytes_hash(key.as_ptr(), key.len());
+ note_proto_descriptor_key_hash(hash);
+ if declared_field_name_hash_exists(hash) {
+ disable_class_field_inline_guard();
+ }
+ }
+}
+
+/// #6759 C5a: FNV hashes of every declared instance-field name across all
+/// registered classes. Written at class registration (cold), read at
+/// prototype-level descriptor installs (rare). Never pruned — class
+/// registrations are process-lifetime.
+static DECLARED_FIELD_NAME_HASHES: std::sync::RwLock