refactor: optimize variable containment check and remove redundant clones - #213
Open
moostoopha wants to merge 1 commit into
Open
moostoopha wants to merge 1 commit into
moostoopha wants to merge 1 commit into
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! |
BerSomBen
approved these changes
Jul 23, 2026
| // - $enc <...> / $enc<...> (legacy scheme, with fallback) | ||
| // - raw base64 (tries new first, then legacy) | ||
| let tmp_loop_var_value = tmp_loop_var.clone().value.unwrap(); | ||
| let tmp_loop_var_value = tmp_loop_var.value.clone().unwrap(); |
| // will set its value to None and push it to vars_final, so it will be deleted. | ||
| // Build a set for O(1) lookup instead of scanning the vec on every iteration. | ||
| let vars_yaml_set: HashSet<EnvironmentVariable> = | ||
| vars_yaml.iter().cloned().collect(); |
Collaborator
There was a problem hiding this comment.
whenever turning O(n) into o(1) its a good change.
| // - $enc <...> / $enc<...> (legacy scheme, with fallback) | ||
| // - raw base64 (tries new first, then legacy) | ||
| let tmp_loop_var_value = tmp_loop_var.clone().value.unwrap(); | ||
| let tmp_loop_var_value = tmp_loop_var.value.clone().unwrap(); |
Collaborator
There was a problem hiding this comment.
I think there are several others like this in the code.
tobias-richter
requested review from
BerSomBen
and
a lite review from Copilot
September 18, 2026 12:10
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