diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2018-05-14 15:21:10 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2018-05-16 14:57:59 +0000 |
commit | 7cb6dce1f3e140ea68d6b05281950f212fc99d38 (patch) | |
tree | bc31a800f853f54415823bd16c1f7fdb59f50e0c /src/qml/qml/qqmljavascriptexpression_p.h | |
parent | c248a32fe69dfe1c685105d0c6aeaeb15d7ba29f (diff) |
Remove bindings that have no dependencies
After the initial enabling of a binding we can quickly determine if
there is a chance whether this binding will be re-evaluated again in the
future as a consequence of dependency changes (properties or
translations). If that is not the case, then we can save memory by
removing that binding again.
One implementation consequence of this change is that such constant
bindings used with the "when" property of states require a proper
reference count increase, which was previously implicit through the
binding association with the target object.
In tst_qqmlecmascript a test that verifies that we don't create run-time
bindings for assignments of literal "null" to QObject pointer properties
now also covers the more complex case where we don't know the property
at parse time. We still evaluate the binding once though and perform one
property assignment.
Similarly on the QtQuick Designer Support API test side a binding such
as
x: Math.max(0, 200)
will not create a persistent binding anymore and needs a tweak to
remain.
On a large scale application this optimization saved up to 5% of all
bindings on start-up (~9000 of ~180000). On Linux x86-64 one binding is
approximately 144 bytes, so the savings are in the range of ~1.2 MB of
heap, as well as reduced fragmentation.
Task-number: QTBUG-64541
Change-Id: Id3653008346fdf36611f5b4c4e82f5f78b5319aa
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/qml/qqmljavascriptexpression_p.h')
-rw-r--r-- | src/qml/qml/qqmljavascriptexpression_p.h | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/qml/qml/qqmljavascriptexpression_p.h b/src/qml/qml/qqmljavascriptexpression_p.h index 9562476940..de3fba0774 100644 --- a/src/qml/qml/qqmljavascriptexpression_p.h +++ b/src/qml/qml/qqmljavascriptexpression_p.h @@ -171,13 +171,17 @@ protected: QForwardFieldList<QQmlJavaScriptExpressionGuard, &QQmlJavaScriptExpressionGuard::next> activeGuards; QForwardFieldList<QQmlJavaScriptExpressionGuard, &QQmlJavaScriptExpressionGuard::next> permanentGuards; + void setTranslationsCaptured(bool captured) { m_error.setFlagValue(captured); } + bool translationsCaptured() const { return m_error.flag(); } + private: friend class QQmlContextData; friend class QQmlPropertyCapture; friend void QQmlJavaScriptExpressionGuard_callback(QQmlNotifierEndpoint *, void **); friend class QQmlTranslationBinding; - QQmlDelayedError *m_error; + // m_error:flag1 translationsCapturedDuringEvaluation + QFlagPointer<QQmlDelayedError> m_error; QQmlContextData *m_context; QQmlJavaScriptExpression **m_prevExpression; @@ -208,12 +212,14 @@ public: static void registerQmlDependencies(QV4::Heap::QmlContext *context, const QV4::ExecutionEngine *engine, const QV4::CompiledData::Function *compiledFunction); void captureProperty(QQmlNotifier *, Duration duration = OnlyOnce); void captureProperty(QObject *, int, int, Duration duration = OnlyOnce, bool doNotify = true); + void captureTranslation() { translationCaptured = true; } QQmlEngine *engine; QQmlJavaScriptExpression *expression; QQmlJavaScriptExpression::DeleteWatcher *watcher; QFieldList<QQmlJavaScriptExpressionGuard, &QQmlJavaScriptExpressionGuard::next> guards; QStringList *errorString; + bool translationCaptured = false; }; QQmlJavaScriptExpression::DeleteWatcher::DeleteWatcher(QQmlJavaScriptExpression *e) @@ -260,18 +266,17 @@ void QQmlJavaScriptExpression::setScopeObject(QObject *v) bool QQmlJavaScriptExpression::hasError() const { - return m_error && m_error->isValid(); + return !m_error.isNull() && m_error->isValid(); } bool QQmlJavaScriptExpression::hasDelayedError() const { - return m_error; + return !m_error.isNull(); } inline void QQmlJavaScriptExpression::clearError() { - if (m_error) - delete m_error; + delete m_error.data(); m_error = nullptr; } |