Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of select_children() and select_parents() #11099

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changes/unreleased/Under the Hood-20241205-143144.yaml
Original file line number Diff line number Diff line change
@@ -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"
20 changes: 16 additions & 4 deletions core/dbt/graph/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading