From 87c063b112b8c7dc1a858af8406008da48b5260b Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Mon, 8 Jan 2024 00:21:42 +0100 Subject: [PATCH] Speedup room switching by forcing a bigger initial item size --- CMakeLists.txt | 8 +------- resources/qml/MessageView.qml | 2 +- resources/qml/TimelineBubbleMessageStyle.qml | 4 +++- resources/qml/TimelineDefaultMessageStyle.qml | 4 +++- resources/qml/delegates/PlayableMediaMessage.qml | 1 + src/main.cpp | 2 +- src/timeline/TimelineModel.cpp | 4 ++++ 7 files changed, 14 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 54dda226..7160ef96 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,6 @@ option(APPVEYOR_BUILD "Build on appveyor" OFF) option(CI_BUILD "Set when building in CI. Enables -Werror where possible" OFF) option(ASAN "Compile with address sanitizers" OFF) option(QML_DEBUGGING "Enable qml debugging" OFF) -option(COMPILE_QML "Compile Qml. It will make Nheko faster, but you will need to recompile it, when you update Qt." OFF) if(UNIX AND NOT APPLE) option(MAN "Build man page" ON) else() @@ -241,7 +240,6 @@ endif() # Discover Qt dependencies. # find_package(Qt6 6.5 COMPONENTS Core Widgets Gui LinguistTools Svg Multimedia Qml QuickControls2 REQUIRED) -#find_package(Qt6QuickCompiler) find_package(Qt6DBus) if(USE_BUNDLED_QTKEYCHAIN) @@ -633,11 +631,7 @@ endif() # # Bundle resources # -if(Qt6QuickCompiler_FOUND AND COMPILE_QML) - qtquick_compiler_add_resources(QRC resources/res.qrc) -else() - qt_add_resources(QRC resources/res.qrc) -endif() +qt_add_resources(QRC resources/res.qrc) if(APPLE) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework Foundation -framework Cocoa -framework UserNotifications") diff --git a/resources/qml/MessageView.qml b/resources/qml/MessageView.qml index 97a121eb..0b7a5a20 100644 --- a/resources/qml/MessageView.qml +++ b/resources/qml/MessageView.qml @@ -47,7 +47,7 @@ Item { anchors.rightMargin: scrollbar.interactive ? scrollbar.width : 0 // reuseItems still has a few bugs, see https://bugreports.qt.io/browse/QTBUG-95105 https://bugreports.qt.io/browse/QTBUG-95107 //onModelChanged: if (room) room.sendReset() - //reuseItems: true + reuseItems: true boundsBehavior: Flickable.StopAtBounds displayMarginBeginning: height / 4 displayMarginEnd: height / 4 diff --git a/resources/qml/TimelineBubbleMessageStyle.qml b/resources/qml/TimelineBubbleMessageStyle.qml index add701a1..2e038131 100644 --- a/resources/qml/TimelineBubbleMessageStyle.qml +++ b/resources/qml/TimelineBubbleMessageStyle.qml @@ -11,7 +11,9 @@ TimelineEvent { id: wrapper ListView.delayRemove: true width: chat.delegateMaxWidth - height: Math.max((section.item?.height ?? 0) + gridContainer.implicitHeight + reactionRow.implicitHeight + unreadRow.height, 10) + // We return a larger size for any item but the most bottom one, if it isn't initialized yet, since otherwise Qt will create way too many items. + // If we did that also for the first item, it would mess with the scroll location a bit, so we don't do it for that item. + height: Math.max((section.item?.height ?? 0) + ((gridContainer.implicitHeight < 1 && index != 0) ? 100 : gridContainer.implicitHeight) + reactionRow.implicitHeight + unreadRow.height, 10) anchors.horizontalCenter: ListView.view.contentItem.horizontalCenter //room: chatRoot.roommodel diff --git a/resources/qml/TimelineDefaultMessageStyle.qml b/resources/qml/TimelineDefaultMessageStyle.qml index a4466442..55c62b02 100644 --- a/resources/qml/TimelineDefaultMessageStyle.qml +++ b/resources/qml/TimelineDefaultMessageStyle.qml @@ -11,7 +11,9 @@ TimelineEvent { id: wrapper ListView.delayRemove: true width: chat.delegateMaxWidth - height: Math.max((section.item?.height ?? 0) + gridContainer.implicitHeight + reactionRow.implicitHeight + unreadRow.height, 10) + // We return a larger size for any item but the most bottom one, if it isn't initialized yet, since otherwise Qt will create way too many items. + // If we did that also for the first item, it would mess with the scroll location a bit, so we don't do it for that item. + height: Math.max((section.item?.height ?? 0) + ((gridContainer.implicitHeight < 1 && index != 0) ? 100 : gridContainer.implicitHeight) + reactionRow.implicitHeight + unreadRow.height, 10) anchors.horizontalCenter: ListView.view.contentItem.horizontalCenter //room: chatRoot.roommodel diff --git a/resources/qml/delegates/PlayableMediaMessage.qml b/resources/qml/delegates/PlayableMediaMessage.qml index 2a47d275..7c035922 100644 --- a/resources/qml/delegates/PlayableMediaMessage.qml +++ b/resources/qml/delegates/PlayableMediaMessage.qml @@ -35,6 +35,7 @@ Item { // TODO: Show error in overlay or so? roomm: room + // FIXME: This takes 500ms on my device, why and how can we avoid that? audioOutput: AudioOutput { muted: mediaControls.muted volume: mediaControls.desiredVolume diff --git a/src/main.cpp b/src/main.cpp index c90cbc2e..efe9333d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -47,7 +47,7 @@ #ifdef QML_DEBUGGING #include -QQmlDebuggingEnabler enabler; +QQmlTriviallyDestructibleDebuggingEnabler enabler; #endif #if HAVE_BACKTRACE_SYMBOLS_FD diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index a49dde3c..05a3c45c 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -997,6 +997,8 @@ TimelineModel::multiData(const QModelIndex &index, QModelRoleDataSpan roleDataSp return; } + // nhlog::db()->debug("MultiData called for {}", index.row()); + // HACK(Nico): fetchMore likes to break with dynamically sized delegates and reuseItems if (index.row() + 1 == rowCount() && !m_paginationInProgress) const_cast(this)->fetchMore(index); @@ -1025,6 +1027,8 @@ TimelineModel::multiData(const QString &id, return; } + // nhlog::db()->debug("MultiData called for {}", id.toStdString()); + auto event = events.get(id.toStdString(), relatedTo.toStdString()); if (!event) {