Potential optimization: eager nulling of Weak references

e6d4d36
Opened by Gábor Lehel at 2023-10-08 20:49:31

Apparently Swift does this:

When a weak reference is loaded, the runtime checks the target's state. If the target is a zombie, then it zeroes the weak reference, decrements the weak reference count, and returns nil.

In our world, this would mean Weak would store a Cell, which would be set to null in upgrade() if the strong count was found to be zero. This could allow the allocation to be freed earlier than it otherwise would be. I'm not sure if it would be a significant pessimization in any other respects?

(I just checked what other operations are available on Weak - this could also potentially be done in clone().)

  1. Triage: not aware of any changes

    Steve Klabnik at 2019-12-25 17:13:07