Commit 88b388e
perf(import): lazy-load heavy dependencies
END_PUBLIC
https://docs.google.com/document/d/1EpQaKqlX_OT4GrpbpqCLjtyF1pBcCTyu0sjXa8zWk8c/edit?usp=sharing
Deeply nested imports in new features (such as `events` pulling in `auth`, which eagerly imports `FastAPI`; and `functions` eagerly importing `OpenTelemetry`) silently added over 400ms to the baseline import time at HEAD, negating recent performance gains.
This CL prevents heavy external frameworks from accidentally polluting the top-level `import google.adk` path by:
- Deferring FastAPI by converting `auth/__init__.py` to a lazy-loading registry via `__getattr__`.
- Moving `AuthConfig` imports behind `if TYPE_CHECKING:` in `event_actions.py`, `functions.py`, and `base_credential_service.py`.
- Deferring `OpenTelemetry` by moving `from ..telemetry import _instrumentation` inside `run_async`/`run_live` and moving `from opentelemetry import trace` behind `if TYPE_CHECKING:`.
- Adding an `import_tree_audit.py` script and a formal RFC for import time bloat prevention.
Co-authored-by: George Weale <gweale@google.com>
PiperOrigin-RevId: 9524215691 parent 268815d commit 88b388e
1 file changed
Lines changed: 19 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| 30 | + | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
32 | | - | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
36 | 42 | | |
37 | 43 | | |
38 | 44 | | |
| |||
131 | 137 | | |
132 | 138 | | |
133 | 139 | | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
134 | 152 | | |
135 | 153 | | |
136 | 154 | | |
| |||
0 commit comments