You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I determined this is the correct repository in which to report this bug.
Summary of the issue
Context
Upgrading google-api-core from version 2.27.0 to 2.28.1 (and later) has caused a significant spike in CPU usage. While version 2.27.0 maintains a steady 20–40% utilization, versions 2.28.1 and above consistently reach 100% CPU consumption.
Expected Behavior:
Same consumption of CPU as in 2.27.0
Actual Behavior:
CPU consumption increased up to 5 times.
Hello @daniel-sanche I see performance degradation during usage. It is really a one-time cost for 2.27.0 . CPU usage spikes once and then drops to 0. But for version higher than 2.27.0 spike lasts during all imports. So each import causes CPU consumption up to 100%.
Isolated the slow call to be importlib.metadata.package_distributions(), which has to scann all package metadata in the venv and takes >1s. Code location:
To clarify: I believe the issue arises here: recent versions of api_core now include these symbols, and so we were calling the function doing these checks every time we imported a new library. The memoization in #16579 should alleviate that.
Activity
daniel-sanche commentedon Apr 3, 2026
Do you see a performance degredation during usage, or just at import time?
This seems likely related to the new version support check. But that should be a one-time cost
Crowiant commentedon Apr 7, 2026
Hello @daniel-sanche I see performance degradation during usage. It is really a one-time cost for 2.27.0 . CPU usage spikes once and then drops to 0. But for version higher than 2.27.0 spike lasts during all imports. So each import causes CPU consumption up to 100%.
bonauer-pf commentedon Apr 8, 2026
This is likely the same regression that also leads to #15015, which is only reproducible in large venvs.
We are also affected by this, and every google cloud library takes 3-4s to import since the version bump, inflating our total startup times by >10s.
bonauer-pf commentedon Apr 8, 2026
Isolated the slow call to be
importlib.metadata.package_distributions(), which has to scann all package metadata in the venv and takes >1s. Code location:google-cloud-python/packages/google-api-core/google/api_core/_python_version_support.py
Line 159 in 281eaae
This gets called at import time for every Google Cloud module, sometimes multiple times.
vchudnov-g commentedon Apr 8, 2026
@bonauer-pf 's #16579 seems like a promising fix. Thanks!
vchudnov-g commentedon Apr 8, 2026
To clarify: I believe the issue arises here: recent versions of
api_corenow include these symbols, and so we were calling the function doing these checks every time we imported a new library. The memoization in #16579 should alleviate that.fix(perf): avoid repeated scan of entire venv via packages_distributi…
daniel-sanche commentedon Apr 10, 2026
This should be fixed in the latest version, but let me know if this is still an issue