-
Notifications
You must be signed in to change notification settings - Fork 218
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: Client-side sorting for the room list #3068
Draft
Hywan
wants to merge
11
commits into
matrix-org:main
Choose a base branch
from
Hywan:feat-roomlist-sorting
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
+246
−41
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
`Store::get_rooms` worked as follows: For each room ID, call * Take the read lock for `rooms`, * For each entry in `rooms`, take the room ID (the key), then call `Store::get_room`, which… * Take the read lock for `rooms`, * Based on the room ID (the key), read the room (the value) from `rooms`. So calling `get_rooms` calls `get_room` for each room, which takes the lock every time. This patch modifies that by fetching the values (the rooms) directly from `rooms`, without calling `get_room`. In my benchmark, it took 1.2ms to read 10'000 rooms. Now it takes 542µs. Performance time has improved by -55.8%.
This patch updates `Store::rooms` from a `Arc<StdRwLock<BTreeMap<OwnedRoomId, Room>>>` to a `Arc<StdRwLock<Rooms>>` where `Rooms` is a new type that mimics a `BTreeMap` but that is observable. It uses an `ObservableVector` for saving us the costs of writing a new `ObservableMap` type in `eyeball-im`. It would have too much implications that are clearly not necessary. The major one being that an `ObservableMap` must emit `MapDiff`, but we expect `VectorDiff` everywhere in the SDK where rooms are observable. It would break too many API and too many projects. The benchmark is coming, but here are the results (for 10'000 rooms, extreme case): * `get_rooms` and `get_rooms_filtered` are twice faster (in practise, it means 650µs is saved per call), * `get_room` and `get_or_create_room` are 10% slower (in practise, it means 8-10ns is lost per call). Overall, I believe these results are acceptable, and even an improvement for the first one.
This patch rewrites `Rooms` to a generic `ObservableMap` struct. It also adds documentation and tests for this type.
This patch basically implements `ObservableMap::stream` which returns a batched stream of the values.
This patch renames `Store::get_rooms`, `::get_rooms_filtered` and `::get_room` to respectively `::rooms`, `::rooms_filtered` and `::room`. This `get_` prefix isn't really Rust idiomatic.
This patch implements a new `Store::rooms_stream` method that forwards the result of `ObservableMap::stream`.
This patch renames `Client::get_rooms`, `::get_rooms_filtered` and `::get_room` to respectively `::rooms`, `::rooms_filtered` and `::room`. This `get_` prefix isn't really Rust idiomatic.
…tion` is enabled. Running `cargo test -p matrix-sdk-base --features e2e-encryption` makes the code to fail to compile because `crate::latest_event` isn't defined. And indeed, it must be defined if `experimental-sliding-sync` is enabled, but also if `e2e-encryption` is enabled.
This patch implements `Client::rooms_stream`, which forwards the result of the recently added `Store::rooms_stream` method.
…iding-sync` aren't enabled.
This patch implements `Client::rooms_stream` by forwarding the result of `matrix_sdk_base::Client::rooms_stream`, and mapping the `matrix_sdk_base::Room` to `matrix_sdk::Room`.
Hywan
force-pushed
the
feat-roomlist-sorting
branch
from
January 31, 2024 15:04
64e8798
to
e0dc148
Compare
bnjbvr
reviewed
Feb 8, 2024
/// The (key, position) tuples. | ||
mapping: HashMap<K, usize>, | ||
|
||
/// The (position, value) tuples. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested change
/// The (position, value) tuples. | |
/// The values. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR is a work-in-progress. The idea is to provide client-side sorting for the rooms.
Blocked by:
SortBy
stream adapter jplatte/eyeball#43SlidingSyncRoom
tech debt #3079