From 63ffadc85230ca09b87461df810bf25a1786d7e4 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sat, 12 Sep 2026 22:18:18 +0200 Subject: [PATCH] Load the startup trace in a background thread. Opening and parsing on the browser main thread froze the tab for the whole load; the file selector path already loads in a worker thread, so boot now uses the same thread, progress modal, and error dialogs. --- profiler/src/main.cpp | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/profiler/src/main.cpp b/profiler/src/main.cpp index 565c1e22..fddbfbda 100644 --- a/profiler/src/main.cpp +++ b/profiler/src/main.cpp @@ -248,14 +248,21 @@ int main( int argc, char** argv ) }; if( FileExists( "/url.tracy" ) ) { - try - { - initFileOpen.reset( tracy::FileRead::Open( "/url.tracy" ) ); - } - catch( const tracy::NotTracyDump& ) { EM_ASM( alert( "The provided URL did not contain a valid Tracy trace." ) ); } - catch( const tracy::FileReadError& ) { EM_ASM( alert( "The trace from the provided URL could not be read." ) ); } - catch( const tracy::UnsupportedVersion& ) { EM_ASM( alert( "The trace from the provided URL requires a newer version of Tracy." ) ); } - catch( const tracy::LegacyVersion& ) { EM_ASM( alert( "The trace from the provided URL is in a legacy format." ) ); } + loadThread = std::thread( [] { + try + { + auto f = std::shared_ptr( tracy::FileRead::Open( "/url.tracy" ) ); + if( f ) + { + view.store( std::make_shared( RunOnMainThread, *f, SetWindowTitleCallback, SetupScaleCallback, AttentionCallback, s_achievements ), std::memory_order_release ); + } + } + catch( const tracy::NotTracyDump& ) { badVer.state = tracy::BadVersionState::BadFile; } + catch( const tracy::FileReadError& ) { badVer.state = tracy::BadVersionState::ReadError; } + catch( const tracy::UnsupportedVersion& e ) { badVer.state = tracy::BadVersionState::UnsupportedVersion; badVer.version = e.version; } + catch( const tracy::LegacyVersion& e ) { badVer.state = tracy::BadVersionState::LegacyVersion; badVer.version = e.version; } + catch( const tracy::LoadFailure& e ) { badVer.state = tracy::BadVersionState::LoadFailure; badVer.msg = e.msg; } + } ); } #endif if( argc == 2 ) @@ -384,17 +391,6 @@ int main( int argc, char** argv ) if( initFileOpen ) { -#ifdef __EMSCRIPTEN__ - try - { - view.store( std::make_shared( RunOnMainThread, *initFileOpen, SetWindowTitleCallback, SetupScaleCallback, AttentionCallback, s_achievements ), std::memory_order_release ); - } - catch( const std::exception& e ) - { - const std::string msg = std::string( "Failed to load the trace: " ) + e.what(); - EM_ASM( alert( UTF8ToString( $0 ) ), msg.c_str() ); - } -#else try { view.store( std::make_shared( RunOnMainThread, *initFileOpen, SetWindowTitleCallback, SetupScaleCallback, AttentionCallback, s_achievements ), std::memory_order_release ); @@ -405,7 +401,6 @@ int main( int argc, char** argv ) initFileOpen.reset(); _Exit( 1 ); } -#endif initFileOpen.reset(); } else if( connectTo )