Andrushika opened a new pull request, #72567:
URL: https://github.com/apache/airflow/pull/72567

   ## Why
   
   Breeze sets `PYTHONDONTWRITEBYTECODE=true` in its containers, so every 
`airflow` process recompiles all mounted sources on import, through the bind 
mount. On macOS this is about 1s per CLI call and several seconds per component 
start. Writing `.pyc` next to the sources was disabled on purpose, it would 
leave root-owned files in the checkout.
   
   ## What
   
   Set `PYTHONPYCACHEPREFIX=/root/.cache/airflow-pycache` and mount an external 
docker volume `airflow-pycache-volume` there, same pattern as 
`mypy-cache-volume`. Only `breeze shell` and `breeze start-airflow` mount it 
and enable the cache. Other containers (`breeze testing`, CI) keep 
`PYTHONDONTWRITEBYTECODE=true`, so CI behaviour does not change. `breeze down 
--cleanup-pycache` removes the volume.
   
   ## Benchmark
   
   Measured inside the breeze container on macOS (Docker Desktop 28.4, 16 
cores, `--backend postgres --dev-mode`, CI image python3.10). Time is until the 
api-server answers its first HTTP request, with scheduler, triggerer and 
dag-processor starting at the same time.
   
   | step | before | after, first run | after, second run |
   |---|---|---|---|
   | `airflow db migrate` | 3.8s | 4.1s | 2.2s |
   | `airflow api-server -d` first response | 10.8s | 6.7s | 6.6s |
   | `airflow version` | 2.1s | 2.4s | 1.2s |
   | start-airflow critical path in container | 16.8s | 10.8s | 8.8s |
   
   The first run is slightly slower because the prefix also replaces the 
pre-built `.pyc` of site-packages, they are compiled once into the volume.
   
   One known limit, same as any normal Python setup: `.pyc` freshness is 
checked by source mtime and size, so an edit within the same second that keeps 
the file size would reuse the old bytecode. That is why the cleanup flag exists.
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes — Claude Code (Fable 5.1)
   
   Generated-by: Claude Code (Fable 5.1) following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)


-- 
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]

Reply via email to