From 458eb65f730178bc93ba7b18f0e4dd2a13efad2e Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Wed, 6 Sep 2017 12:48:55 +0200 Subject: Buttons: defer the execution of the delegates In practice, deferring the execution of the delegates (until accessed) means that the default delegate item does not get created at all, when a custom control replaces it at construction time. Button { background: Rectangle { ... } } Before, such custom Button would never be faster than the original one, because the default delegate was first created and then thrown away at construction time. Originally, this was not considered a huge problem, because the plan was to keep the default delegates so light- weight that it wouldn't matter. However, then came the fancy styles with shadows and effects and thus, heavier default delegates. There's also a growing demand for more features, and the default delegates are slowly getting heavier... Now, after this patch, if you replace a heavy default delegate with a light and simple custom delegate, the result is a much faster control. For example, replacing Material style Button's background, which has a shadow effect, with a plain Rectangle gives a ~10x boost, because the default background with its heavy shadow effect is not executed at all. At the same time, deferring the execution of the default delegates avoids troubles with asynchronous incubation, because we don't need to destroy an object in the middle of the incubation process. Task-number: QTBUG-50992 Change-Id: I2274bff99b9ff126d3748278d58d859222910c98 Reviewed-by: Mitch Curtis --- src/quicktemplates2/qquickcontrol.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'src/quicktemplates2/qquickcontrol.cpp') diff --git a/src/quicktemplates2/qquickcontrol.cpp b/src/quicktemplates2/qquickcontrol.cpp index 908c0f42..51248745 100644 --- a/src/quicktemplates2/qquickcontrol.cpp +++ b/src/quicktemplates2/qquickcontrol.cpp @@ -48,6 +48,7 @@ #include "qquickpopup_p.h" #include "qquickpopupitem_p_p.h" #include "qquickapplicationwindow_p.h" +#include "qquickdeferredexecute_p_p.h" #include #include @@ -290,7 +291,7 @@ void QQuickControlPrivate::setContentItem_helper(QQuickItem *item, bool notify) return; q->contentItemChange(item, contentItem); - destroyDelegate(contentItem, q); + delete contentItem; contentItem = item; if (item) { @@ -300,7 +301,7 @@ void QQuickControlPrivate::setContentItem_helper(QQuickItem *item, bool notify) resizeContent(); } - if (notify) + if (notify && !contentItem.isExecuting()) emit q->contentItemChanged(); } @@ -933,6 +934,18 @@ QLocale QQuickControlPrivate::calcLocale(const QQuickItem *item) return QLocale(); } +void QQuickControlPrivate::executeContentItem() +{ + Q_Q(QQuickControl); + quickExecuteDeferred(q, QStringLiteral("contentItem"), contentItem); +} + +void QQuickControlPrivate::executeBackground() +{ + Q_Q(QQuickControl); + quickExecuteDeferred(q, QStringLiteral("background"), background); +} + /* Cancels incubation recursively to avoid "Object destroyed during incubation" (QTBUG-50992) */ @@ -1214,7 +1227,8 @@ void QQuickControl::setWheelEnabled(bool enabled) */ QQuickItem *QQuickControl::background() const { - Q_D(const QQuickControl); + QQuickControlPrivate *d = const_cast(d_func()); + d->executeBackground(); return d->background; } @@ -1224,7 +1238,7 @@ void QQuickControl::setBackground(QQuickItem *background) if (d->background == background) return; - QQuickControlPrivate::destroyDelegate(d->background, this); + delete d->background; d->background = background; if (background) { background->setParentItem(this); @@ -1233,7 +1247,8 @@ void QQuickControl::setBackground(QQuickItem *background) if (isComponentComplete()) d->resizeBackground(); } - emit backgroundChanged(); + if (!d->background.isExecuting()) + emit backgroundChanged(); } /*! -- cgit v1.2.3 From d9e740d2ccf8c1d3caacfcd95537718048e3a7ba Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 11 Dec 2017 21:49:53 +0100 Subject: Migitate the performance regression caused by deferred execution 458eb65f7 introduced a performance regression. Before 458eb65f7, qmlbench delegates_button.qml results were around 40 frames on a TX1. After 458eb65f, it dropped to 32. This patch is unfortunately not able to bring it on the original level, but at least improves the results to 37. For QQuickText, it is extremely important that implicitWidth() gets called before the component is completed, to avoid doing implicit size calculation multiple times. Deferred execution caused a performance regression by creating contentItem in "one go". We need to split the deferred execution to two parts so that bindings get first setup, and later enabled upon completion. This way, we utilize QQuickText's performance optimization for implicit size calculation. Task-number: QTBUG-50992 Change-Id: I4bf00af71b6d7dbf1d4b58b00fe547c6c321f8ed Reviewed-by: Mitch Curtis --- src/quicktemplates2/qquickcontrol.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'src/quicktemplates2/qquickcontrol.cpp') diff --git a/src/quicktemplates2/qquickcontrol.cpp b/src/quicktemplates2/qquickcontrol.cpp index 51248745..2f3791d5 100644 --- a/src/quicktemplates2/qquickcontrol.cpp +++ b/src/quicktemplates2/qquickcontrol.cpp @@ -934,16 +934,32 @@ QLocale QQuickControlPrivate::calcLocale(const QQuickItem *item) return QLocale(); } -void QQuickControlPrivate::executeContentItem() +static inline QString contentItemName() { return QStringLiteral("contentItem"); } + +void QQuickControlPrivate::executeContentItem(bool complete) { Q_Q(QQuickControl); - quickExecuteDeferred(q, QStringLiteral("contentItem"), contentItem); + if (contentItem.wasExecuted()) + return; + + if (!contentItem) + quickBeginDeferred(q, contentItemName(), contentItem); + if (complete) + quickCompleteDeferred(q, contentItemName(), contentItem); } -void QQuickControlPrivate::executeBackground() +static inline QString backgroundName() { return QStringLiteral("background"); } + +void QQuickControlPrivate::executeBackground(bool complete) { Q_Q(QQuickControl); - quickExecuteDeferred(q, QStringLiteral("background"), background); + if (background.wasExecuted()) + return; + + if (!background) + quickBeginDeferred(q, backgroundName(), background); + if (complete) + quickCompleteDeferred(q, backgroundName(), background); } /* @@ -1228,7 +1244,8 @@ void QQuickControl::setWheelEnabled(bool enabled) QQuickItem *QQuickControl::background() const { QQuickControlPrivate *d = const_cast(d_func()); - d->executeBackground(); + if (!d->background) + d->executeBackground(); return d->background; } -- cgit v1.2.3 From a03f18e026bb564237702cab477589b6916a0102 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Thu, 14 Dec 2017 15:50:32 +0100 Subject: Control: defer the execution of the background item Task-number: QTBUG-50992 Change-Id: I6372e143c68f0a5bf7212d759281acef3c81618e Reviewed-by: Mitch Curtis --- src/quicktemplates2/qquickcontrol.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/quicktemplates2/qquickcontrol.cpp') diff --git a/src/quicktemplates2/qquickcontrol.cpp b/src/quicktemplates2/qquickcontrol.cpp index 2f3791d5..26f1f7e8 100644 --- a/src/quicktemplates2/qquickcontrol.cpp +++ b/src/quicktemplates2/qquickcontrol.cpp @@ -1320,6 +1320,7 @@ void QQuickControl::classBegin() void QQuickControl::componentComplete() { Q_D(QQuickControl); + d->executeBackground(true); QQuickItem::componentComplete(); d->resizeContent(); if (!d->hasLocale) -- cgit v1.2.3 From 6b89293b99e763589181fd1f75470712f52cee3c Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Thu, 14 Dec 2017 20:00:46 +0100 Subject: Control: defer the execution of the content item Tumbler is excluded because test_customContentItemAtConstruction() starts failing if deferred execution is enabled for the content item. Task-number: QTBUG-50992 Change-Id: I11022c3c380311396453cf6229e068e4aae2d82a Reviewed-by: Mitch Curtis --- src/quicktemplates2/qquickcontrol.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/quicktemplates2/qquickcontrol.cpp') diff --git a/src/quicktemplates2/qquickcontrol.cpp b/src/quicktemplates2/qquickcontrol.cpp index 26f1f7e8..cfecc67c 100644 --- a/src/quicktemplates2/qquickcontrol.cpp +++ b/src/quicktemplates2/qquickcontrol.cpp @@ -281,6 +281,8 @@ void QQuickControlPrivate::resizeContent() QQuickItem *QQuickControlPrivate::getContentItem() { + if (!contentItem) + executeContentItem(); return contentItem; } @@ -1321,6 +1323,7 @@ void QQuickControl::componentComplete() { Q_D(QQuickControl); d->executeBackground(true); + d->executeContentItem(true); QQuickItem::componentComplete(); d->resizeContent(); if (!d->hasLocale) -- cgit v1.2.3