You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ConditionalWeakTable - don't link Containers when no entries are transferred (#108941)
ConditionalWeakTable uses internal Container objects for the underlying table. Container entries are write-once because the read path is lock-free. When a Container is full, a new Container is allocated, entries are copied, and compaction can occur (if there aren't any currently live enumerators relying on specific indices).
A two-pass finalization scheme is used to free the entries (dependent handles) and then the Containers themselves. Finalization provides a guarantee that the Container is no longer in use, and the second pass accounts for finalization resurrection. Because entries can be duplicated across Containers, each Container contains a link to the one that replaces it.
This can _greatly_ extend the lifetime of Containers. (See #50683 and #108447.)
However, if the Container is empty and not being enumerated, there is no need to link it to the next Container. This PR handles that case, which includes microbenchmarks where single entries are added and removed from ConditionalWeakTable and equivalent tests where TransactionScope is functioning as a wrapper around a ConditionalWeakTable entry. Of course, this is only a partial solution because a single live entry or enumerator leaves the old behavior. Another caveat is that the finalization queue can be filled faster than it can be emptied, though this is more likely in microbenchmarks where other work isn't being done.
0 commit comments