Lazy load snowflake imports to improve performance#62365
Open
dwreeves wants to merge 2 commits intoapache:mainfrom
Open
Lazy load snowflake imports to improve performance#62365dwreeves wants to merge 2 commits intoapache:mainfrom
dwreeves wants to merge 2 commits intoapache:mainfrom
Conversation
53fc532 to
bc41432
Compare
558a677 to
ff6f899
Compare
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.
This PR lazy-loads Snowflake modules to improve performance when importing from
airflow.providers.snowflake.Because
SnowflakeSqlApiHookis a subclass ofSnowflakeHook, and the operators module imports theSnowflakeSqlApiHookglobally, this improves the load time of effectively every import fromairflow.providers.snowflakeand puts significantly less stress on the scheduler instance when parsing the DAG.See linked issue for full benchmarking code. TLDR, the cost of importing Snowflake modules is fairly significant:
The one thing I am unclear about is covering this with tests. I have written code before which asserts the non-import of a module, and I also see this in some cases in Airflow (see [1], [2]), however I'm not sure if that's done generally or if it makes sense here.
snowflakemodules insnowflake/hooks/snowflake.py#62362Was generative AI tooling used to co-author this PR?
(No AI code is present in this commit. However, I did use code generated by Claude to help benchmark the performance improvement.)