QmlProfiler: Optimize flame graph model

foreach() is slow in hot loops like these. Also, by moving frequently
used children to the front we reduce the effort to find them in
further iterations.

Change-Id: Ib5dceb82511fdd1cb59c50e1ab2485f5035fbef8
Reviewed-by: Milian Wolff <milian.wolff@kdab.com>
This commit is contained in:
Ulf Hermann
2017-02-21 10:42:18 +01:00
parent 7e8591c017
commit 39459f98e8

View File

@@ -136,7 +136,7 @@ void FlameGraphModel::loadEvent(const QmlEvent &event, const QmlEventType &type)
void FlameGraphModel::finalize()
{
foreach (FlameGraphData *child, m_stackBottom.children)
for (FlameGraphData *child : m_stackBottom.children)
m_stackBottom.duration += child->duration;
loadNotes(-1, false);
@@ -217,9 +217,19 @@ FlameGraphData::~FlameGraphData()
FlameGraphData *FlameGraphModel::pushChild(FlameGraphData *parent, const QmlEvent &data)
{
foreach (FlameGraphData *child, parent->children) {
QVector<FlameGraphData *> &siblings = parent->children;
for (auto it = siblings.begin(), end = siblings.end(); it != end; ++it) {
FlameGraphData *child = *it;
if (child->typeIndex == data.typeIndex()) {
++child->calls;
for (auto back = it, front = siblings.begin(); back != front;) {
--back;
if ((*back)->calls >= (*it)->calls)
break;
qSwap(*it, *back);
it = back;
}
return child;
}
}