From 553e3ca38b7ee02aafbed5526d5c75dd0ba34761 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Mon, 30 Apr 2018 13:44:44 +0200 Subject: [PATCH] Optimize mem plot reconstruction loop. --- server/TracyWorker.cpp | 47 +++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index a3f65cbe..9c7a07e7 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -1955,27 +1955,40 @@ void Worker::ReconstructMemAllocPlot() ptr->val = 0; ptr++; - while( aptr != aend && fptr != fend ) + if( aptr != aend && fptr != fend ) { - int64_t time; - if( aptr->timeAlloc < fptr->time ) + auto atime = aptr->timeAlloc; + auto ftime = fptr->time; + + for(;;) { - time = aptr->timeAlloc; - usage += int64_t( aptr->size ); - aptr++; + if( atime < ftime ) + { + usage += int64_t( aptr->size ); + assert( usage >= 0 ); + if( max < usage ) max = usage; + ptr->time = atime; + ptr->val = usage; + ptr++; + aptr++; + if( aptr == aend ) break; + atime = aptr->timeAlloc; + } + else + { + usage -= fptr->size; + assert( usage >= 0 ); + if( max < usage ) max = usage; + ptr->time = ftime; + ptr->val = usage; + ptr++; + fptr++; + if( fptr == fend ) break; + ftime = fptr->time; + } } - else - { - time = fptr->time; - usage -= fptr->size; - fptr++; - } - assert( usage >= 0 ); - if( max < usage ) max = usage; - ptr->time = time; - ptr->val = usage; - ptr++; } + while( aptr != aend ) { assert( aptr->timeFree < 0 );