From 9781da51e1683bd2cb826d1fd99ff2a60c5d3b1f Mon Sep 17 00:00:00 2001 From: Seth Hillbrand <seth@kipro-pcb.com> Date: Tue, 18 Feb 2025 17:57:14 -0800 Subject: [PATCH] Speed up the time it takes to GeneratePaths The loop processes nodes but skips those nodes that share the same parent. Because of this, we can get strong performance improvement from caching gains by sorting the vector first by the parents so that the inner loop is able to skip ahead without invalidating its cache --- pcbnew/drc/drc_creepage_utils.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pcbnew/drc/drc_creepage_utils.cpp b/pcbnew/drc/drc_creepage_utils.cpp index d10f4430f1..281457e174 100644 --- a/pcbnew/drc/drc_creepage_utils.cpp +++ b/pcbnew/drc/drc_creepage_utils.cpp @@ -2281,6 +2281,13 @@ void CREEPAGE_GRAPH::GeneratePaths( double aMaxWeight, PCB_LAYER_ID aLayer, bool && ( gn->m_type != GRAPH_NODE::TYPE::VIRTUAL ); } ); + std::sort( nodes.begin(), nodes.end(), + []( std::shared_ptr<GRAPH_NODE> gn1, std::shared_ptr<GRAPH_NODE> gn2 ) + { + return ( gn1->m_parent < gn2->m_parent ) || ( gn1->m_parent == gn2->m_parent + && gn1->m_net < gn2->m_net ); + } ); + auto processNodes = [&]( size_t i, size_t j ) -> bool { for( size_t ii = i; ii < j; ii++ )