Implement Phase 1 Native PEP 0810 Lazy Loading#17591
Draft
hebaalazzeh wants to merge 2 commits into
Draft
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request adds a conditional check for Python 3.15+ to define __lazy_modules__ in the initialization file of google-cloud-compute. However, the sys module is not imported, which will cause a NameError at runtime. Since this is a generated file, the generator or templates should be updated to include the necessary import rather than applying manual fixes.
Comment on lines
+26
to
+27
|
|
||
| if sys.version_info >= (3, 15): |
Contributor
There was a problem hiding this comment.
The sys module is not imported in this file, which will cause a NameError at runtime on all Python versions when this package is imported. Since this is a generated file, please update the generator or templates to import sys at the module level to prevent manual changes from being overwritten.
References
- Do not suggest manual code modifications, optimizations, or style fixes for generated files, as any changes should be implemented in the generator or templates to prevent them from being overwritten.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR represents Phase 1 of our initiative to resolve severe initialization bottlenecks (~10s-13s) in generated client libraries by adopting Native Python 3.15 Explicit Lazy Imports (PEP 0810).
To avoid introducing maintenance burdens or subtle breaking changes via custom import hooks, this PR focuses exclusively on utilizing native interpreter standards.
Implementation Architecture
We modify the upstream GAPIC Generator to emit a native
__lazy_modules__set at the top of the__init__.pyfiles, immediately followed by the standard eager imports.__lazy_modules__set and treats them as fast C-level lazy proxies. Startup times drop from ~13s to ~200ms, and peak RAM consumption drops by up to 85%.__lazy_modules__variable and process the standard eager imports exactly as they do today. This guarantees 100% backwards compatibility with zero risk.Example Structure:
Related Links:
Design Doc: go/sdk-performance-design
Towards googleapis/python-aiplatform#4749