Commit 39459f98 authored by Ulf Hermann's avatar Ulf Hermann

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: default avatarMilian Wolff <milian.wolff@kdab.com>
parent 7e8591c0
......@@ -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;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment