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(base) Client-side sorting, prelude: Implement Client::rooms_stream #3068

Merged
merged 13 commits into from
Jun 19, 2024

Conversation

Hywan
Copy link
Member

@Hywan Hywan commented Jan 29, 2024

This patch defines the basis to get client-side sorting inside the RoomList. The first step is to get a Stream of Room from a Client, and this is what this patch does! It's only for non-wasm targets.

It's built on top of #3561 to avoid Clippy warnings.


Blocked by:

@Hywan Hywan force-pushed the feat-roomlist-sorting branch 2 times, most recently from 54c587b to 0186631 Compare June 13, 2024 14:22
@Hywan Hywan force-pushed the feat-roomlist-sorting branch 3 times, most recently from 1375bbf to 20e62dc Compare June 17, 2024 09:49
@Hywan Hywan changed the title feat: Client-side sorting for the room list feat(base): Implement Client::rooms_stream Jun 17, 2024
@Hywan Hywan marked this pull request as ready for review June 17, 2024 09:58
@Hywan Hywan requested a review from a team as a code owner June 17, 2024 09:58
@Hywan Hywan requested review from bnjbvr and removed request for a team June 17, 2024 09:58
@Hywan Hywan force-pushed the feat-roomlist-sorting branch 2 times, most recently from 57d54a9 to ff04efb Compare June 17, 2024 12:23
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 implements a new `Store::rooms_stream` method that forwards
the result of `ObservableMap::stream`.
…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.
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.

Sweet, can you add some basic smoke test for rooms_stream() please?

crates/matrix-sdk-base/src/store/mod.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-base/src/store/mod.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-base/src/store/mod.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-base/src/store/mod.rs Outdated Show resolved Hide resolved
Some(position) => *position,
None => {
let value = default();
self.insert(key.to_owned(), value)
Copy link
Member

Choose a reason for hiding this comment

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

(Same comment as previous applies here too, we may be doing the lookup once too many)

crates/matrix-sdk-base/src/store/mod.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-base/src/store/mod.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-base/src/client.rs Outdated Show resolved Hide resolved
crates/matrix-sdk/src/client/mod.rs Show resolved Hide resolved
crates/matrix-sdk-base/src/store/mod.rs Outdated Show resolved Hide resolved
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`.
This patch creates an `ObservableMap` for `wasm32-unknown-unknown` which
simply wraps a `BTreeMap`, and without the `stream` method. Indeed, the
first implementation uses `eyeball_im::ObservableVector` which requires
`Send` and `Sync` on its values, which cannot compile to Wasm.
@Hywan Hywan requested a review from bnjbvr June 17, 2024 13:16
@matrix-org matrix-org deleted a comment from codecov bot Jun 18, 2024
Copy link

codecov bot commented Jun 18, 2024

Codecov Report

Attention: Patch coverage is 83.05085% with 10 lines in your changes missing coverage. Please review.

Project coverage is 83.80%. Comparing base (3ffeef5) to head (717c68d).
Report is 13 commits behind head on main.

Files Patch % Lines
crates/matrix-sdk-base/src/store/observable_map.rs 72.97% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3068      +/-   ##
==========================================
- Coverage   83.83%   83.80%   -0.04%     
==========================================
  Files         253      254       +1     
  Lines       25884    25931      +47     
==========================================
+ Hits        21701    21731      +30     
- Misses       4183     4200      +17     

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

@Hywan Hywan merged commit 6340eea into matrix-org:main Jun 19, 2024
38 checks passed
@Hywan Hywan changed the title feat(base): Implement Client::rooms_stream feat(base) Client-side sorting, prelude: Implement Client::rooms_stream Jun 21, 2024
@Hywan Hywan mentioned this pull request Jul 4, 2024
32 tasks
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