8000 Get rid of frozen shapes by casperisfine · Pull Request #13289 · ruby/ruby · GitHub
[go: up one dir, main page]

Skip to content

Get rid of frozen shapes #13289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 4, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.
  • Loading branch information
byroot committed Jun 3, 2025
commit 3c14d2bb0a04bb334714f92f5a2d1d17de845129
9 changes: 9 additions & 0 deletions shape.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
#define SHAPE_ID_READ_ONLY_MASK (~SHAPE_ID_FL_FROZEN)

typedef uint32_t redblack_id_t;

Expand Down Expand Up @@ -110,6 +111,14 @@ RBASIC_SHAPE_ID(VALUE obj)
#endif
}

// Same as RBASIC_SHAPE_ID but with flags that have no impact
// on reads removed. e.g. Remove FL_FROZEN.
static inline shape_id_t
RBASIC_SHAPE_ID_FOR_READ(VALUE obj)
{
return RBASIC_SHAPE_ID(obj) & SHAPE_ID_READ_ONLY_MASK;
}

static inline void
RBASIC_SET_SHAPE_ID(VALUE obj, shape_id_t shape_id)
{
Expand Down
3 changes: 1 addition & 2 deletions vm_insnhelper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
shape_id_t shape_id = RBASIC_SHAPE_ID_FOR_READ(obj);

switch (BUILTIN_TYPE(obj)) {
case T_OBJECT:
Expand Down
0