diff options
author | Ulf Hermann <ulf.hermann@theqtcompany.com> | 2016-03-03 13:38:27 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@theqtcompany.com> | 2016-03-11 09:19:01 +0000 |
commit | 6300f4dde0ab3279b18a0fb29f94cfe142557cba (patch) | |
tree | 4158af34ad0e812fa50f8b046f54439411ebc151 /src/plugins/qmltooling/qmldbg_quickprofiler/qquickprofileradapter.cpp | |
parent | 9ca9de7cbc8b045c19899987d6666576399af33d (diff) |
QmlDebug: Reuse packets instead of deleting and recreating them
This reduces memory churn as we don't have to reallocate the various
QPacket, QBuffer, QByteArray objects and their private classes all the
time. Also, subsequent packets often have similar sizes, which makes it
beneficial to preallocate the underlying byte array to the size of the
previous packet on clear(). In order not to carry the extra reserved
space in the lists passed to the debug server, we squeeze the byte
arrays before inserting them into the lists. That detaches and copies
them, which would have been done anyway when reusing the same packet
for the next message.
The result is a reduction in the number of temporary memory allocations
from QQmlProfilerServiceImpl::sendMessages() by about 75%.
Change-Id: Ief98cd7a93a2e8e840e111dee6b346cae00e06bf
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'src/plugins/qmltooling/qmldbg_quickprofiler/qquickprofileradapter.cpp')
-rw-r--r-- | src/plugins/qmltooling/qmldbg_quickprofiler/qquickprofileradapter.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/plugins/qmltooling/qmldbg_quickprofiler/qquickprofileradapter.cpp b/src/plugins/qmltooling/qmldbg_quickprofiler/qquickprofileradapter.cpp index 0f44ba3dc2..9a2afd367d 100644 --- a/src/plugins/qmltooling/qmldbg_quickprofiler/qquickprofileradapter.cpp +++ b/src/plugins/qmltooling/qmldbg_quickprofiler/qquickprofileradapter.cpp @@ -79,6 +79,7 @@ QQuickProfilerAdapter::~QQuickProfilerAdapter() static void qQuickProfilerDataToByteArrays(const QQuickProfilerData &data, QList<QByteArray> &messages) { + QQmlDebugPacket ds; Q_ASSERT_X(((data.messageType | data.detailType) & (1 << 31)) == 0, Q_FUNC_INFO, "You can use at most 31 message types and 31 detail types."); for (uint decodedMessageType = 0; (data.messageType >> decodedMessageType) != 0; @@ -91,8 +92,6 @@ static void qQuickProfilerDataToByteArrays(const QQuickProfilerData &data, if ((data.detailType & (1 << decodedDetailType)) == 0) continue; - //### using QDataStream is relatively expensive - QQmlDebugPacket ds; ds << data.time << decodedMessageType << decodedDetailType; switch (decodedMessageType) { @@ -145,7 +144,8 @@ static void qQuickProfilerDataToByteArrays(const QQuickProfilerData &data, Q_ASSERT_X(false, Q_FUNC_INFO, "Invalid message type."); break; } - messages << ds.data(); + messages.append(ds.squeezedData()); + ds.clear(); } } } |