Skip to content

perf(gapic-generator): lazily import unversioned package exports - #19032

Draft
GouthamMahesh wants to merge 2 commits into
googleapis:mainfrom
GouthamMahesh:perf/unversioned-lazy-imports
Draft

GouthamMahesh wants to merge 2 commits into
googleapis:mainfrom
GouthamMahesh:perf/unversioned-lazy-imports

Conversation

@GouthamMahesh

Copy link
Copy Markdown

Add native Python 3.15 lazy imports to the unversioned package template, matching the existing versioned package behavior. Includes regression tests and eight updated golden files.

Version metadata stays eager. Export names and resolved objects stay the same. Older Python versions keep eager imports.

Related to #18987. The 300 ms threshold stays unchanged.

Replayed the original BackupDR revision pair with Python 3.15.1, pinned CI dependencies, and the original 100 ms profiler threshold:

Comparison Before API update After API update Increase
Original GitHub CI 1345.08 ms 1589.62 ms 244.54 ms
Local replay, unchanged 2115.16 ms 2381.46 ms 266.30 ms
Local replay, lazy imports 4.42 ms 6.22 ms 1.80 ms

Local measurements used Linux ARM64 and 11 fresh processes per condition, discarding the first. The unchanged local pair also passes the 15% relative gate, so this does not reproduce the original CI failure exactly. This measures bare imports. Loading costs, side effects, and dependency errors move to first use. SDKs receive the change through regeneration.

Validation:

  • 669 generator tests pass on Python 3.10, 3.14, and 3.15, with 100% generator coverage on 3.10 and 3.15.
  • 48 profiler tests pass on Linux with 100% coverage.
  • 4519 BackupDR tests pass with each Protobuf backend.
  • All nine Bazel-generated APIs match their 1022 expected files using GNU comparison tools. The native macOS test wrapper fails on its existing GNU-only cp -T command.

@GouthamMahesh
GouthamMahesh requested a review from a team as a code owner November 10, 2026 06:53
@google-cla

google-cla Bot commented Nov 10, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@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 implements PEP 0810 (Explicit Lazy Imports) for Python 3.15+ by generating a __lazy_modules__ set in the package initialization templates. It updates the corresponding golden files and adds integration and unit tests to verify the behavior. The reviewer suggested improving the formatting of the generated __lazy_modules__ elements by applying an indentation filter in the Jinja template to comply with PEP 8 guidelines.

@parthea

parthea commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Hi @GouthamMahesh, Thanks for providing a performance fix! Please could you sign the CLA? Once it's signed, please mark the PR as Ready for review. Thanks!

@parthea
parthea marked this pull request as draft November 11, 2026 13:55

This branch has not been deployed

No deployments
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.

2 participants