Optimize CTE-heavy lineage by sharing scopes via Rc - #366
Merged
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Owner
|
Thanks a lot for the PR, merged! THis will be included in the upcoming version |
Owner
|
I added some smallish improvements on top of it as GPT-5.6 xhigh indicated… Performance should be improved by 20-70% on a per-case basis. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
I've run into performance issue in my project - parsing lineage in a complex dbt project with many CTEs was taking too much time (relatively, still faster than dbt itself). So checked
lineage.rsand found the culprit:to_node_inner deep-cloned every ancestor CTE scope (full expression trees) at each recursion level, and resolve_qualified_column re-cloned the entire set again for every column reference resolved through a CTE.
This PR switches the lineage recursion plumbing to
Rc<Scope>.Also self-exclusion filter now has a cheap pre-check by name, while still falling back to expression equality.
I've run a benchmark (on M5 Pro):