Skip to content

feat: lazy imports gapic v1#17673

Open
hebaalazzeh wants to merge 2 commits into
mainfrom
feature/lazy-imports-gapic-v1
Open

feat: lazy imports gapic v1#17673
hebaalazzeh wants to merge 2 commits into
mainfrom
feature/lazy-imports-gapic-v1

Conversation

@hebaalazzeh

Copy link
Copy Markdown
Contributor

Description

This PR initiates the rollout of our PEP810 lazy-loading architecture to google-api-core, starting with the gapic_v1 module.

By applying Python 3.15's native explicit lazy imports (PEP 0810), we defer the eager execution of inner modules (like method.py and config.py) which recursively pull in massive third-party C-extensions like grpcio. This acts as the first step in addressing the high initialization latency and peak memory footprints we're seeing on Serverless cold-starts.

Older Python runtimes (3.14 and below) safely ignore the __lazy_modules__ set and fall back to standard eager execution, meaning this introduces zero backwards compatibility risk.

Related Documents

Note: This PR was kept intentionally small for review speed. We will be executing an iterative rollout, extending this pattern to other heavy modules like exceptions and operations_v1 in fast follow-up PRs once this structural pattern is approved.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds an import_profile test target to the CI script and attempts to implement lazy loading for gapic_v1 submodules using Python 3.15's __lazy_modules__ feature. However, a critical issue was identified: placing the imports inside a conditional block (sys.version_info < (3, 15)) prevents them from being executed at all on Python 3.15+, which will lead to AttributeErrors at runtime. To fix this, the imports should remain at the top level so that Python 3.15+ can lazily load them while older versions load them eagerly.

Comment thread packages/google-api-core/google/api_core/gapic_v1/__init__.py Outdated
@hebaalazzeh hebaalazzeh force-pushed the feature/lazy-imports-gapic-v1 branch from 2439765 to 603236b Compare July 8, 2026 19:49
@hebaalazzeh hebaalazzeh marked this pull request as ready for review July 8, 2026 19:49
@hebaalazzeh hebaalazzeh requested a review from a team as a code owner July 8, 2026 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant