Skip to content

Commit a631479

Browse files
committed
schema: short circuit subsystem selector
Problem: Fluxion profiling revealed hotspots related to string finding and string comparisons in `subsystem_selector_t`. Add metadata to the `subsystem_selector_t` to store the number of subsystems. Resource graphs most commonly have only one subsystem, so we can short-circuit expensive string finding and comparisons if m_subsystem_size == 1.
1 parent ea0749c commit a631479

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

resource/modules/resource_match.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,9 +1421,12 @@ static std::shared_ptr<f_resource_graph_t> create_filtered_graph (
14211421
edg_infra_map_t emap = get (&resource_relation_t::idata, g);
14221422

14231423
// Set vertex and edge filters based on subsystems to use
1424+
int subsys_size = ctx->db->metadata.roots.size ();
14241425
const multi_subsystemsS &filter = ctx->matcher->subsystemsS ();
1425-
subsystem_selector_t<vtx_t, f_vtx_infra_map_t> vtxsel (vmap, filter);
1426-
subsystem_selector_t<edg_t, f_edg_infra_map_t> edgsel (emap, filter);
1426+
subsystem_selector_t<vtx_t, f_vtx_infra_map_t> vtxsel (vmap, filter,
1427+
subsys_size);
1428+
subsystem_selector_t<edg_t, f_edg_infra_map_t> edgsel (emap, filter,
1429+
subsys_size);
14271430
fg = std::make_shared<f_resource_graph_t> (g, edgsel, vtxsel);
14281431
} catch (std::bad_alloc &e) {
14291432
errno = ENOMEM;

resource/reapi/bindings/c++/reapi_cli_impl.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,12 +310,15 @@ std::shared_ptr<f_resource_graph_t> resource_query_t::create_filtered_graph ()
310310
std::shared_ptr<f_resource_graph_t> fg = nullptr;
311311

312312
resource_graph_t &g = db->resource_graph;
313+
int subsys_size = db->metadata.roots.size ();
313314
vtx_infra_map_t vmap = get (&resource_pool_t::idata, g);
314315
edg_infra_map_t emap = get (&resource_relation_t::idata, g);
315316
const multi_subsystemsS &filter =
316317
matcher->subsystemsS ();
317-
subsystem_selector_t<vtx_t, f_vtx_infra_map_t> vtxsel (vmap, filter);
318-
subsystem_selector_t<edg_t, f_edg_infra_map_t> edgsel (emap, filter);
318+
subsystem_selector_t<vtx_t, f_vtx_infra_map_t> vtxsel (vmap, filter,
319+
subsys_size);
320+
subsystem_selector_t<edg_t, f_edg_infra_map_t> edgsel (emap, filter,
321+
subsys_size);
319322

320323
try {
321324
fg = std::make_shared<f_resource_graph_t> (g, edgsel, vtxsel);

resource/schema/resource_graph.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,19 @@ class subsystem_selector_t {
4545
public:
4646
subsystem_selector_t () {}
4747
~subsystem_selector_t () {}
48-
subsystem_selector_t (inframap &im, const multi_subsystemsS &sel)
48+
subsystem_selector_t (inframap &im, const multi_subsystemsS &sel,
49+
int subsys_size)
4950
{
5051
// must be lightweight -- e.g., bundled property map.
5152
m_imap = im;
5253
m_selector = sel;
54+
m_single_subsystem = (subsys_size == 1) ? true : false;
5355
}
5456
bool operator () (const graph_entity &ent) const {
57+
// Short circuit for single subsystem. This will be a common case.
58+
// TODO: make systems ints or enums for faster comparison and search.
59+
if (m_single_subsystem)
60+
return true;
5561
typedef typename boost::property_traits<inframap>::value_type infra_type;
5662
const infra_type &inf = get (m_imap, ent);
5763
const multi_subsystems_t &subsystems = inf.member_of;
@@ -72,6 +78,7 @@ class subsystem_selector_t {
7278
private:
7379
multi_subsystemsS m_selector;
7480
inframap m_imap;
81+
bool m_single_subsystem;
7582
};
7683

7784
using vtx_infra_map_t = boost::property_map<resource_graph_t, pinfra_t>::type;

resource/utilities/resource-query.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,11 +525,14 @@ static std::shared_ptr<f_resource_graph_t> create_filtered_graph (
525525
std::shared_ptr<f_resource_graph_t> fg = nullptr;
526526

527527
resource_graph_t &g = ctx->db->resource_graph;
528+
int subsys_size = ctx->db->metadata.roots.size ();
528529
vtx_infra_map_t vmap = get (&resource_pool_t::idata, g);
529530
edg_infra_map_t emap = get (&resource_relation_t::idata, g);
530531
const multi_subsystemsS &filter = ctx->matcher->subsystemsS ();
531-
subsystem_selector_t<vtx_t, f_vtx_infra_map_t> vtxsel (vmap, filter);
532-
subsystem_selector_t<edg_t, f_edg_infra_map_t> edgsel (emap, filter);
532+
subsystem_selector_t<vtx_t, f_vtx_infra_map_t> vtxsel (vmap, filter,
533+
subsys_size);
534+
subsystem_selector_t<edg_t, f_edg_infra_map_t> edgsel (emap, filter,
535+
subsys_size);
533536

534537
try {
535538
fg = std::make_shared<f_resource_graph_t> (g, edgsel, vtxsel);

0 commit comments

Comments
 (0)