-
Notifications
You must be signed in to change notification settings - Fork 2.5k
perf: use list join instead of string concatenation in loop #3829
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
base: develop
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -98,9 +98,15 @@ def _get_function_names( | |||||||
| ) | ||||||||
| if not resolved_function_name: | ||||||||
| continue | ||||||||
| self.function_names.setdefault(api_name, "") | ||||||||
| self.function_names[api_name] += str(resolved_function_name) | ||||||||
| return self.function_names | ||||||||
| # OLD APPROACH: String concatenation in loop | ||||||||
| # self.function_names.setdefault(api_name, "") | ||||||||
| # self.function_names[api_name] += str(resolved_function_name) | ||||||||
| # NEW APPROACH: Collect in list | ||||||||
| if api_name not in self.function_names: | ||||||||
| self.function_names[api_name]=[] | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| self.function_names[api_name].append(str(resolved_function_name)) | ||||||||
| #backward compatibility | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment is also probably unnecessary.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okayy |
||||||||
| return {api: "".join(names) for api, names in self.function_names.items()} | ||||||||
|
|
||||||||
| def translate( # noqa: PLR0912, PLR0915 | ||||||||
| self, | ||||||||
|
|
@@ -127,7 +133,9 @@ def translate( # noqa: PLR0912, PLR0915 | |||||||
| self.feature_toggle = feature_toggle or FeatureToggle( | ||||||||
| FeatureToggleDefaultConfigProvider(), stage=None, account_id=None, region=None | ||||||||
| ) | ||||||||
| self.function_names: Dict[Any, Any] = {} | ||||||||
| # OLD: self.function_names: Dict[Any, Any] = {} | ||||||||
| # NEW: Use List[str] for efficient accumulation, convert to str when needed | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same suggestion on commenting the old approach. |
||||||||
| self.function_names: Dict[str, List[str]] = {} | ||||||||
| self.redeploy_restapi_parameters = {} | ||||||||
| sam_parameter_values = SamParameterValues(parameter_values) | ||||||||
| sam_parameter_values.add_default_parameter_values(sam_template) | ||||||||
|
|
||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need the comment with the old approach.