-
Notifications
You must be signed in to change notification settings - Fork 15.5k
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
Ruby <2.7now uses WeakMap too, which prevents memory leaks. #8341
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ruby <2.7 does not allow non-finalizable objects to be WeakMap keys: https://bugs.ruby-lang.org/issues/16035 We work around this by using a secondary map for Ruby <2.7 which maps the non-finalizable integer to a distinct object. For now we accept that the entries in the secondary map wil never be collected. If this becomes a problem we can perform a GC pass every so often that looks at the contents of the object cache to decide what can be deleted from the secondary map.
Besides not leaking memory any more, this PR also runs the unit tests faster for Ruby 2.5. So I expect improved performance for Rubies prior to 2.7. |
gerben-s
approved these changes
Feb 25, 2021
This was referenced Mar 7, 2021
This was referenced Mar 12, 2021
Closed
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Ruby <2.7 does not allow non-finalizable objects to be WeakMap
keys: https://bugs.ruby-lang.org/issues/16035
We work around this by using a secondary map for Ruby <2.7 which
maps the non-finalizable integer to a distinct object.
For now we accept that the entries in the secondary map wil never
be collected. If this becomes a problem we can perform a GC pass
every so often that looks at the contents of the object cache to
decide what can be deleted from the secondary map.
This also changes the way that object pinning works. We pin objects
when they are frozen so they do not forget their frozen state.
Now we implement this with a simple array in Arena, instead of
making it part of the object cache.
Fixes: #8337