diff options
author | Jean Boussier <[email protected]> | 2025-05-28 09:34:37 +0200 |
---|---|---|
committer | Jean Boussier <[email protected]> | 2025-06-04 07:59:20 +0200 |
commit | bbd5a5a81d8bf3c7368d308c10f5752be25af6d1 () | |
tree | 5e9ec252371ab832175c44af0f1ca419317137e2 | |
parent | 625d6a9cbb0ed617b28115e4e3cb063e52481635 (diff) |
vm_getivar: normalize shape_id to ignore frozen state
Freezing an object changes its `shape_id` This is necessary so that `setivar` routines can use the `shape_id` as a cache key and save on checking the frozen status every time. However for `getivar` routines, this causes needless cache misses. By clearing that bit we increase hit rate in codepaths that see both frozen and mutable objects.
Notes: Merged: https://.com/ruby/ruby/pull/13289
-rw-r--r-- | shape.h | 9 | ||||
-rw-r--r-- | vm_insnhelper.c | 3 |
2 files changed, 10 insertions, 2 deletions
@@ -14,6 +14,7 @@ STATIC_ASSERT(shape_id_num_bits, SHAPE_ID_NUM_BITS == sizeof(shape_id_t) * CHAR_ #define SHAPE_ID_OFFSET_MASK (SHAPE_BUFFER_SIZE - 1) #define SHAPE_ID_FLAGS_MASK (shape_id_t)(((1 << (SHAPE_ID_NUM_BITS - SHAPE_ID_OFFSET_NUM_BITS)) - 1) << SHAPE_ID_OFFSET_NUM_BITS) #define SHAPE_ID_FL_FROZEN (SHAPE_FL_FROZEN << SHAPE_ID_OFFSET_NUM_BITS) typedef uint32_t redblack_id_t; @@ -110,6 +111,14 @@ RBASIC_SHAPE_ID(VALUE obj) #endif } static inline void RBASIC_SET_SHAPE_ID(VALUE obj, shape_id_t shape_id) { @@ -1215,14 +1215,13 @@ vm_getivar(VALUE obj, ID id, const rb_iseq_t *iseq, IVC ic, const struct rb_call { #if OPT_IC_FOR_IVAR VALUE val = Qundef; - shape_id_t shape_id; VALUE * ivar_list; if (SPECIAL_CONST_P(obj)) { return default_value; } - shape_id = RBASIC_SHAPE_ID(obj); switch (BUILTIN_TYPE(obj)) { case T_OBJECT: |