chore: Reduce contention when using EszipV2
from multiple threads
#108
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
EszipV2
struct guards the module map behind anArc<Mutex>
. This is needed to support streaming sources while returning a result before finishing parsing. However, this means every operation that needs access to the module map has to contend for that same lock.This contention is inevitable while the streaming parsing is going on, but reads also contend with each other. This change avoids this read contention by switching the
Mutex
for aRwLock
.However, for pending modules, the
get_module_source
andget_module_source_map
methods add a waker for the current async context to the module's waker list, and this would need some write locking. To avoid this, this change also guards the waker list behind aMutex
, which also reduces the scope of that contention by making it specific to a module.With these changes, given a fully-resolved
EszipV2
which isn't modified, all operations on it are now guaranteed to be lock-free.