diff options
author | Milian Wolff <milian.wolff@kdab.com> | 2013-11-13 18:37:55 +0100 |
---|---|---|
committer | Milian Wolff <milian.wolff@kdab.com> | 2013-11-25 14:57:29 +0100 |
commit | a47a4fe5ea497133340b71cf6f48a640f414edbe (patch) | |
tree | 47763f82fd7e1118f29c351dc91431366cb7d871 /src | |
parent | 36f3243211f9ff28d8a84e17564a181629018112 (diff) | |
download | qtwebchannel-a47a4fe5ea497133340b71cf6f48a640f414edbe.tar.gz |
Optimize QtMetaObjectPublisher::classInfoForObject.
This includes two optimizations which have been forgotten to be
upstreamed before:
a) For the common case of property notify signals named "...Changed",
the string name is now not send anymore to the client. Instead, these
cases are special-cased and constructed on the fly. This drastically
reduces the size of Qt.init responses and property update messages.
b) Furthermore, do not list signals as methods, further reducing the
size of Qt.init response messages.
Together this shows a noticeable reduce of CPU instructions in the
benchmarks as recorded with perf:
benchmark_classInfo: down ~10%
benchmark_initializeClients: down ~2%
benchmark_propertyUpdates: down ~1%
Change-Id: I01e59f5c1dceedb893f7a3e3e127acb493baaa7f
Reviewed-by: Michael Bruning <michael.bruning@digia.com>
Reviewed-by: Pierre Rossi <pierre.rossi@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/qtmetaobjectpublisher.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/qtmetaobjectpublisher.cpp b/src/qtmetaobjectpublisher.cpp index 6d67df1..1922cd2 100644 --- a/src/qtmetaobjectpublisher.cpp +++ b/src/qtmetaobjectpublisher.cpp @@ -105,14 +105,23 @@ QVariantMap QtMetaObjectPublisher::classInfoForObject(QObject *object) const qWarning("Notify signal for property '%s' has %d parameters, expected zero or one.", prop.name(), numParams); } - propertyInfo.append(QString::fromLatin1(prop.notifySignal().name())); + // optimize: compress the common propertyChanged notification names, just send a 1 + const QByteArray ¬ifySignal = prop.notifySignal().name(); + static const QByteArray changedSuffix = QByteArrayLiteral("Changed"); + if (notifySignal.length() == changedSuffix.length() + propertyName.length() && + notifySignal.endsWith(changedSuffix) && notifySignal.startsWith(prop.name())) + { + propertyInfo.append(1); + } else { + propertyInfo.append(QString::fromLatin1(notifySignal)); + } } else { if (!prop.isConstant()) { qWarning("Property '%s'' of object '%s' has no notify signal and is not constant, " "value updates in HTML will be broken!", prop.name(), object->metaObject()->className()); } - propertyInfo.append(QString()); + propertyInfo.append(0); } propertyInfo.append(prop.read(object)); qtProperties.append(QVariant::fromValue(propertyInfo)); @@ -130,10 +139,10 @@ QVariantMap QtMetaObjectPublisher::classInfoForObject(QObject *object) const // property on the client side anyways. continue; } - if (method.access() == QMetaMethod::Public) - qtMethods << name; if (method.methodType() == QMetaMethod::Signal) qtSignals << name; + else if (method.access() == QMetaMethod::Public) + qtMethods << name; } for (int i = 0; i < metaObject->enumeratorCount(); ++i) { QMetaEnum enumerator = metaObject->enumerator(i); |