Skip to content

Commit ae90d48

Browse files
committed
traverser: optimize traversal for single-subsystem graphs
Problem: determining whether an edge crosses subsystem boundaries is a frequent check in Fluxion traversals. the check involves string comparison which can be expensive. The majority of current use cases involve only one subsystem, so a traversal won't cross subsystem boundaries. Furthermore, conditional checks are currently written such that the least likely outcome is checked first. Add a check to avoid string comparison in `in_subsystem`, and order conditional checks by decreasing likelihood.
1 parent a631479 commit ae90d48

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

resource/traversers/dfu_impl.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ void dfu_impl_t::tick ()
4343

4444
bool dfu_impl_t::in_subsystem (edg_t e, const subsystem_t &subsystem) const
4545
{
46-
return ((*m_graph)[e].idata.member_of.find (subsystem)
46+
// Short circuit for single subsystem. This will be a common case.
47+
// TODO: make systems ints or enums for faster comparison and search.
48+
if (m_graph_db->metadata.roots.size () == 1)
49+
return true;
50+
else
51+
return ((*m_graph)[e].idata.member_of.find (subsystem)
4752
!= (*m_graph)[e].idata.member_of.end ());
4853
}
4954

@@ -376,7 +381,7 @@ int dfu_impl_t::prime_exp (const subsystem_t &subsystem, vtx_t u,
376381
int rc = 0;
377382
f_out_edg_iterator_t ei, ei_end;
378383
for (tie (ei, ei_end) = out_edges (u, *m_graph); ei != ei_end; ++ei) {
379-
if (!in_subsystem (*ei, subsystem) || stop_explore (*ei, subsystem))
384+
if (stop_explore (*ei, subsystem) || !in_subsystem (*ei, subsystem))
380385
continue;
381386
if ((rc = prime_pruning_filter (subsystem,
382387
target (*ei, *m_graph), dfv)) != 0)
@@ -396,7 +401,7 @@ int dfu_impl_t::explore_statically (const jobmeta_t &meta, vtx_t u,
396401
int rc2 = -1;
397402
f_out_edg_iterator_t ei, ei_end;
398403
for (tie (ei, ei_end) = out_edges (u, *m_graph); ei != ei_end; ++ei) {
399-
if (!in_subsystem (*ei, subsystem) || stop_explore (*ei, subsystem))
404+
if (stop_explore (*ei, subsystem) || !in_subsystem (*ei, subsystem))
400405
continue;
401406

402407
bool x_inout = *excl;
@@ -479,7 +484,7 @@ int dfu_impl_t::explore_dynamically (const jobmeta_t &meta, vtx_t u,
479484
auto &outedges = iter->second;
480485
for (auto &kv : outedges) {
481486
edg_t e = kv.second;
482-
if (!in_subsystem (e, subsystem) || stop_explore (e, subsystem))
487+
if (stop_explore (e, subsystem) || !in_subsystem (e, subsystem))
483488
continue;
484489
vtx_t tgt = target (e, *m_graph);
485490
if (sat_types.find ((*m_graph)[tgt].type) != sat_types.end ())
@@ -770,7 +775,7 @@ int dfu_impl_t::dom_find_dfv (std::shared_ptr<match_writers_t> &w,
770775
m_trav_level++;
771776
for (auto &s : m_match->subsystems ()) {
772777
for (tie (ei, ei_end) = out_edges (u, *m_graph); ei != ei_end; ++ei) {
773-
if (!in_subsystem (*ei, s) || stop_explore (*ei, s))
778+
if (stop_explore (*ei, s) || !in_subsystem (*ei, s))
774779
continue;
775780
vtx_t tgt = target (*ei, *m_graph);
776781
rc = (s == dom)? dom_find_dfv (w, criteria, tgt, p_overridden)
@@ -826,7 +831,7 @@ int dfu_impl_t::enforce_dfv (vtx_t u, scoring_api_t &dfu)
826831

827832
for (auto &subsystem : m_match->subsystems ()) {
828833
for (tie (ei, ei_end) = out_edges (u, *m_graph); ei != ei_end; ++ei) {
829-
if (!in_subsystem (*ei, subsystem) || stop_explore (*ei, subsystem))
834+
if (stop_explore (*ei, subsystem) || !in_subsystem (*ei, subsystem))
830835
continue;
831836
vtx_t tgt = target (*ei, *m_graph);
832837
bool tgt_constrained = true;

0 commit comments

Comments
 (0)