Skip to content

Improve correctness for allocated object counts #13192

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

etiennebarrie
Copy link
Contributor

Currently the count of allocated object for a heap is incremented without regards to parallelism which leads to incorrect counts.

5.times.map do
  Ractor.new do
    10_000_000.times { Object.new }
  end
end
  .each(&:take)

p GC.stat(:total_allocated_objects)
p GC.count

Before

17419220
2486

After

50008126
2074

By maintaining a local counter in the ractor newobj cache, and only syncing atomically with some granularity, we can improve the correctness without increasing contention.

The allocated object count is also synced when the ractor is freed.

Currently the count of allocated object for a heap is incremented
without regards to parallelism which leads to incorrect counts.

By maintaining a local counter in the ractor newobj cache, and only
syncing atomically with some granularity, we can improve the correctness
without increasing contention.

The allocated object count is also synced when the ractor is freed.

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
Copy link

launchable-app bot commented Apr 28, 2025

All Tests passed!

✖️no tests failed ✔️61953 tests passed(5 flakes)

@ko1
Copy link
Contributor

ko1 commented Apr 28, 2025

Thank you, but rb_objspace_t will be modified for Ractor-local GC soon so this proposal will not work soon.

@ko1 ko1 closed this Apr 28, 2025
@byroot byroot reopened this Apr 29, 2025
@byroot
Copy link
Member

byroot commented Apr 29, 2025

I'd like us to consider this anyway. Even if it no longer work once Ractor-local GC is merged, until then fixing Ractor bugs allow us to explore further and find more bugs and issues to fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants