Improve the Performance Characteristics of add_test_edges() #11092
+205
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #10950
Problem
The existing add_test_edges() function, executed on every
dbt build
, has poor performance characteristics. In the average case, it increases the number of edges in the graph by a factor of five. In extreme cases the factor can be 100 or more. This is causing slow run times and high memory usage for a small but important subset users. In the extreme case that kicked off this investigation, over 8,000,000 edges are being added, taking several minutes and consuming over a gigabyte of memory.Solution
Create a new version of the add_test_edges() function, with the same overall behavior (as defined and explained in the code comments) but taking a faster approach which also adds fewer edges.
For now, this new behavior is behind the --use-fast-test-edges flag, also accessible via the DBT_USE_FAST_TEST_EDGES=True env var.
The before and after results across a set of >7K real world graph structures is recorded in this spreadsheet.
For each graph in the test set, the old algorithm and the new algorithm were run separately to produce two result graphs. The transitive closure of the result graphs were calculated and confirmed to be equal, meaning they impose the exact same restrictions on execution order.
Across the test set, the new algorithm saved a median of 134 edges and an average of 8227 edges, emphasizing the outsized role played by the worst-case graphs. The new algorithm was strictly faster on graphs of appreciable size (>20 nodes). The average speedup was 17x with a median of 9x.
In the most extreme case, the new algorithm added ~96,000 edges instead of ~8,000,000, and it completed in 0.27s instead of 140s.
Checklist