Skip to content

ChannelListController synchronize taking a long time #3682

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

Open
kylelol opened this issue May 14, 2025 · 9 comments
Open

ChannelListController synchronize taking a long time #3682

kylelol opened this issue May 14, 2025 · 9 comments
Labels
🔎 Investigating This issue is currently being investigated (Not reproducible yet) ⚡ Performance An Issue or PR related to performance improvements

Comments

@kylelol
Copy link

kylelol commented May 14, 2025

What did you do?

After connecting a user to our chat, I am creating my ChannelListController and manually calling synchronize in order to attempt to have all the channels loaded before the user navigates to our chat feature.

I'm noticing that the synchronize call takes about ~3.5-5 seconds on average to actually finish and call the completion. I am fetching the default page size 20 channels

I inspected the network requests and the one that fetches the channels finishes in about 300ms. I'm not sure exactly what the SDK does after that but taking 3.5-5 seconds for 20 channels that don't have a lot of messages feels like a bit too long.

If a user navigates to our chat experience very quickly, they sit there and wait in the loading state until it finishes.

What did you expect to happen?

I would expect the synchronize call to finish in 1-2 seconds if the network requests finishes in 300ms

What happened instead?

They synchronize call took about ~3.5-5 seconds.

This also seems to carry over to our search, sometimes the search takes a good 3-5 seconds to return a result, and it also seems to returns channels that are not in my channel list normally.

GetStream Environment

GetStream Chat version: 4.76
GetStream Chat frameworks: StreamChat, StreamChatSwiftUI
iOS version: 18.3
Swift version: 5
Xcode version: 16.2
Device: iPad simulator

Additional context

Here are some screenshots from Proxyman and my own logging to showcase what is going on:

This is the initial set of network requests that happen when the app is launched and we:

  • Call connect on the SDK
  • Call synchronize on our created ChannelListController
Image

This screenshot just showcases the response time of the channels call:

Image

This screenshot shows the time measurement of the synchronize call after we connect and create our channel list controller

Image
@nuno-vieira
Copy link
Member

Hi @kylelol,

What query are you using? In our Demo App, this takes on average about 1.5s, 2s at most.

Can also try to update the messageLimit parameter to see if this improves anything. Maybe change it to 5.

Best,
Nuno

@kylelol
Copy link
Author

kylelol commented May 15, 2025

@nuno-vieira This is what my query looks like:

        currentChannelController = client?.channelListController(
            query: ChannelListQuery(
                filter: .and([
                    .containMembers(userIds: [client?.currentUserId ?? ""]),
                    .equal("student_status", to: true)
                ])
            )
        )

Adding the message limit to 5 didn't have much of an impact, still takes about 3.8-4.0 seconds to synchronize. The only thing that has a meaningful impact is lowering the page size.

        currentChannelController = client?.channelListController(
            query: ChannelListQuery(
                filter: .and([
                    .containMembers(userIds: [client?.currentUserId ?? ""]),
                    .equal("student_status", to: true)
                ]),
                messagesLimit: 5
            )
        )

Since the network request happens quickly it seems the persistency layer is what is taking up the most time here. Are there logs I can enable to help further investigate?

Also found this to show the SDK is reporting similar numbers:

ℹ️ 2025-05-15 08:53:45.568 [INFO] [com.stream.sync-repository (QOS: UTILITY)] [SyncRepository.swift:195] [syncLocalState(lastSyncAt:completion:)] > Finished refreshing offline state (20 channels in 3.8 seconds)

@nuno-vieira
Copy link
Member

Hi @kylelol.

The log Finished refreshing offline state (20 channels in 3.8 seconds) is a bit suspicious, yes. But it is weird, that we can't reproduce this. Is this happening 100% of times with you?

Can you try removing this .equal("student_status", to: true), to see if there are any improvements?
Also, besides the messagesLimit, can you also do membersLimit: 5 as well?

Thank you!

@nuno-vieira nuno-vieira transferred this issue from GetStream/stream-chat-swiftui May 28, 2025
@nuno-vieira
Copy link
Member

Hi @kylelol, I've transfered the issue to the Low level SDK. Since this is not related to SwiftUI.

Have you had the opportunity to look into my comment above?

Thank you!

@nuno-vieira nuno-vieira added ⚡ Performance An Issue or PR related to performance improvements 🔎 Investigating This issue is currently being investigated (Not reproducible yet) labels May 28, 2025
@kylelol
Copy link
Author

kylelol commented May 30, 2025

@nuno-vieira Sorry for the delay, so it seems like the biggest impact is passing in the membersList parameter as 5. That drops the time from 4 seconds down to under 1.

Could you explain why that is necessary and what impact that might have? Or are we doing something wrong with our channels on the server side?

@nuno-vieira
Copy link
Member

nuno-vieira commented Jun 2, 2025

That looks like your member's data is slowing down our database layer. Can you share the HTTP response to my email at [email protected]? Make sure to share the HTTP request without any changes of the membersLimit.

Some additiona questions:

  • How many members per channel do you have?
  • Do you have any custom data in members?

Best,
Nuno

@kylelol
Copy link
Author

kylelol commented Jun 2, 2025

@nuno-vieira Yes I can, do you want the http request without the memberList: 5 I added and let it be the default?

Also this is the http request on the iOS client that fetches the channels right?

@nuno-vieira
Copy link
Member

@kylelol Yes, share the response without any limit. Yes this is the channel list query.

@kylelol
Copy link
Author

kylelol commented Jun 2, 2025

@nuno-vieira Sent!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔎 Investigating This issue is currently being investigated (Not reproducible yet) ⚡ Performance An Issue or PR related to performance improvements
Projects
None yet
Development

No branches or pull requests

2 participants