diff --git a/profiler/src/profiler/TracyView.cpp b/profiler/src/profiler/TracyView.cpp index de96d5d9..6865cbec 100644 --- a/profiler/src/profiler/TracyView.cpp +++ b/profiler/src/profiler/TracyView.cpp @@ -715,10 +715,17 @@ bool View::DrawImpl() auto& threadHints = m_worker.GetPendingThreadHints(); if( !threadHints.empty() ) { + m_threadReinsert.reserve( threadHints.size() ); for( auto v : threadHints ) { auto it = std::find_if( m_threadOrder.begin(), m_threadOrder.end(), [v]( const auto& t ) { return t->id == v; } ); - if( it != m_threadOrder.end() ) m_threadOrder.erase( it ); // Will be added in the correct place later, like any newly appearing thread + if( it != m_threadOrder.end() ) + { + // Will be reinserted in the correct place later. + // A separate list is kept of threads that were already known to avoid having to figure out which one is missing in m_threadOrder. + m_threadReinsert.push_back( *it ); + m_threadOrder.erase( it ); + } } m_worker.ClearPendingThreadHints(); } diff --git a/profiler/src/profiler/TracyView.hpp b/profiler/src/profiler/TracyView.hpp index 4855f1f8..6f7b76de 100644 --- a/profiler/src/profiler/TracyView.hpp +++ b/profiler/src/profiler/TracyView.hpp @@ -386,6 +386,7 @@ private: unordered_flat_map m_gpuDrift; unordered_flat_map m_plotView; Vector m_threadOrder; + Vector m_threadReinsert; Vector m_threadDnd; tracy_force_inline bool& VisibleMsgThread( uint64_t thread ) diff --git a/profiler/src/profiler/TracyView_Timeline.cpp b/profiler/src/profiler/TracyView_Timeline.cpp index 010ce1ed..107fce4b 100644 --- a/profiler/src/profiler/TracyView_Timeline.cpp +++ b/profiler/src/profiler/TracyView_Timeline.cpp @@ -366,11 +366,19 @@ void View::DrawTimeline() if( threadData.size() != m_threadOrder.size() ) { m_threadOrder.reserve( threadData.size() ); - for( size_t i=m_threadOrder.size(); igroupHint, []( const auto& lhs, const auto& rhs ) { return lhs < rhs->groupHint; } ); - m_threadOrder.insert( it, threadData[i] ); + const ThreadData *td = i < numReinsert ? m_threadReinsert[i] : threadData[m_threadOrder.size()]; + auto it = std::find_if( m_threadOrder.begin(), m_threadOrder.end(), [td]( const auto t ) { return td->groupHint < t->groupHint; } ); + m_threadOrder.insert( it, td ); } + m_threadReinsert.clear(); } for( const auto& v : m_threadOrder ) {