From 5eb057c7e2641b06436b3f8626bb79e4ed66bba0 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 5 Nov 2013 17:16:43 +0100 Subject: [PATCH] Optimize TimelineRenderer to not paint invisible items Check the dimensions of the window being painted to before actually painting the events and skip invisible ones. Some primitive profiling using QTime shows that the average time taken per event in TimelineRenderer::paint() is approximately halved by this patch when profiling the QML widget gallery example and expanding all categories in the timeline. drawSelectionBoxes() is not optimized because the number of selection boxes is expected to be so small that the overhead of the check might outweigh the performance gains of skipping events. Task-number: QTCREATORBUG-9982 Change-Id: I42e533c11e3a17f9d63b61ce5e4192c8f40e1be9 Reviewed-by: Kai Koehne --- src/plugins/qmlprofiler/timelinerenderer.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/plugins/qmlprofiler/timelinerenderer.cpp b/src/plugins/qmlprofiler/timelinerenderer.cpp index 77d895cf249..052e2ab4df9 100644 --- a/src/plugins/qmlprofiler/timelinerenderer.cpp +++ b/src/plugins/qmlprofiler/timelinerenderer.cpp @@ -118,6 +118,7 @@ void TimelineRenderer::drawItemsToPainter(QPainter *p, int modelIndex, int fromI int modelRowStart = 0; for (int mi = 0; mi < modelIndex; mi++) modelRowStart += m_profilerModelProxy->rowCount(mi); + QRect window = p->window(); for (int i = fromIndex; i <= toIndex; i++) { int x, y, width, height; @@ -125,6 +126,8 @@ void TimelineRenderer::drawItemsToPainter(QPainter *p, int modelIndex, int fromI int rowNumber = m_profilerModelProxy->getEventRow(modelIndex, i); y = (modelRowStart + rowNumber) * DefaultRowHeight; + if (y >= window.bottom()) + continue; width = m_profilerModelProxy->getDuration(modelIndex, i) * m_spacing; if (width < 1) @@ -132,6 +135,8 @@ void TimelineRenderer::drawItemsToPainter(QPainter *p, int modelIndex, int fromI height = DefaultRowHeight * m_profilerModelProxy->getHeight(modelIndex, i); y += DefaultRowHeight - height; + if (y + height < window.top()) + continue; // normal events p->setBrush(m_profilerModelProxy->getColor(modelIndex, i)); @@ -201,6 +206,7 @@ void TimelineRenderer::drawBindingLoopMarkers(QPainter *p, int modelIndex, int f QPen markerPen = QPen(QColor("orange"),2); QBrush shadowBrush = QBrush(QColor("grey")); QBrush markerBrush = QBrush(QColor("orange")); + QRect window = p->window(); p->save(); for (int i = fromIndex; i <= toIndex; i++) { @@ -228,8 +234,12 @@ void TimelineRenderer::drawBindingLoopMarkers(QPainter *p, int modelIndex, int f if (radius < 2) radius = 2; - // shadow int shadowoffset = 2; + if ((yfrom + radius + shadowoffset < window.top() && yto + radius + shadowoffset < window.top()) || + (yfrom - radius >= window.bottom() && yto - radius >= window.bottom())) + return; + + // shadow p->setPen(shadowPen); p->setBrush(shadowBrush); p->drawEllipse(QPoint(xfrom, yfrom + shadowoffset), radius, radius);