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

feat(common): Introduce Chunk::lazy_previous in the LinkedChunk #4675

Merged
merged 1 commit into from
Feb 17, 2025

Conversation

Hywan
Copy link
Member

@Hywan Hywan commented Feb 17, 2025

This patch introduces Chunk::lazy_previous which is a key feature to support lazy-loading of a LinkedChunk. When a chunk is loaded, if it is the first, it keeps in memory whether it has a previous chunk or not. Thus, it is possible to insert new chunk in front of the LinkedChunk, and Updates will correctly continue to link chunks between them (with NewItemsChunk and NewGapChunk).

Example, imagine the following chunks: [0] <-> [1] <-> [2]. If [2] is the only one being loaded. Then its previous chunk, [1], is loaded from the store (because [2]'s previous is [1] in the store). Then [1] is replaced by [3] and [4]. We get this: [4] <-> [3] <-> [1] <-> [2]. If the Update::New*Chunk for [4] doesn't contain a previous, the store is out of sync: in the store, [4] has no previous, but [0] still has [1] for its next.

With this lazy_previous, the links are correctly computed.


@Hywan Hywan requested a review from a team as a code owner February 17, 2025 11:48
@Hywan Hywan requested review from bnjbvr and removed request for a team February 17, 2025 11:49
This patch introduces `Chunk::lazy_previous` which is a key feature to
support lazy-loading of a `LinkedChunk`. When a chunk is loaded, if it
is the first, it keeps in memory whether it has a previous chunk or not.
Thus, it is possible to insert new chunk in front of the `LinkedChunk`,
and `Update`s will correctly continue to link chunks between them (with
`NewItemsChunk` and `NewGapChunk`).

Example, imagine the following chunks: [0] <-> [1] <-> [2]. If [2] is
the only one being loaded. Then its previous chunk, [1], is loaded from
the store (because [2]'s previous is [1] in the store). Then [1] is
replaced by [3] and [4]. We get this: [4] <-> [3] <-> [1] <-> [2]. If
the `Update::New*Chunk` for [4] doesn't contain a `previous`, the store
is out of sync: in the store, [4] has no previous, but [0] still has [1]
for its `next`.

With this `lazy_previous`, the links are correctly computed.
@Hywan Hywan force-pushed the feat-common-linked-chunk-lazy-previous branch from 0d58ae3 to 00637f3 Compare February 17, 2025 11:51
Copy link

codecov bot commented Feb 17, 2025

Codecov Report

Attention: Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 85.84%. Comparing base (1c11497) to head (00637f3).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
crates/matrix-sdk-common/src/linked_chunk/mod.rs 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4675      +/-   ##
==========================================
- Coverage   85.84%   85.84%   -0.01%     
==========================================
  Files         292      292              
  Lines       33634    33638       +4     
==========================================
+ Hits        28873    28876       +3     
- Misses       4761     4762       +1     

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

Copy link
Member

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

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

Seeing how it's used in #4632, makes sense!

@Hywan Hywan merged commit 07f0017 into matrix-org:main Feb 17, 2025
42 checks passed
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.

2 participants