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

Fix slow chat switching 2: Electric Boogaloo #16279

Merged
merged 8 commits into from
Sep 25, 2024

Conversation

jrainville
Copy link
Member

Redo of #16178

Fixes #16132

In the previous PR, I was improving the slow chat switching by delaying the loading of the member list and the nkeeping it in memory.

After discussing with @micieslak , we agreed that it was making the code harder to understand and also didn't fix the root cause.

Turns out, the root cause is the SortFilterProxyModel and the preferredDisplayName property.

@caybro already has a PR improving it, but I pushed it one step further (sorry)

In my PR, I moved the preferredDisplayName property to the Nim side (this is the biggest speed up).

I also made it so that we populate the models in one go instead of one entry at a time (saves just a little bit on start, but it's something)

Finally, I made it so that we don't update the user model if not needed.
Basically, when a community channel is not encrypted is when we put all the members of the community in the member list. Those are the channels that are the slowest to switch to.
To help that, I made it so that if we are switching from an unencrypted channel to another unencrypted channel, we just don't update the member list.
This makes the channel switching instantaneous.

The only caveat of that approach is that we are putting a little bit of app logic in the QML. If that's a problem, I can move it to a property in the model.

fast-switching.webm

@status-im-auto
Copy link
Member

status-im-auto commented Sep 5, 2024

Jenkins Builds

Click to see older builds (20)
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 5aa80d3 #1 2024-09-05 21:02:53 ~7 min tests/nim 📄log
✔️ 5aa80d3 #1 2024-09-05 21:04:35 ~8 min macos/aarch64 🍎dmg
✔️ 5aa80d3 #1 2024-09-05 21:07:44 ~12 min tests/ui 📄log
✔️ 5aa80d3 #1 2024-09-05 21:11:02 ~15 min macos/x86_64 🍎dmg
✔️ 5aa80d3 #1 2024-09-05 21:11:18 ~15 min linux-nix/x86_64 📦tgz
✔️ 5aa80d3 #1 2024-09-05 21:14:45 ~19 min linux/x86_64 📦tgz
✔️ 5aa80d3 #1 2024-09-05 21:21:33 ~25 min windows/x86_64 💿exe
✔️ 3314d35 #2 2024-09-06 15:19:00 ~6 min macos/aarch64 🍎dmg
✔️ 3314d35 #2 2024-09-06 15:19:29 ~6 min tests/nim 📄log
✔️ 3314d35 #2 2024-09-06 15:23:28 ~10 min macos/x86_64 🍎dmg
✔️ 3314d35 #2 2024-09-06 15:24:27 ~11 min tests/ui 📄log
✔️ 3314d35 #2 2024-09-06 15:28:16 ~15 min linux-nix/x86_64 📦tgz
✔️ 3314d35 #2 2024-09-06 15:29:34 ~16 min linux/x86_64 📦tgz
✔️ 3314d35 #2 2024-09-06 15:35:36 ~22 min windows/x86_64 💿exe
✔️ 76f88c8 #3 2024-09-16 19:19:19 ~4 min macos/aarch64 🍎dmg
✔️ 76f88c8 #3 2024-09-16 19:20:59 ~6 min tests/nim 📄log
✔️ 76f88c8 #3 2024-09-16 19:26:12 ~11 min macos/x86_64 🍎dmg
✔️ 76f88c8 #3 2024-09-16 19:26:34 ~12 min tests/ui 📄log
✔️ 76f88c8 #3 2024-09-16 19:27:39 ~13 min linux-nix/x86_64 📦tgz
✔️ 76f88c8 #3 2024-09-16 19:30:43 ~16 min linux/x86_64 📦tgz
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 0d2faa9 #4 2024-09-24 18:06:47 ~4 min macos/aarch64 🍎dmg
✔️ 0d2faa9 #4 2024-09-24 18:08:48 ~6 min tests/nim 📄log
✔️ 0d2faa9 #4 2024-09-24 18:14:24 ~12 min tests/ui 📄log
✔️ 0d2faa9 #4 2024-09-24 18:14:47 ~12 min macos/x86_64 🍎dmg
✔️ 0d2faa9 #4 2024-09-24 18:15:59 ~14 min linux-nix/x86_64 📦tgz
✔️ 0d2faa9 #4 2024-09-24 18:18:08 ~16 min linux/x86_64 📦tgz
✔️ 955d95e #5 2024-09-25 14:00:03 ~4 min macos/aarch64 🍎dmg
✔️ 955d95e #5 2024-09-25 14:02:26 ~6 min tests/nim 📄log
✔️ 955d95e #5 2024-09-25 14:07:09 ~11 min tests/ui 📄log
✔️ 955d95e #5 2024-09-25 14:07:26 ~11 min macos/x86_64 🍎dmg
✔️ 955d95e #5 2024-09-25 14:10:38 ~15 min linux-nix/x86_64 📦tgz
✔️ 955d95e #5 2024-09-25 14:11:05 ~15 min linux/x86_64 📦tgz

@caybro caybro requested a review from alexjba September 5, 2024 21:07
Copy link
Member

@caybro caybro left a comment

Choose a reason for hiding this comment

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

Looks good in general!

Copy link
Contributor

@alexjba alexjba left a comment

Choose a reason for hiding this comment

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

Nicee! Glad to see this improvement is happening now 👍

Some doubts below, otherwise looks good to me!

@@ -117,6 +119,15 @@ QtObject:
result = newQVariant(item.pubKey)
of ModelRole.DisplayName:
result = newQVariant(item.displayName)
of ModelRole.PreferredDisplayName:
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: I'm wondering if there's a reason why it's not a member in the item object? 😄

We'll still need to take care of the dataChanged events for this new role and add this logic in all functions updating any of the user names. So IMO adding it as a member in the item object would be a nice way to go here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I prefer adding the PreferredDisplayName in dataChanged in the model, as it's way simpler than modifying all the modules that use this model.
Also, this way, the logic for the order which name is more important is only in one place.

}

rightPanel: Component {
id: userListComponent
UserListPanel {
id: userListPanel
readonly property bool isFullCommunityList: !root.chatContentModule || !root.chatContentModule.chatDetails || !root.chatContentModule.chatDetails.requiresPermissions
Copy link
Contributor

Choose a reason for hiding this comment

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

both isFullCommunityList and the Connections below have a dependency on the onChatContentModuleChanged signal. The implementation assumes that isFullCommunityList will always receive the signal first and its value is updated before handling the connection signal.
I'd redo this a little bit to remove any dependency on the signal order.

onChatContentModuleChanged: {
if (!root.chatContentModule ||
(userListPanel.usersModel != null && root.chatContentModule.chatDetails.belongsToCommunity && userListPanel.wasFullCommunityList && userListPanel.isFullCommunityList)) {
// If the previous channel had the full community list already, and we still need the whole list, just keep the old model
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if this isn't a bit dangerous..What if we delete the previous channel and the model is still cached here? I think it would lead to a crash since there are cases where the usersModel won't have a binding anymore on the proper chatContentModule, but the model reference assigned below.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tested it and it didn't crash, but I totally get your worry. I also think it can be dangerous.
I'm not sure how to make it safe though (apart from just removing this).

I know back in the day when we switched from one UserList for the whole community to having a specific lists per channel, I suggested having one model for all the members of the community that we can show for unpermissioned channels, and then permissioned channels could have their own model, but I know it wasn't done because it was too complex with the current architecture.

I'll try to figure out a way to do it now.
It would free a lot of memory and also fix the worry that it might crash.
I'll open a new issue for it though and work on it in another PR on top

Copy link
Member Author

Choose a reason for hiding this comment

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

Issue opened here #16288

Copy link
Member Author

Choose a reason for hiding this comment

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

PR opened here: #16301

We can wait until that new PR is merged before merging this one, that way we don't have to merge the possibly dangerous code.

Copy link
Member Author

Choose a reason for hiding this comment

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

Alright, I removed the dangerous code. I was tired of rebasing lal my PRs on this. I want to merge it hahaha

Copy link
Member

@caybro caybro left a comment

Choose a reason for hiding this comment

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

LGTM

@status-im-auto
Copy link
Member

@status-im-auto
Copy link
Member

Copy link
Member

@micieslak micieslak left a comment

Choose a reason for hiding this comment

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

Nice work! I'm happy to see such simplifications and performance boost in the same time!

I left some minor comments/suggestions only.

ui/app/AppLayouts/Chat/views/ChatView.qml Outdated Show resolved Hide resolved
self.beginInsertRows(modelIndex, first, last)
self.items.add(items)
self.endInsertRows()
self.countChanged()
Copy link
Member

Choose a reason for hiding this comment

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

As we have ModelCount attached property, there is no need to expose count from nim. Ideally we should just remove it from the model. Not necessary in this PR, just pointing for the future.

src/app/modules/shared_models/member_model.nim Outdated Show resolved Hide resolved
@status-im-auto
Copy link
Member

Copy link
Member

@micieslak micieslak left a comment

Choose a reason for hiding this comment

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

Nice!

@jrainville jrainville merged commit bb7e5be into master Sep 25, 2024
9 checks passed
@jrainville jrainville deleted the fix/slow-chat-switching-2 branch September 25, 2024 15:29
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.

Chat switching is sometimes slow and doesn't show the chat loader animation
5 participants