{{ message }}
Commit c5728b2
authored
fix(perf): avoid repeated scan of entire venv via packages_distributions() at import time (#16579)
packages_distributions() scans every installed package in the
environment to build a complete module-to-distribution mapping. In large
venvs (500+ packages, common with many google-cloud-* libs), this causes
multi-second import delays for google.api_core and every library that
depends on it.
This PR contains 2 changes:
- Wrap `packages_distributions()` with functools.cache so the expensive
O(n) scan happens at most once per process.
- Defer the package label resolution in `check_python_version()` so it
only runs when a warning is actually emitted, not on the common happy
path of a supported Python version.
Thank you for opening a Pull Request! Before submitting your PR, there
are a few things you can do to make sure it goes smoothly:
- [x] Make sure to open an issue as a
[bug/issue](https://github.com/googleapis/google-cloud-python/issues)
before writing your code! That way we can discuss the change, evaluate
designs, and agree on the general idea
- [ ] Ensure the tests and linter pass
- [x] Code coverage does not decrease (if any source code was changed)
- [x] Appropriate docs were updated (if necessary)
Fixes #15015 and #16552.1 parent f86bdfd commit c5728b2
1 file changed
Lines changed: 15 additions & 5 deletions
Lines changed: 15 additions & 5 deletions

0 commit comments