-
Notifications
You must be signed in to change notification settings - Fork 502
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
Fix typing performance by avoiding expensive UI operations #5913
Conversation
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 👍 I would recommend to use UIView.bounds
though.
} | ||
|
||
- (void)viewDidLayoutSubviews | ||
{ | ||
[super viewDidLayoutSubviews]; | ||
BOOL didViewChangeFrame = !CGRectEqualToRect(lastViewFrame, self.view.frame); | ||
lastViewFrame = self.view.frame; |
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.
I do agree that viewDidLayoutSubviews
can be called for many reasons and very often indeed. Storing the last view frame is fine but I usually store the last bounds of the view as we're interested by the dimension of the view more than its position.
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.
Yea thats valid, changed.
📱 Scan the QR code below to install the build for this PR. If you can't scan the QR code you can install the build via this link: https://i.diawi.com/CY26t6 |
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 👍
Relates to #5906
Root cause
There are a few things going on here, and all related to an insane amount of spaghetti layout code in RoomViewController. Often time a simple sounding method will internally call other less innocent code, escalating the performance cost This is what I observed:
viewDidLayoutSubview
we will try to scroll back to the bottom, even if the size of the view has not really changed. The scrolling itself would be fine, but it is one of those methods that trigger a number of other heavy updates (e.g.updateViewControllerAppearanceOnRoomDataSourceState
). Note thatviewDidLayoutSubview
is called every time you type a character, which means that when typing fast we are essentially doing all of this expensive work many times per second.refreshRoomTitle
more often (I eat my words about no performance impact) has made this even worse, becauserefreshRoomTitle
is one of those very long methods with ton of side effects that are not easy to see. This is I believe also why we started seeing this issue worse in the latest release.Solution
The solution to this is patchwork, because the code is too messy for a simple fix:
MXFileStore
after typing every single characted (see Do not commit to file store after typing a single character matrix-org/matrix-ios-sdk#1422)Before my changes typing rapidly would consume around 33% of CPU on iPhone 13 Pro. After the changes it dropped to around 17%. We can certainly do more to bring this down.
I am not able to confirm yet whether this also solves the battery drain issue, but using CPU must be at least partly responsible for it.