forked from googleapis/python-aiplatform
-
Notifications
You must be signed in to change notification settings - Fork 0
⚡️ Speed up method PipelineRuntimeConfigBuilder.build
by 2,940%
#20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
codeflash-ai
wants to merge
12
commits into
main
Choose a base branch
from
codeflash/optimize-PipelineRuntimeConfigBuilder.build-mgik0ltq
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
⚡️ Speed up method PipelineRuntimeConfigBuilder.build
by 2,940%
#20
codeflash-ai
wants to merge
12
commits into
main
from
codeflash/optimize-PipelineRuntimeConfigBuilder.build-mgik0ltq
Conversation
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
… in Vertex AI GenAI SDK evals PiperOrigin-RevId: 815745954
…ion_item` methods to Vertex AI GenAI SDK evals PiperOrigin-RevId: 815805880
-- e339795 by Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>: feat:Auto-generated CL for //google/cloud/aiplatform:aiplatform_v1beta1_public_proto_gen PiperOrigin-RevId: 813083326 Source-Link: googleapis/googleapis@3ecf1f0 Source-Link: googleapis/googleapis-gen@00da0dd Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMDBkYTBkZDIyZDAwZmNkMTExMGE0MGI5MzJiNzI0M2Q4ZmRlZmIzYyJ9 -- efdd99a by Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>: 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md -- b9fd9fa by Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>: feat: Auto-generated CL for //google/cloud/aiplatform:aiplatform_v1_public_proto_gen PiperOrigin-RevId: 813096234 Source-Link: googleapis/googleapis@e78280f Source-Link: googleapis/googleapis-gen@d83eeb4 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZDgzZWViNGIwNTU5YWQwYjMyNDMxNTJlYzhiOGMyMzEwYzIzYWVjNyJ9 -- e01fdae by Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>: 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md -- 5f2b229 by Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>: feat: add DeploymentTier enum to DeployedIndex PiperOrigin-RevId: 813384393 Source-Link: googleapis/googleapis@063f9e1 Source-Link: googleapis/googleapis-gen@1119646 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMTExOTY0NmY5ZTUxOTIyZmJjYThjM2E3YWU3NDNhNmM3OTEzMWMxZSJ9 -- b9d3464 by Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>: 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md -- fabb82d by Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>: feat: Add labels field for Predict API for Imagen use case (v1beta) PiperOrigin-RevId: 815803050 Source-Link: googleapis/googleapis@7f0c1e5 Source-Link: googleapis/googleapis-gen@a452a5d Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYTQ1MmE1ZGRhOGU3MmMzMmQ2MGIwMWU3NTFiZDBjYmRmNmIzYTI2ZSJ9 -- 8cf83c2 by Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>: 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md COPYBARA_INTEGRATE_REVIEW=googleapis#5863 from googleapis:owl-bot-copy a962595 PiperOrigin-RevId: 815901905
PiperOrigin-RevId: 816259798
PiperOrigin-RevId: 816278193
PiperOrigin-RevId: 816325320
…M metric PiperOrigin-RevId: 816389819
…th_events calls. PiperOrigin-RevId: 816470728
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
The optimized code achieves a 2939% speedup by **pre-computing version comparisons in the constructor** instead of repeating expensive `packaging.version.parse()` calls during execution. **Key optimizations:** 1. **Version parsing moved to `__init__`**: The original code called `packaging.version.parse(self._schema_version)` and `packaging.version.parse("2.0.0")` on every `build()` and `_get_vertex_value()` call. The optimized version parses these once during initialization and stores the results as `self._parsed_schema_version` and `self._is_version_gt_2`. 2. **Boolean flag for version comparison**: Instead of repeating the expensive version comparison `> packaging.version.parse("2.0.0")`, the code uses the pre-computed boolean `self._is_version_gt_2`. **Why this is faster:** - `packaging.version.parse()` involves string parsing and object creation, which is computationally expensive - In the original code, these parsing operations dominated execution time (95.4% in `_get_vertex_value` and significant time in `build()`) - The optimization eliminates redundant parsing - especially impactful when `_get_vertex_value()` is called multiple times per `build()` invocation **Test case performance:** - **Large-scale scenarios benefit most**: Tests with 500+ parameters show 2700-5500% speedups because `_get_vertex_value()` is called repeatedly - **Basic scenarios**: Even simple cases show 700-1200% improvements due to eliminating version parsing overhead - **Edge cases**: Error scenarios still improve 400-600% as version parsing happens before validation logic The optimization is particularly effective for pipelines with many parameters, where the version comparison cost scales linearly with parameter count.
PiperOrigin-RevId: 816927504
…der.build-mgik0ltq
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.
📄 2,940% (29.40x) speedup for
PipelineRuntimeConfigBuilder.build
ingoogle/cloud/aiplatform/utils/pipeline_utils.py
⏱️ Runtime :
18.1 milliseconds
→595 microseconds
(best of391
runs)📝 Explanation and details
The optimized code achieves a 2939% speedup by pre-computing version comparisons in the constructor instead of repeating expensive
packaging.version.parse()
calls during execution.Key optimizations:
Version parsing moved to
__init__
: The original code calledpackaging.version.parse(self._schema_version)
andpackaging.version.parse("2.0.0")
on everybuild()
and_get_vertex_value()
call. The optimized version parses these once during initialization and stores the results asself._parsed_schema_version
andself._is_version_gt_2
.Boolean flag for version comparison: Instead of repeating the expensive version comparison
> packaging.version.parse("2.0.0")
, the code uses the pre-computed booleanself._is_version_gt_2
.Why this is faster:
packaging.version.parse()
involves string parsing and object creation, which is computationally expensive_get_vertex_value
and significant time inbuild()
)_get_vertex_value()
is called multiple times perbuild()
invocationTest case performance:
_get_vertex_value()
is called repeatedlyThe optimization is particularly effective for pipelines with many parameters, where the version comparison cost scales linearly with parameter count.
✅ Correctness verification report:
🌀 Generated Regression Tests and Runtime
To edit these changes
git checkout codeflash/optimize-PipelineRuntimeConfigBuilder.build-mgik0ltq
and push.