PCB_PARSER: add timeout for of 100 ms for refreshing the progress window.

The previously used line number threshold was causing (on some systems) severe slowdown in loading
due to relatively long redraw time of the progress bar window.
This commit is contained in:
Tomasz Wlostowski 2021-11-21 17:30:45 +01:00
parent a93c2c24fa
commit 90157db537
2 changed files with 17 additions and 7 deletions

View File

@ -111,13 +111,13 @@ void PCB_PARSER::init()
void PCB_PARSER::checkpoint()
{
const unsigned PROGRESS_DELTA = 250;
if( m_progressReporter )
{
TIME_PT curTime = CLOCK::now();
unsigned curLine = m_lineReader->LineNumber();
auto delta = std::chrono::duration_cast<TIMEOUT>( curTime - m_lastProgressTime );
if( curLine > m_lastProgressLine + PROGRESS_DELTA )
if( delta > std::chrono::milliseconds( 100 ) )
{
m_progressReporter->SetCurrentProgress( ( (double) curLine )
/ std::max( 1U, m_lineCount ) );
@ -125,7 +125,7 @@ void PCB_PARSER::checkpoint()
if( !m_progressReporter->KeepRefreshing() )
THROW_IO_ERROR( ( "Open cancelled by user." ) );
m_lastProgressLine = curLine;
m_lastProgressTime = curTime;
}
}
}

View File

@ -37,6 +37,7 @@
#include <pcb_lexer.h>
#include <kiid.h>
#include <chrono>
#include <unordered_map>
@ -77,7 +78,7 @@ public:
m_resetKIIDs( false ),
m_progressReporter( nullptr ),
m_lineReader( nullptr ),
m_lastProgressLine( 0 ),
m_lastProgressTime( std::chrono::steady_clock::now() ),
m_lineCount( 0 )
{
init();
@ -112,7 +113,7 @@ public:
{
m_progressReporter = aProgressReporter;
m_lineReader = aLineReader;
m_lastProgressLine = 0;
m_lastProgressTime = std::chrono::steady_clock::now();
m_lineCount = aLineCount;
}
@ -364,6 +365,15 @@ private:
typedef std::unordered_map< std::string, LSET > LSET_MAP;
typedef std::unordered_map< wxString, KIID > KIID_MAP;
///< The type of progress bar timeout
using TIMEOUT = std::chrono::milliseconds;
///< The clock used for the timestamp (guaranteed to be monotonic).
using CLOCK = std::chrono::steady_clock;
///< The type of the time stamps.
using TIME_PT = std::chrono::time_point<CLOCK>;
BOARD* m_board;
LAYER_ID_MAP m_layerIndices; ///< map layer name to it's index
LSET_MAP m_layerMasks; ///< map layer names to their masks
@ -380,7 +390,7 @@ private:
PROGRESS_REPORTER* m_progressReporter; ///< optional; may be nullptr
const LINE_READER* m_lineReader; ///< for progress reporting
unsigned m_lastProgressLine;
TIME_PT m_lastProgressTime; ///< for progress reporting
unsigned m_lineCount; ///< for progress reporting
// Group membership info refers to other Uuids in the file.