Skip to content
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

ConditionalWeakTable - don't link Containers when no entries are transferred #108941

Merged
merged 2 commits into from
Dec 6, 2024

Conversation

markples
Copy link
Member

@markples markples commented Oct 16, 2024

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.

Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-runtime-compilerservices
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Draft Pull Request was automatically closed for 30 days of inactivity. Please let us know if you'd like to reopen it.

@stephentoub stephentoub reopened this Dec 6, 2024
@stephentoub stephentoub marked this pull request as ready for review December 6, 2024 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants