-
Notifications
You must be signed in to change notification settings - Fork 204
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
High CPU usage while typing #3372
Merged
laevandus
merged 1 commit into
develop
from
perf/typing-events-current-user-controller-recreation
Aug 14, 2024
Merged
High CPU usage while typing #3372
laevandus
merged 1 commit into
develop
from
perf/typing-events-current-user-controller-recreation
Aug 14, 2024
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
laevandus
added
🌐 SDK: StreamChat (LLC)
Tasks related to the StreamChat LLC SDK
⚡ Performance
An Issue or PR related to performance improvements
🤞 Ready For QA
A PR that is Ready for QA
labels
Aug 12, 2024
SDK Size
|
SDK Performance
|
laevandus
commented
Aug 12, 2024
martinmitrevski
approved these changes
Aug 12, 2024
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.
LGTM ✅
nuno-vieira
reviewed
Aug 12, 2024
Sources/StreamChat/Controllers/ChannelController/ChannelController.swift
Show resolved
Hide resolved
nuno-vieira
reviewed
Aug 12, 2024
Sources/StreamChat/Controllers/ChannelController/ChannelController.swift
Show resolved
Hide resolved
nuno-vieira
approved these changes
Aug 12, 2024
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.
LGTM! ✅
laevandus
force-pushed
the
perf/typing-events-current-user-controller-recreation
branch
from
August 13, 2024 06:26
e205a31
to
37c07fa
Compare
SDK Size
|
testableapple
added
🟢 QAed
A PR that was QAed
and removed
🤞 Ready For QA
A PR that is Ready for QA
labels
Aug 13, 2024
laevandus
force-pushed
the
perf/typing-events-current-user-controller-recreation
branch
from
August 14, 2024 07:17
37c07fa
to
030a3bd
Compare
Quality Gate passedIssues Measures |
laevandus
deleted the
perf/typing-events-current-user-controller-recreation
branch
August 14, 2024 08:00
Merged
glennposadas
added a commit
to fotonotes/stream-chat-swift
that referenced
this pull request
Sep 7, 2024
* main: (154 commits) Unblock release on workflow dispatch (GetStream#3389) [CI] Run release action on workflow dispatch (GetStream#3386) [CI] Do not unshallow branches on CI [CI] Do not unshallow branches on CI [CI] Update git config on merging develop and release branches [CI] Update git config on merging develop and release branches [CI] Pull origin release branch on release [CI] Pull origin release branch on release [CI] Fetch all branches on release (GetStream#3385) [CI] Fetch all branches on release (GetStream#3385) Bump 4.62.0 Store pending message along with regular messages (GetStream#3378) [CI] Set up a default base branch when automatically creating PRs (GetStream#3383) Fix reading the local database state just after the initial write (GetStream#3373) [CI] Add space to SDK size badge (GetStream#3379) Update channel type documentation to reflect allowed characters (GetStream#3377) Reuse CurrentChatUserController instead of recreating it when sending typing events (GetStream#3372) Run offline state sync in the background (GetStream#3367) [CI] Bump fastlane plugin version (GetStream#3376) [CI] Bump fastlane actions plugin (GetStream#3375) ...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
⚡ Performance
An Issue or PR related to performance improvements
🟢 QAed
A PR that was QAed
🌐 SDK: StreamChat (LLC)
Tasks related to the StreamChat LLC SDK
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.
🔗 Issue Links
Resolves PBE-5497
🎯 Goal
Reduce CPU usage caused by recreating
CurrentChatUserController
when sending typing events📝 Summary
ChatClient.UserSession
for reusing objects from connect to logoutCurrentChatUserController
for reading privacy settings🛠 Implementation
We check if we should send typing events using an internal property in the
ChatChannelController
which created a new instance of theCurrentChatUserController
. This is called often when typing to a channel. This led to high CPU usage because controller is created and the local database is read on every character change. If the current user has, for example, a lot of muted channels, then recreatingCurrentChatUser
gets really expensive.🎨 Showcase
iPhone 12 Pro Max (low power mode was on)
An account with 10 muted channels (important). I used Chewbacca.
shouldSendTypingEvents
shouldSendTypingEvents
does not spend ~66 ms per character change just for checking this property. Instead, there is a single ~56 ms cost once (or almost none if the shared controller had been already created. Currently it is created on demand.)🧪 Manual Testing Notes
☑️ Contributor Checklist