refactor: optimize variable containment check and remove redundant clones#213
Open
moostoopha wants to merge 1 commit into
Open
Conversation
…ones Replace O(n²) vec scan with a HashSet for cloud-vs-yaml variable diffing in both set_env_vars_from_file and set_pipeline_vars_from_file. Also fix tmp_loop_var.clone().value to tmp_loop_var.value.clone() to avoid cloning the whole struct just to access one field. Remove duplicate/wrong docstring on PipelineVariable (copy-paste from EnvironmentVariable).
There was a problem hiding this comment.
Pull request overview
This PR refactors variable processing to reduce unnecessary cloning and improve the performance of “cloud vs YAML” containment checks when determining which variables should be deleted.
Changes:
- Avoids cloning entire variable structs when only the
valuefield is needed for decryption checks. - Replaces repeated
Vec::containsscans inside the cloud-variable loop with a precomputedHashSetfor faster lookups. - Removes a redundant/copy-pasted doc comment on
PipelineVariable.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/variables.rs |
Reduces cloning in secret handling and replaces repeated Vec::contains checks with a prebuilt HashSet for faster membership tests. |
src/models/variables.rs |
Removes an incorrect/redundant doc comment on PipelineVariable. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
|
@lokeshnasina can you please review and test? Thanks! |
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.
spotted a couple of small things while reviewing the deploy step pipeline variables change
tmp_loop_var.clone().value.unwrap()clones the whole struct just to read one field, changed totmp_loop_var.value.clone().unwrap()vars_yaml.clone().contains(&vc)inside the cloud var loop is O(n²), replaced with a HashSet built once before the loop for O(1) lookupall 24 tests pass