Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Reclaim one VALUE from rb_classext_t by shrinking super_classdepth #13319

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 1 commit into from
May 14, 2025

Conversation

casperisfine
Copy link
Contributor

By making super_classdepth uint16_t, classes and modules can now fit in 160B slots again.

The downside of course is that before super_classdepth was large enough we never had to care about overflow, as you couldn't realistically create enough classes to ever go over it.

With this change, while it is stupid, you could realistically create an ancestor chain containing 65k classes and modules.

@jhawthorn thoughts?

Also cc @tagomoris

@casperisfine casperisfine force-pushed the repack-rclass branch 4 times, most recently from f41fd0c to 147bd0a Compare May 13, 2025 18:20
@jhawthorn
Copy link
Member

Looks good to me!

65k classes and modules

It's actually only classes which are recorded in the superclasses Array, so this should be even less of an issue.

To me it also doesn't seem like namespaces should need to look up a separate superclass array per-namespace, since the superclass shouldn't be possible to change. I'll look at that in a separate PR.

@byroot
Copy link
Member

byroot commented May 14, 2025

To me it also doesn't seem like namespaces should need to look up a separate superclass array per-namespace

Yes, I think there are a bunch of things in classext_t that aren't namespace dependent and that we could avoid duplicating.

@@ -145,14 +145,16 @@ struct RClass {
};

// Assert that classes can be embedded in heaps[2] (which has 160B slot size)
// TODO: restore this assertion after removing several fields from rb_classext_t
// STATIC_ASSERT(sizeof_rb_classext_t, sizeof(struct RClass) + sizeof(rb_classext_t) <= 4 * RVALUE_SIZE);
// On 32bit platforms there is no variable width allocation so it doesn't matter.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't reenable that assertion if we merge: #13315

By making `super_classdepth` `uint16_t`, classes and modules can
now fit in 160B slots again.

The downside of course is that before `super_classdepth` was large
enough we never had to care about overflow, as you couldn't
realistically create enough classes to ever go over it.

With this change, while it is stupid, you could realistically
create an ancestor chain containing 65k classes and modules.
@byroot byroot merged commit 130d6aa into ruby:master May 14, 2025
80 checks passed
@casperisfine casperisfine deleted the repack-rclass branch May 14, 2025 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants