From 8346b3e76ab8418b8c6dd7322d13db8abeb0a8e4 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Tue, 20 Feb 2018 14:55:37 +0100 Subject: [PATCH] preload the expander (the dialog) too Summary: when preloading, preload the expander as well, and reparent the full representation to it, so we have a scene schanged less. also do a create() of that window (may be worth to do create() automatically in every Dialog?) Test Plan: the first open is visibly a lot faster now Reviewers: #plasma, davidedmundson Reviewed By: #plasma, davidedmundson Subscribers: davidedmundson, plasma-devel, #frameworks Tags: #plasma, #frameworks Differential Revision: https://phabricator.kde.org/D10681 --- src/plasmaquick/appletquickitem.cpp | 46 ++++++++++++++------- src/plasmaquick/private/appletquickitem_p.h | 1 + 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/plasmaquick/appletquickitem.cpp b/src/plasmaquick/appletquickitem.cpp index 74ea195c9..139f61439 100644 --- a/src/plasmaquick/appletquickitem.cpp +++ b/src/plasmaquick/appletquickitem.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include @@ -288,6 +289,33 @@ QQuickItem *AppletQuickItemPrivate::createCompactRepresentationExpanderItem() return compactRepresentationExpanderItem; } +void AppletQuickItemPrivate::preloadForExpansion() +{ + qint64 time = 0; + if (QLoggingCategory::defaultCategory()->isInfoEnabled()) { + time = QDateTime::currentMSecsSinceEpoch(); + } + createFullRepresentationItem(); + if (!applet->isContainment() && + (!preferredRepresentation || + preferredRepresentation != fullRepresentation)) { + createCompactRepresentationExpanderItem(); + } + + if (compactRepresentationExpanderItem) { + compactRepresentationExpanderItem->setProperty("fullRepresentation", QVariant::fromValue(createFullRepresentationItem())); + } else { + fullRepresentationItem->setProperty("parent", QVariant::fromValue(q)); + } + + //preallocate nodes + if (fullRepresentationItem && fullRepresentationItem->window()) { + fullRepresentationItem->window()->create(); + } + + qCInfo(LOG_PLASMAQUICK) << "Applet" << applet->title() << "loaded after" << ( QDateTime::currentMSecsSinceEpoch() - time) << "msec"; +} + void AppletQuickItemPrivate::compactRepresentationCheck() { if (!qmlObject->rootObject()) { @@ -658,7 +686,7 @@ void AppletQuickItem::init() const int delay = qrand() % ((max + 1) - min) + min; QTimer::singleShot(delay, this, [this, delay]() { qCInfo(LOG_PLASMAQUICK) << "Delayed preload of " << d->applet->title() << "after" << (qreal)delay/1000 << "seconds"; - d->createFullRepresentationItem(); + d->preloadForExpansion(); }); } } @@ -790,27 +818,13 @@ void AppletQuickItem::setExpanded(bool expanded) } if (expanded) { - qint64 time = QDateTime::currentMSecsSinceEpoch(); - d->createFullRepresentationItem(); - if (!d->applet->isContainment() && - (!d->preferredRepresentation || - d->preferredRepresentation != d->fullRepresentation)) { - d->createCompactRepresentationExpanderItem(); - } - - if (d->compactRepresentationExpanderItem) { - d->compactRepresentationExpanderItem->setProperty("fullRepresentation", QVariant::fromValue(d->createFullRepresentationItem())); - } else { - d->fullRepresentationItem->setProperty("parent", QVariant::fromValue(this)); - } - + d->preloadForExpansion(); //increase on open, ignore containments if (d->s_preloadPolicy >= AppletQuickItemPrivate::Adaptive && !d->applet->isContainment()) { const int newWeight = qMin(d->preloadWeight() + AppletQuickItemPrivate::PreloadWeightIncrement, 100); d->applet->config().writeEntry(QStringLiteral("PreloadWeight"), newWeight); qCInfo(LOG_PLASMAQUICK) << "Increasing score for" << d->applet->title() << "to" << newWeight; } - qCInfo(LOG_PLASMAQUICK) << "Applet" << d->applet->title() << "opened after" << ( QDateTime::currentMSecsSinceEpoch() - time) << "msec"; } d->expanded = expanded; diff --git a/src/plasmaquick/private/appletquickitem_p.h b/src/plasmaquick/private/appletquickitem_p.h index a1056d597..c0b66672f 100644 --- a/src/plasmaquick/private/appletquickitem_p.h +++ b/src/plasmaquick/private/appletquickitem_p.h @@ -80,6 +80,7 @@ public: QQuickItem *createCompactRepresentationItem(); QQuickItem *createFullRepresentationItem(); QQuickItem *createCompactRepresentationExpanderItem(); + void preloadForExpansion(); //look into item, and return the Layout attached property, if found void connectLayoutAttached(QObject *item);