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_profiler/qqmlprofileradapter.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_profiler/qqmlprofileradapter.cpp')
-rw-r--r-- | src/plugins/qmltooling/qmldbg_profiler/qqmlprofileradapter.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/plugins/qmltooling/qmldbg_profiler/qqmlprofileradapter.cpp b/src/plugins/qmltooling/qmldbg_profiler/qqmlprofileradapter.cpp index 872dcbe718..688ced26ec 100644 --- a/src/plugins/qmltooling/qmldbg_profiler/qqmlprofileradapter.cpp +++ b/src/plugins/qmltooling/qmldbg_profiler/qqmlprofileradapter.cpp @@ -67,7 +67,7 @@ QQmlProfilerAdapter::QQmlProfilerAdapter(QQmlProfilerService *service, QQmlEngin // (see tst_qqmldebugtrace::trace() benchmark) static void qQmlProfilerDataToByteArrays(const QQmlProfilerData *d, QList<QByteArray> &messages) { - QByteArray data; + QQmlDebugPacket ds; Q_ASSERT_X(((d->messageType | d->detailType) & (1 << 31)) == 0, Q_FUNC_INFO, "You can use at most 31 message types and 31 detail types."); for (uint decodedMessageType = 0; (d->messageType >> decodedMessageType) != 0; @@ -81,7 +81,6 @@ static void qQmlProfilerDataToByteArrays(const QQmlProfilerData *d, QList<QByteA continue; //### using QDataStream is relatively expensive - QQmlDebugPacket ds; ds << d->time << decodedMessageType << decodedDetailType; switch (decodedMessageType) { @@ -99,7 +98,8 @@ static void qQmlProfilerDataToByteArrays(const QQmlProfilerData *d, QList<QByteA Q_ASSERT_X(false, Q_FUNC_INFO, "Invalid message type."); break; } - messages << ds.data(); + messages.append(ds.squeezedData()); + ds.clear(); } } } |