[GODRIVER-3094] Use atomic.Value instead of sync.RWMutex to provide atomic read/writes to values Created: 11/Jan/24  Updated: 12/Jan/24

Status: Backlog
Project: Go Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Unknown
Reporter: Matt Dale Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Context

Go's atomic.Value type can perform a lot better than using a sync.RWMutex to guard values, especially when the use case is read-heavy and has a lot of concurrent contention. See some benchmarks here. We should use atomic.Value instead of a snc.RWMutex in those cases.

Definition of done

  • Replace all uses of sync.RWMutex to guard values that are read frequently and written infrequently with atomic.Value.

Pitfalls

atomic.Value is not as useful for write-heavy or read-write balanced use cases. We should only use it for read-heavy use cases.

Note that we can't use most of the new types in the atomic package because they were added with Go 1.19.


Generated at Thu Feb 08 08:40:03 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.