Don't recalculate message list every frame.

This commit is contained in:
Bartosz Taudul 2020-07-12 15:26:05 +02:00
parent 29ac0169aa
commit 420bdd5854
2 changed files with 38 additions and 25 deletions

View File

@ -8527,11 +8527,14 @@ void View::DrawMessages()
size_t tsz = 0;
for( const auto& t : m_threadOrder ) if( !t->messages.empty() ) tsz++;
m_messageFilter.Draw( ICON_FA_FILTER " Filter messages", 200 );
const bool msgsChanged = msgs.size() != m_prevMessages;
if( msgsChanged ) m_prevMessages = msgs.size();
bool filterChanged = m_messageFilter.Draw( ICON_FA_FILTER " Filter messages", 200 );
ImGui::SameLine();
if( ImGui::Button( ICON_FA_BACKSPACE " Clear" ) )
{
m_messageFilter.Clear();
filterChanged = true;
}
ImGui::SameLine();
ImGui::Spacing();
@ -8549,6 +8552,7 @@ void View::DrawMessages()
ImGui::Checkbox( ICON_FA_IMAGE " Show frame images", &m_showMessageImages );
}
bool threadsChanged = false;
auto expand = ImGui::TreeNode( ICON_FA_RANDOM " Visible threads:" );
ImGui::SameLine();
ImGui::TextDisabled( "(%zu)", tsz );
@ -8563,6 +8567,7 @@ void View::DrawMessages()
{
VisibleMsgThread( t->id ) = true;
}
threadsChanged = true;
}
ImGui::SameLine();
if( ImGui::SmallButton( "Unselect all" ) )
@ -8571,6 +8576,7 @@ void View::DrawMessages()
{
VisibleMsgThread( t->id ) = false;
}
threadsChanged = true;
}
int idx = 0;
@ -8581,7 +8587,10 @@ void View::DrawMessages()
const auto threadColor = GetThreadColor( t->id, 0 );
SmallColorBox( threadColor );
ImGui::SameLine();
SmallCheckbox( m_worker.GetThreadName( t->id ), &VisibleMsgThread( t->id ) );
if( SmallCheckbox( m_worker.GetThreadName( t->id ), &VisibleMsgThread( t->id ) ) )
{
threadsChanged = true;
}
ImGui::PopID();
ImGui::SameLine();
ImGui::TextDisabled( "(%s)", RealToString( t->messages.size() ) );
@ -8594,9 +8603,10 @@ void View::DrawMessages()
ImGui::TreePop();
}
static Vector<uint32_t> msgList;
msgList.reserve( msgs.size() );
msgList.clear();
if( msgsChanged || filterChanged || threadsChanged )
{
m_msgList.reserve( msgs.size() );
m_msgList.clear();
if( m_messageFilter.IsActive() )
{
for( size_t i=0; i<msgs.size(); i++ )
@ -8608,7 +8618,7 @@ void View::DrawMessages()
const auto text = m_worker.GetString( msgs[i]->ref );
if( m_messageFilter.PassFilter( text ) )
{
msgList.push_back_no_space_check( uint32_t( i ) );
m_msgList.push_back_no_space_check( uint32_t( i ) );
}
}
}
@ -8621,11 +8631,12 @@ void View::DrawMessages()
const auto tid = m_worker.DecompressThread( v->thread );
if( VisibleMsgThread( tid ) )
{
msgList.push_back_no_space_check( uint32_t( i ) );
m_msgList.push_back_no_space_check( uint32_t( i ) );
}
}
}
m_visibleMessages = msgList.size();
m_visibleMessages = m_msgList.size();
}
bool hasCallstack = m_worker.GetCallstackFrameCount() != 0;
ImGui::Separator();
@ -8663,19 +8674,19 @@ void View::DrawMessages()
int idx = 0;
if( m_msgToFocus )
{
for( const auto& msgIdx : msgList )
for( const auto& msgIdx : m_msgList )
{
DrawMessageLine( *msgs[msgIdx], hasCallstack, idx );
}
}
else
{
ImGuiListClipper clipper( msgList.size() );
ImGuiListClipper clipper( m_msgList.size() );
while( clipper.Step() )
{
for( auto i=clipper.DisplayStart; i<clipper.DisplayEnd; i++ )
{
DrawMessageLine( *msgs[i], hasCallstack, idx );
DrawMessageLine( *msgs[m_msgList[i]], hasCallstack, idx );
}
}
}

View File

@ -330,6 +330,8 @@ private:
bool m_showMessageImages = false;
ImGuiTextFilter m_statisticsFilter;
int m_visibleMessages = 0;
size_t m_prevMessages = 0;
Vector<uint32_t> m_msgList;
bool m_disconnectIssued = false;
DecayValue<uint64_t> m_drawThreadMigrations = 0;
DecayValue<uint64_t> m_drawThreadHighlight = 0;