o-nikolas opened a new pull request, #31001: URL: https://github.com/apache/airflow/pull/31001
### Overview This PR aims to improve the time it takes to load/import the Celery executor module. ### Motivation Executors are imported in more places now that various compatibility checks are in core Airflow code (re: AIP-51). Also, decreasing import times is very important for the work of executors vending CLI commands (see #29055), since the CLI code in Airflow is particularly sensitive to slow imports (because all code is loaded fresh each time you run an individual Airflow CLI command). ### The changes Move some expensive typing related imports to be under TYPE_CHECKING. Also move some imports to runtime imports, closer to their usage. 1. Move some expensive typing related imports to be under TYPE_CHECKING. 1. Refactor expensive classes and methods (other than the CeleryExecutor) out of the `celery_executor.py` module into a utils module so that they are only loaded at runtime. 1. Also move some imports closer to their usage. ### Testing I benchmarked these changes by writing a script to import the executor module in a fresh python runtime and timing how long that takes (you can test this yourself quickly from a bash shell by doing something like `time python -c 'from airflow.executors.local_executor import CeleryExecutor'`). Then doing that in a loop for several samples (with some randomness in the order for fairness) both on main and on my development branch. ### Results  <!-- Thank you for contributing! Please make sure that your code changes are covered with tests. And in case of new features or big changes remember to adjust the documentation. Feel free to ping committers for the review! In case of an existing issue, reference it using one of the following: closes: #ISSUE related: #ISSUE How to write a good git commit message: http://chris.beams.io/posts/git-commit/ --> --- **^ Add meaningful description above** Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#pull-request-guidelines)** for more information. In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed. In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x). In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [newsfragments](https://github.com/apache/airflow/tree/main/newsfragments). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
