Skip to content
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

Refactor vm->mark_object_ary to be a linked list of WB protected objects #10179

Merged
merged 1 commit into from
Mar 6, 2024

Conversation

casperisfine
Copy link
Contributor

@casperisfine casperisfine commented Mar 5, 2024

Fix: #10171

This st_table is used to both mark and pin classes defined from the C API. But vm->mark_object_ary already does both much more efficiently.

Currently a Ruby process starts with 252 rooted classes, which uses 7224B in an st_table or 2016B in an RArray.

So a baseline of 5kB saved, but since mark_object_ary is preallocated with 1024 slots but only use 405 of them, it's a net 7kB save.

vm->mark_object_ary is also being refactored.

Prior to this changes, mark_object_ary was a regular RArray, but since this allows for references to be moved, it was marked a second time from rb_vm_mark() to pin these objects.

This has the detrimental effect of marking these references on every minors even though it's a mostly append only list.

But using a custom TypedData we can save from having to mark all the references on minor GC runs.

Addtionally, immediate values are now ignored and not appended to vm->mark_object_ary as it's just wasted space.

cc @peterzhu2118

@casperisfine casperisfine requested a review from a team as a code owner March 5, 2024 13:57

This comment has been minimized.

@casperisfine casperisfine force-pushed the immortal-classes-pin-list-type branch 4 times, most recently from 6f39f34 to 15756f3 Compare March 6, 2024 15:54
This `st_table` is used to both mark and pin classes
defined from the C API. But `vm->mark_object_ary` already
does both much more efficiently.

Currently a Ruby process starts with 252 rooted classes,
which uses `7224B` in an `st_table` or `2016B` in an `RArray`.

So a baseline of 5kB saved, but since `mark_object_ary` is
preallocated with `1024` slots but only use `405` of them,
it's a net `7kB` save.

`vm->mark_object_ary` is also being refactored.

Prior to this changes, `mark_object_ary` was a regular `RArray`, but
since this allows for references to be moved, it was marked a second
time from `rb_vm_mark()` to pin these objects.

This has the detrimental effect of marking these references on every
minors even though it's a mostly append only list.

But using a custom TypedData we can save from having to mark
all the references on minor GC runs.

Addtionally, immediate values are now ignored and not appended
to `vm->mark_object_ary` as it's just wasted space.
@casperisfine casperisfine force-pushed the immortal-classes-pin-list-type branch from 15756f3 to 8938769 Compare March 6, 2024 18:15
@casperisfine
Copy link
Contributor Author

So a baseline of 5kB saved, but since mark_object_ary is preallocated with 1024 slots but only use 405 of them, it's a net 7kB save.

I checked the number on a large application.defined_module_hash has 1k entires for a memsize of 28728B, and mark_object_ary 3242 entries. So there the saving is rougthly 20KB, and saves marking 4.2k objects on every minors.

@peterzhu2118 peterzhu2118 merged commit d4f3dcf into ruby:master Mar 6, 2024
97 checks passed
@peterzhu2118 peterzhu2118 deleted the immortal-classes-pin-list-type branch March 6, 2024 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants