Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Avoid taking a write lock in RegisteredType::{root,clone,drop} #7969

Conversation

fitzgen
Copy link
Member

@fitzgen fitzgen commented Feb 20, 2024

By moving the registration count into the Arc, that is pulling the Arc outwards from containing just the WasmFuncType to the registration count as well, and turning it into an atomic, we can manipulate the registration count without a write lock. Once that is done, we have the following:

  • RegisteredType::root only needs a read lock, not a write lock.

  • RegisteredType::clone, which used to need a write lock, doesn't need any locking anymore.

  • RegisteredType::drop doesn't need any locking most of the time. The exception is when this is this drop that moves the refcount to zero, in which case grabbing a write lock is still necessary to remove the type from the registry.

@fitzgen fitzgen requested a review from a team as a code owner February 20, 2024 22:04
@fitzgen fitzgen requested review from alexcrichton and removed request for a team February 20, 2024 22:04
By moving the registration count into the `Arc`, that is pulling the `Arc`
outwards from containing just the `WasmFuncType` to the registration count as
well, and turning it into an atomic, we can manipulate the registration count
without a write lock. Once that is done, we have the following:

* `RegisteredType::root` only needs a read lock, not a write lock.

* `RegisteredType::clone`, which used to need a write lock, doesn't need any
  locking anymore.

* `RegisteredType::drop` doesn't need any locking most of the time. The
  exception is when this is this drop that moves the refcount to zero, in which
  case grabbing a write lock is still necessary to remove the type from the
  registry.
@fitzgen fitzgen force-pushed the no-lock-to-clone-drop-registered-type branch from 6244e73 to effb5f0 Compare February 20, 2024 23:19
@alexcrichton alexcrichton added this pull request to the merge queue Feb 21, 2024
Merged via the queue into bytecodealliance:main with commit 2515b7a Feb 21, 2024
19 checks passed
@fitzgen fitzgen deleted the no-lock-to-clone-drop-registered-type branch February 21, 2024 00:52
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants