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(sdk): Do not send a room subscription that has already been sent #3874

Conversation

Hywan
Copy link
Member

@Hywan Hywan commented Aug 21, 2024

This patch should ideally be reviewed commit-by-commit.

The problem the patch is trying to solve is the following: in sliding sync, for every new room subscriptions, all the previous room subscriptions are part of the request to be send. This is a waste of bandwidth. This patch adds the following feature: when a room subscription has been sent, it won't be part of the next request anymore. All room subscriptions are kept in memory though, but they are marked as Applied instead of Pending (see the new RoomSubscriptionState type).


Hywan added 2 commits August 21, 2024 14:08
This patch adds the `commit` method on the `StickyData` trait. It is
called by `SlidingSyncStickyManager::maybe_commit` when we are sure the
data can be validated because of a valid response to the sent request.
This patch introduces the `RoomSubscriptionState` type, to represent
whether a room subscription has already been correctly sent to the
server.
@Hywan Hywan requested a review from a team as a code owner August 21, 2024 16:00
@Hywan Hywan requested review from bnjbvr and removed request for a team August 21, 2024 16:00
@Hywan Hywan mentioned this pull request Aug 21, 2024
32 tasks
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.

Makes sense!

crates/matrix-sdk/src/sliding_sync/sticky_parameters.rs Outdated Show resolved Hide resolved
crates/matrix-sdk/src/sliding_sync/sticky_parameters.rs Outdated Show resolved Hide resolved
crates/matrix-sdk/src/sliding_sync/mod.rs Show resolved Hide resolved
crates/matrix-sdk/src/sliding_sync/mod.rs Outdated Show resolved Hide resolved
Copy link

codecov bot commented Aug 21, 2024

Codecov Report

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

Project coverage is 84.10%. Comparing base (fbc9db9) to head (4110a1d).
Report is 18 commits behind head on main.

Files Patch % Lines
crates/matrix-sdk/src/sliding_sync/mod.rs 92.30% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3874   +/-   ##
=======================================
  Coverage   84.09%   84.10%           
=======================================
  Files         261      261           
  Lines       27656    27669   +13     
=======================================
+ Hits        23257    23270   +13     
  Misses       4399     4399           

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

@Hywan
Copy link
Member Author

Hywan commented Aug 22, 2024

Night thought: If sticky parameters are "disabled" (i.e. the server doesn't return the txn_id), the new mechanism introduced by this PR will have no effect. All room subscriptions will continue being marked as Pending, and will be sent entirely with all requests. It does solve the problem with SS proxy, but not with SS native.

Hywan added 3 commits August 23, 2024 09:02
This patch uses the new `RoomSubscriptionState` enum to filter
room subscriptions that have already been sent, when building a
`http::Request` with the sticky parameters.

By default, to start, a `http::request::RoomSubscription` is in the
state `Pending`, i.e. it's not sent yet. Once the sticky parameters are
committed, the state is updated to `Applied`. When the sticky parameters
are applied, only the `Pending` room subscriptions are added.

This patch contains one test to specifically assert this behaviour.
This patch fixes a test. It now fails, for my own personal joy. The new
behaviour is much better.
@Hywan Hywan force-pushed the fix-sdk-sliding-sync-room-subscriptions-mark-as-sent branch from 36640e0 to 4110a1d Compare August 23, 2024 07:03
@Hywan Hywan enabled auto-merge (rebase) August 23, 2024 07:05
@Hywan Hywan merged commit 3a1c374 into matrix-org:main Aug 23, 2024
40 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