From d683699ba983bd5af6cc3dfeab221f8d16261b7f Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 16 Jun 2019 16:41:52 +0200 Subject: [PATCH] Don't recalculate histogram bins every frame. This remedies slowdown that was only visible when a histogram of a large number of zones (~100 million) was displayed. The slowdown was caused by std::accumulate() calls over whole set of zones. --- server/TracyView.cpp | 146 +++++++++++++++++++++++-------------------- server/TracyView.hpp | 8 +++ 2 files changed, 87 insertions(+), 67 deletions(-) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index ad32cb9d..2dc9024c 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -6313,25 +6313,81 @@ void View::DrawFindZone() m_findZone.bins = std::make_unique( numBins ); m_findZone.binTime = std::make_unique( numBins ); m_findZone.selBin = std::make_unique( numBins ); + m_findZone.binCache.numBins = -1; } const auto& bins = m_findZone.bins; const auto& binTime = m_findZone.binTime; const auto& selBin = m_findZone.selBin; - memset( bins.get(), 0, sizeof( int64_t ) * numBins ); - memset( binTime.get(), 0, sizeof( int64_t ) * numBins ); - memset( selBin.get(), 0, sizeof( int64_t ) * numBins ); - - if( m_findZone.logTime ) + const auto distBegin = std::distance( sorted.begin(), sortedBegin ); + const auto distEnd = std::distance( sorted.begin(), sortedEnd ); + if( m_findZone.binCache.numBins != numBins || + m_findZone.binCache.distBegin != distBegin || + m_findZone.binCache.distEnd != distEnd ) { - const auto tMinLog = log10( tmin ); - const auto zmax = ( log10( tmax ) - tMinLog ) / numBins; + m_findZone.binCache.numBins = numBins; + m_findZone.binCache.distBegin = distBegin; + m_findZone.binCache.distEnd = distEnd; + + memset( bins.get(), 0, sizeof( int64_t ) * numBins ); + memset( binTime.get(), 0, sizeof( int64_t ) * numBins ); + memset( selBin.get(), 0, sizeof( int64_t ) * numBins ); + + if( m_findZone.logTime ) { + const auto tMinLog = log10( tmin ); + const auto zmax = ( log10( tmax ) - tMinLog ) / numBins; + { + auto zit = sortedBegin; + for( int64_t i=0; i= s && *end <= e ) selectionTime += timeSum; + } + zit = nit; + } + const auto timeSum = std::accumulate( zit, sortedEnd, int64_t( 0 ) ); + bins[numBins-1] += std::distance( zit, sortedEnd ); + binTime[numBins-1] += timeSum; + if( m_findZone.highlight.active && *zit >= s && *(sortedEnd-1) <= e ) selectionTime += timeSum; + } + + if( m_findZone.selGroup != m_findZone.Unselected ) + { + auto zit = m_findZone.selSort.begin(); + while( zit != m_findZone.selSort.end() && *zit == 0 ) ++zit; + for( int64_t i=0; i= s && *(sortedEnd-1) <= e ) selectionTime += timeSum; - } - if( m_findZone.selGroup != m_findZone.Unselected ) - { - auto zit = m_findZone.selSort.begin(); - while( zit != m_findZone.selSort.end() && *zit == 0 ) ++zit; - for( int64_t i=0; i= s && *end <= e ) selectionTime += timeSum; - } - zit = nit; - } - const auto timeSum = std::accumulate( zit, sortedEnd, int64_t( 0 ) ); - bins[numBins-1] += std::distance( zit, sortedEnd ); - binTime[numBins-1] += timeSum; - if( m_findZone.highlight.active && *zit >= s && *(sortedEnd-1) <= e ) selectionTime += timeSum; - - if( m_findZone.selGroup != m_findZone.Unselected ) - { - auto zit = m_findZone.selSort.begin(); - while( zit != m_findZone.selSort.end() && *zit == 0 ) ++zit; - for( int64_t i=0; i