From 3a0e3fb8ef7972968dbd264a313bbeed420e305c Mon Sep 17 00:00:00 2001 From: Peter Allen Webb Date: Thu, 5 Dec 2024 14:22:37 -0500 Subject: [PATCH 1/2] Improve performance of select_children() and select_parents() --- core/dbt/graph/graph.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/core/dbt/graph/graph.py b/core/dbt/graph/graph.py index cf569f3547d..4d1e545cbd2 100644 --- a/core/dbt/graph/graph.py +++ b/core/dbt/graph/graph.py @@ -67,8 +67,14 @@ def select_children( while len(selected) > 0 and (max_depth is None or i < max_depth): next_layer: Set[UniqueId] = set() for node in selected: - next_layer.update(self.descendants(node, 1)) - next_layer = next_layer - children # Avoid re-searching + next_layer.update( + iter( + e[1] + for e in self.graph.out_edges(node) + if e[1] not in children + and self.filter_edges_by_type(e[0], e[1], "parent_test") + ) + ) children.update(next_layer) selected = next_layer i += 1 @@ -86,8 +92,14 @@ def select_parents( while len(selected) > 0 and (max_depth is None or i < max_depth): next_layer: Set[UniqueId] = set() for node in selected: - next_layer.update(self.ancestors(node, 1)) - next_layer = next_layer - parents # Avoid re-searching + next_layer.update( + iter( + e[0] + for e in self.graph.in_edges(node) + if e[0] not in parents + and self.filter_edges_by_type(e[0], e[1], "parent_test") + ) + ) parents.update(next_layer) selected = next_layer i += 1 From 3a7c52d0fbc4e6cf4427ef710f8d2621caa2a343 Mon Sep 17 00:00:00 2001 From: Peter Allen Webb Date: Thu, 5 Dec 2024 14:32:02 -0500 Subject: [PATCH 2/2] Add changelog entry. --- .changes/unreleased/Under the Hood-20241205-143144.yaml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changes/unreleased/Under the Hood-20241205-143144.yaml diff --git a/.changes/unreleased/Under the Hood-20241205-143144.yaml b/.changes/unreleased/Under the Hood-20241205-143144.yaml new file mode 100644 index 00000000000..10aa90a2b2a --- /dev/null +++ b/.changes/unreleased/Under the Hood-20241205-143144.yaml @@ -0,0 +1,7 @@ +kind: Under the Hood +body: Improve selection peformance by optimizing the select_children() and select_parents() + functions. +time: 2024-12-05T14:31:44.584216-05:00 +custom: + Author: peterallenwebb + Issue: "11099"