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/qquickdeferredexecute_p_p.h | 79 +++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 src/quicktemplates2/qquickdeferredexecute_p_p.h (limited to 'src/quicktemplates2/qquickdeferredexecute_p_p.h') diff --git a/src/quicktemplates2/qquickdeferredexecute_p_p.h b/src/quicktemplates2/qquickdeferredexecute_p_p.h new file mode 100644 index 00000000..2157d7ef --- /dev/null +++ b/src/quicktemplates2/qquickdeferredexecute_p_p.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Templates 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKDEFERREDEXECUTE_P_P_H +#define QQUICKDEFERREDEXECUTE_P_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include + +QT_BEGIN_NAMESPACE + +class QString; +class QObject; + +namespace QtQuickPrivate { + void executeDeferred(QObject *object, const QString &property); +} + +template +void quickExecuteDeferred(QObject *object, const QString &property, QQuickDeferredPointer &delegate) +{ + if (!delegate.isNull() || delegate.wasExecuted()) + return; + + delegate.setExecuting(true); + QtQuickPrivate::executeDeferred(object, property); + delegate.setExecuting(false); + + if (!delegate.isNull()) + delegate.setExecuted(); +} + +QT_END_NAMESPACE + +#endif // QQUICKDEFERREDEXECUTE_P_P_H -- 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/qquickdeferredexecute_p_p.h | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src/quicktemplates2/qquickdeferredexecute_p_p.h') diff --git a/src/quicktemplates2/qquickdeferredexecute_p_p.h b/src/quicktemplates2/qquickdeferredexecute_p_p.h index 2157d7ef..87124e48 100644 --- a/src/quicktemplates2/qquickdeferredexecute_p_p.h +++ b/src/quicktemplates2/qquickdeferredexecute_p_p.h @@ -57,21 +57,27 @@ class QString; class QObject; namespace QtQuickPrivate { - void executeDeferred(QObject *object, const QString &property); + void beginDeferred(QObject *object, const QString &property); + void completeDeferred(QObject *object, const QString &property); } template -void quickExecuteDeferred(QObject *object, const QString &property, QQuickDeferredPointer &delegate) +void quickBeginDeferred(QObject *object, const QString &property, QQuickDeferredPointer &delegate) { - if (!delegate.isNull() || delegate.wasExecuted()) - return; - + Q_ASSERT(delegate.isNull()); delegate.setExecuting(true); - QtQuickPrivate::executeDeferred(object, property); + QtQuickPrivate::beginDeferred(object, property); delegate.setExecuting(false); +} - if (!delegate.isNull()) - delegate.setExecuted(); +template +void quickCompleteDeferred(QObject *object, const QString &property, QQuickDeferredPointer &delegate) +{ + Q_ASSERT(!delegate.wasExecuted()); + delegate.setExecuting(true); + QtQuickPrivate::completeDeferred(object, property); + delegate.setExecuting(false); + delegate.setExecuted(); } QT_END_NAMESPACE -- cgit v1.2.3