-
-
Notifications
You must be signed in to change notification settings - Fork 66
Intern Property instances so reference equality is guaranteed #22
base: 1.16.x
Are you sure you want to change the base?
Conversation
Uses WeakReferences, so properties can be GC'd if necessary
…ableWeakReferenceToCachedProperty This allows mixins into Direction and Integer properties as well
I think the asymmetry of Object::equals is problematic. Is there any guarantee that WeakHashMap handles this the way you intend on all platforms? Could there be a platform where equals is called on the stored value leading to this breaking? |
I don't know of any implementations that don't call equals on the new object, but this change doesn't seem to have any downsides and it's always good to be cautious, especially with undefined behavior! |
Co-authored-by: 2No2Name <[email protected]>
src/main/java/me/jellysquid/mods/hydrogen/common/state/property/WeakPropertyCache.java
Outdated
Show resolved
Hide resolved
This prevents the GC from clearing the weak reference before we access it strongly
Why hasn't this been merged yet? Is it still not safe to use? |
This doesn't explain why it isn't merged yet (since I'm not the one who would need to merge it), but I'm not sure whether this is the right approach. Nothing is stopping modders from adding their own property implementations, which would not be interned by this PR and continue to cause issues. Maybe I just don't know Yarn names, but I would have expected one of the mixins to target the property implementation for generic |
@malte0811 That's true, if a mod implements You're right about the mixin, I need to make one that targets the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed on Discord: Mods adding their own property implementation is still a concern, but a purely theoretical one for the time being. So IMO it is reasonable to merge this and deal with the issue if and when it actually turns up (never, likely as not).
Closes #19