Skip to content

Conversation

@Hywan
Copy link
Member

@Hywan Hywan commented Nov 18, 2025

This patch changes how SlidingSync enables long-polling. Long-polling with sliding sync is based on a timeout query parameter. If absent or 0, the server is expected to return immediately, otherwise the server waits up to timeout milliseconds before returning a response.

Before this patch, to define whether long-polling was necessary, we were relying on this simple algorithm (applied onto each sliding sync list):

  • if the list is Selective (i.e. it has a constant range), or if the list is fully loaded, then do long-polling,
  • otherwise, do not do long-polling.

This behaviour has been introduced in #3853.

As pointed in #5862, this algorithm is a bit annoying with our today's use of SlidingSync. Why? Because sometimes the server has nothing new to return despite the list is not Selective and is not fully-loaded. Thus, we need a more customizable mechanism, hence this set of patches.

First off, we introduce a new SlidingSyncListBuilder::requires_timeout method that accepts a user-defined function controlling whether a timeout is required or not, i.e. if the sliding sync client must do long-polling or not. The default function mimics the existing behaviour for compatibility purposes.

Second, RoomListService defines its own function, and uses it.

Finally, the test suite has been updated to test this new behaviour.


@Hywan Hywan requested a review from a team as a code owner November 18, 2025 13:58
@Hywan Hywan requested review from a team, poljar and stefanceriu and removed request for a team and poljar November 18, 2025 13:58
@codspeed-hq
Copy link

codspeed-hq bot commented Nov 18, 2025

CodSpeed Performance Report

Merging #5878 will not alter performance

Comparing Hywan:fix-5862 (aaca74b) with main (4ae82dd)

Summary

✅ 50 untouched

@codecov
Copy link

codecov bot commented Nov 18, 2025

Codecov Report

❌ Patch coverage is 90.90909% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.59%. Comparing base (4ae82dd) to head (aaca74b).
⚠️ Report is 12 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...rix-sdk/src/sliding_sync/list/request_generator.rs 62.50% 3 Missing ⚠️
crates/matrix-sdk/src/sliding_sync/list/mod.rs 92.85% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5878      +/-   ##
==========================================
- Coverage   88.60%   88.59%   -0.01%     
==========================================
  Files         363      363              
  Lines      102926   102943      +17     
  Branches   102926   102943      +17     
==========================================
+ Hits        91194    91207      +13     
- Misses       7490     7493       +3     
- Partials     4242     4243       +1     

☔ 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.

Looks great! 👏 Hope this is the last time we'll have to tweak it.

Comment on lines +232 to +243
match observable_state.get() {
// These are the states where we want an immediate response from the
// server, with no long-polling.
State::Init
| State::SettingUp
| State::Recovering
| State::Error { .. }
| State::Terminated { .. } => false,

// Otherwise we want long-polling if the list is fully-loaded.
State::Running => request_generator.is_fully_loaded(),
}
Copy link
Member

Choose a reason for hiding this comment

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

This ended up being so nice and clean 👏

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup!

This patch updates `SlidingSyncListInner::state` from a
`RwLock<Observable>` to a `SharedObservable`. It is semantically and
programmatically identical, but the API is simpler.
…_mode`.

This patch updates the documentation of `SlidingSyncList::set_sync_mode`
to remove an outdated reference to a `reset` method that no longer
exists.
This patch adds a new `SlidingSyncListBuilder::requires_timeout` method
that takes a function deciding whether the list requires a timeout, i.e.
if the list should trigger a `http::Request::timeout`, i.e. if it
deserves a long-polling or not.

The default behaviour is kept for compatibility purposes.
…vice`.

This patch uses the newly introduced
`SlidingSyncListBuilder::requires_timeout` to define when the
`RoomListService` must apply a long-polling depending on its state
machine.
This patch declares the type of the expected value for `assert pos`.
This patch tests whether long-polling is used for Sliding Sync requests
made by `RoomListService`.
@Hywan Hywan enabled auto-merge (rebase) November 19, 2025 09:26
@Hywan Hywan merged commit 2eb4323 into matrix-org:main Nov 19, 2025
52 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.

SlidingSync pos restoration and intial request timeouts

2 participants