Cache subgraph driver connections for improved performance

This commit is contained in:
Jon Evans 2019-03-31 14:49:26 -04:00 committed by Wayne Stambaugh
parent f1882f333e
commit 2466b4363d
2 changed files with 23 additions and 18 deletions

View File

@ -290,12 +290,18 @@ void CONNECTION_GRAPH::Recalculate( SCH_SHEET_LIST aSheetList, bool aUncondition
#ifdef CONNECTIVITY_PROFILE #ifdef CONNECTIVITY_PROFILE
phase1.Stop(); phase1.Stop();
std::cout << "UpdateItemConnectivity() " << phase1.msecs() << " ms" << std::endl; std::cout << "UpdateItemConnectivity() " << phase1.msecs() << " ms" << std::endl;
PROF_COUNTER tde;
#endif #endif
// IsDanglingStateChanged() also adds connected items for things like SCH_TEXT // IsDanglingStateChanged() also adds connected items for things like SCH_TEXT
SCH_SCREENS schematic; SCH_SCREENS schematic;
schematic.TestDanglingEnds(); schematic.TestDanglingEnds();
#ifdef CONNECTIVITY_PROFILE
tde.Stop();
std::cout << "TestDanglingEnds() " << tde.msecs() << " ms" << std::endl;
#endif
buildConnectionGraph(); buildConnectionGraph();
} }
@ -645,6 +651,9 @@ void CONNECTION_GRAPH::buildConnectionGraph()
auto sheet = subgraph->m_sheet; auto sheet = subgraph->m_sheet;
auto connection = driver->Connection( sheet ); auto connection = driver->Connection( sheet );
// Cache the driving connection for later use
subgraph->m_driver_connection = connection;
// TODO(JE) This should live in SCH_CONNECTION probably // TODO(JE) This should live in SCH_CONNECTION probably
switch( driver->Type() ) switch( driver->Type() )
{ {
@ -709,7 +718,7 @@ void CONNECTION_GRAPH::buildConnectionGraph()
// Add strong drivers to the cache, for later checking against conflicts // Add strong drivers to the cache, for later checking against conflicts
auto driver = subgraph->m_driver; auto driver = subgraph->m_driver;
auto conn = subgraph->m_driver->Connection( subgraph->m_sheet ); auto conn = subgraph->m_driver_connection;
auto sheet = subgraph->m_sheet; auto sheet = subgraph->m_sheet;
auto name = conn->Name( true ); auto name = conn->Name( true );
@ -761,7 +770,7 @@ void CONNECTION_GRAPH::buildConnectionGraph()
if( !subgraph->m_driver || subgraph->m_strong_driver ) if( !subgraph->m_driver || subgraph->m_strong_driver )
continue; continue;
auto conn = subgraph->m_driver->Connection( subgraph->m_sheet ); auto conn = subgraph->m_driver_connection;
auto name = conn->Name(); auto name = conn->Name();
bool conflict = false; bool conflict = false;
@ -807,7 +816,7 @@ void CONNECTION_GRAPH::buildConnectionGraph()
if( candidate == subgraph || !candidate->m_driver || candidate->m_strong_driver ) if( candidate == subgraph || !candidate->m_driver || candidate->m_strong_driver )
continue; continue;
auto c_conn = candidate->m_driver->Connection( candidate->m_sheet ); auto c_conn = candidate->m_driver_connection;
auto check_name = c_conn->Name(); auto check_name = c_conn->Name();
if( check_name == name ) if( check_name == name )
@ -835,7 +844,7 @@ void CONNECTION_GRAPH::buildConnectionGraph()
if( !subgraph->m_driver ) if( !subgraph->m_driver )
continue; continue;
auto connection = subgraph->m_driver->Connection( subgraph->m_sheet ); auto connection = subgraph->m_driver_connection;
int code; int code;
auto name = subgraph->GetNetName(); auto name = subgraph->GetNetName();
@ -929,7 +938,7 @@ void CONNECTION_GRAPH::buildConnectionGraph()
if( candidate->m_sheet != sheet || !candidate->m_driver || candidate == subgraph ) if( candidate->m_sheet != sheet || !candidate->m_driver || candidate == subgraph )
continue; continue;
auto candidate_connection = candidate->m_driver->Connection( sheet ); auto candidate_connection = candidate->m_driver_connection;
if( !candidate_connection->IsNet() ) if( !candidate_connection->IsNet() )
continue; continue;
@ -995,7 +1004,7 @@ void CONNECTION_GRAPH::buildConnectionGraph()
if( subgraph && subgraph->m_driver ) if( subgraph && subgraph->m_driver )
{ {
auto parent = subgraph->m_driver->Connection( subgraph->m_sheet ); auto parent = subgraph->m_driver_connection;
pc->Connection( sheet )->Clone( *parent ); pc->Connection( sheet )->Clone( *parent );
} }
else else
@ -1022,7 +1031,7 @@ void CONNECTION_GRAPH::buildConnectionGraph()
continue; continue;
auto sheet = subgraph->m_sheet; auto sheet = subgraph->m_sheet;
auto connection = std::make_shared<SCH_CONNECTION>( *subgraph->m_driver->Connection( sheet ) ); auto connection = std::make_shared<SCH_CONNECTION>( *subgraph->m_driver_connection );
// Collapse power nets that are shorted together // Collapse power nets that are shorted together
@ -1055,7 +1064,7 @@ void CONNECTION_GRAPH::buildConnectionGraph()
continue; continue;
auto subsheet = subgraph_to_update->m_sheet; auto subsheet = subgraph_to_update->m_sheet;
auto conn = subgraph_to_update->m_driver->Connection( subsheet ); auto conn = subgraph_to_update->m_driver_connection;
if( conn->IsBus() || conn->NetCode() != code ) if( conn->IsBus() || conn->NetCode() != code )
continue; continue;
@ -1108,7 +1117,7 @@ void CONNECTION_GRAPH::buildConnectionGraph()
for( auto neighbor : kv.second ) for( auto neighbor : kv.second )
{ {
auto neighbor_conn = neighbor->m_driver->Connection( sheet ); auto neighbor_conn = neighbor->m_driver_connection;
try try
{ {
@ -1364,10 +1373,10 @@ void CONNECTION_GRAPH::buildConnectionGraph()
if( subgraph->m_dirty ) if( subgraph->m_dirty )
subgraph->m_dirty = false; subgraph->m_dirty = false;
if( subgraph->m_driver->Connection( subgraph->m_sheet )->IsBus() ) if( subgraph->m_driver_connection->IsBus() )
continue; continue;
int code = subgraph->m_driver->Connection( subgraph->m_sheet )->NetCode(); int code = subgraph->m_driver_connection->NetCode();
m_net_code_to_subgraphs_map[ code ].push_back( subgraph ); m_net_code_to_subgraphs_map[ code ].push_back( subgraph );
} }

View File

@ -112,6 +112,9 @@ public:
// Needed for m_UserUnits for now; maybe refactor later // Needed for m_UserUnits for now; maybe refactor later
SCH_EDIT_FRAME* m_frame; SCH_EDIT_FRAME* m_frame;
/// Cache for driver connection
SCH_CONNECTION* m_driver_connection;
/** /**
* This map stores pointers to other subgraphs on the same sheet as this one * This map stores pointers to other subgraphs on the same sheet as this one
* which should be connected to this one. * which should be connected to this one.
@ -146,11 +149,6 @@ public:
*/ */
void Recalculate( SCH_SHEET_LIST aSheetList, bool aUnconditional = false ); void Recalculate( SCH_SHEET_LIST aSheetList, bool aUnconditional = false );
/**
* Updates the connectivity graph based on a single item
*/
void RebuildGraphForItem( SCH_ITEM* aItem );
/** /**
* Returns a bus alias pointer for the given name if it exists (from cache) * Returns a bus alias pointer for the given name if it exists (from cache)
* *
@ -263,8 +261,6 @@ private:
* the driver is first selected by CONNECTION_SUBGRAPH::ResolveDrivers(), * the driver is first selected by CONNECTION_SUBGRAPH::ResolveDrivers(),
* and then the connection for the chosen driver is propagated to all the * and then the connection for the chosen driver is propagated to all the
* other items in the subgraph. * other items in the subgraph.
*
* @param aUnconditional is true if a full rebuild should be done
*/ */
void buildConnectionGraph(); void buildConnectionGraph();