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

refactor(state store): use a single lock for all memory store accesses #4403

Merged
merged 1 commit into from
Dec 12, 2024

Conversation

bnjbvr
Copy link
Member

@bnjbvr bnjbvr commented Dec 11, 2024

The MemoryStore implementation of the StateStore has grown into a monster, with one lock per field. It's probably overkill, as individual fields don't need fine-grained locks like this; after all, accesses to the store shouldn't be reentrant in general.

Also allows us to get rid of some annoying trace logs, which is the reason why I was reminded of this problem.

Fixes #3720.

Let's see how Complement Crypto likes it…

@bnjbvr bnjbvr requested a review from a team as a code owner December 11, 2024 13:17
@bnjbvr bnjbvr requested review from stefanceriu and removed request for a team December 11, 2024 13:17
The `MemoryStore` implementation of the `StateStore` has grown into a
monster, with one lock per field. It's probably overkill, as individual
fields don't need fine-grained locks like this; after all, accesses to
the store shouldn't be reentrant in general.

Fixes #3720.
@bnjbvr bnjbvr force-pushed the bnjbvr/inner-state-memory-store branch from bf7c72d to e9fd733 Compare December 11, 2024 13:18
Copy link

codecov bot commented Dec 11, 2024

Codecov Report

Attention: Patch coverage is 95.02762% with 9 lines in your changes missing coverage. Please review.

Project coverage is 85.26%. Comparing base (0264e49) to head (e9fd733).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
crates/matrix-sdk-base/src/store/memory_store.rs 95.02% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4403      +/-   ##
==========================================
- Coverage   85.27%   85.26%   -0.02%     
==========================================
  Files         282      282              
  Lines       31209    31178      -31     
==========================================
- Hits        26615    26584      -31     
  Misses       4594     4594              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@stefanceriu stefanceriu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Way better! 🙌

/// Default if no other is configured at startup.
#[derive(Debug, Default)]
pub struct MemoryStore {
inner: RwLock<MemoryStoreInner>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, that's all there is to it, very nice 👏

@bnjbvr bnjbvr merged commit 3356e0c into main Dec 12, 2024
40 checks passed
@bnjbvr bnjbvr deleted the bnjbvr/inner-state-memory-store branch December 12, 2024 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

in-memory state store: use a single lock for all the data instead of one lock per field
2 participants