Skip to content

ci: add import profiler check across monorepo#17657

Draft
hebaalazzeh wants to merge 11 commits into
mainfrom
feat/import-profiler-ci
Draft

ci: add import profiler check across monorepo#17657
hebaalazzeh wants to merge 11 commits into
mainfrom
feat/import-profiler-ci

Conversation

@hebaalazzeh

@hebaalazzeh hebaalazzeh commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Overview

This PR integrates the import profiler script (introduced in #17467) into our automated CI pipeline.

Why this matters: Import times significantly impact CLI responsiveness and cold starts for Serverless products like Cloud Run and Cloud Functions. Ideally, library imports should stay under 500ms, and anything taking over 1 second is a target for optimization. This CI check helps us proactively track metrics like import latency, memory footprint, and code volume to prevent performance regressions on critical libraries.

The primary goal of this check is to track and enforce performance standards for package import times across the repository, especially following our recent work on lazy loading and cold-start optimizations.

By running this benchmark as a CI check with a defined failure threshold, we can programmatically prevent major regressions in module initialization times before they are merged, ensuring downstream consumers aren't impacted by unexpectedly slow startup times.

Changes Included

  • GitHub Actions Workflow: Created a new workflow (.github/workflows/import-profiler.yml) that triggers on PRs and merge groups. The workflow is pinned specifically to Python 3.15.
  • Nox Session Integration: Rather than maintaining a complex inline script in CI, we updated the central gapic-generator template (noxfile.py.j2) to natively generate a standardized import_profile Nox session for all packages.
  • Conditional Execution & Graceful Skips: Updated ci/run_single_test.sh to execute the new Nox session. To avoid breaking the pipeline on older packages that haven't been regenerated yet, it verifies if the import_profile session exists before running it, and gracefully skips it if it doesn't.
  • Fail Threshold & Module Auto-detection: Enhanced profiler.py to accept a --fail-threshold argument (to fail CI if the P99 time exceeds an absolute limit like 5 seconds) and a --package argument (to internally auto-detect the underlying module namespace natively).
  • All Packages Testing: Adding the import_profile:all_packages label to a Pull Request will now force the CI pipeline to run the profiler check against all packages in the mono-repo, instead of just the modified ones.

Related PRs

@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 a new import_profile session to the noxfile.py.j2 template to measure and ensure import times remain below defined thresholds. Feedback points out that because this template is used in standalone repositories outside of the monorepo, referencing a relative path to the monorepo's root scripts directory will cause default nox runs to fail in those environments. It is recommended to check for the script's existence and gracefully skip the session if it is missing, while also using pathlib.Path for cleaner path handling.

Comment thread packages/gapic-generator/gapic/templates/noxfile.py.j2 Outdated

@daniel-sanche daniel-sanche 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.

I left a couple comments. It would be good to clarify the goal of this check though.

What counts as a failure? Can we calculate an import time diff before and after the target changes, instead of just reporting an absolute value? How are developers intended to interact with this?

Comment thread ci/run_single_test.sh Outdated
Comment thread ci/run_single_test.sh Outdated
Comment thread ci/run_single_test.sh
;;
*)
nox -s ${TEST_TYPE}
retval=$?

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.

This PR doesn't touch any packages, so it's hard to tell what the action will look like. Can you temporarily touch some files to test it out?

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.

We should also see how long the new check would take if all packages were updated. In #17438, I added a new unit_test:all_packages tag, that will run against all packages when added. Maybe we should support that here too

It's possible we would only want to profile a few key packages instead of all of them. Most generated libraries should be very similar

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

addressed!

Comment thread ci/run_single_test.sh Outdated
@hebaalazzeh hebaalazzeh force-pushed the feat/import-profiler-ci branch from 113b3d5 to 9472ab6 Compare July 8, 2026 23:50
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