Skip to content

Conversation

akshatsinha0
Copy link

Issue #, if available

N/A - Performance optimization proposal

Description of changes

Replace O(n^2) string concatenation with O(n) list accumulation in _get_function_names() method.
Current approach: Uses += operator in loop, creating new string objects on each iteration
Proposed approach: Accumulate in list, join at end using ''.join()
This maintains backward compatibility.

Description of how you validated changes

  • Existing unit tests pass (no behavior change)
  • Type hints updated for clarity (Dict[str, List[str]])
  • Code follows development guidelines
  • No breaking changes - output remains identical

Checklist

Examples?

N/A - Internal performance optimization


Note: This is not a critical fix...
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@akshatsinha0 akshatsinha0 requested a review from a team as a code owner October 16, 2025 14:15
Copy link
Contributor

@reedham-aws reedham-aws left a comment

Choose a reason for hiding this comment

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

Sorry to be nitpicky, suggestion is not a bad one! Also, if you could check the formatting by running make pr locally, that would help get the workflows to pass.

Comment on lines 101 to 104
# 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
Copy link
Contributor

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.

Comment on lines 136 to 137
# OLD: self.function_names: Dict[Any, Any] = {}
# NEW: Use List[str] for efficient accumulation, convert to str when needed
Copy link
Contributor

Choose a reason for hiding this comment

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

Same suggestion on commenting the old approach.

Comment on lines 105 to 106
if api_name not in self.function_names:
self.function_names[api_name]=[]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if api_name not in self.function_names:
self.function_names[api_name]=[]
self.function_names.setdefault(api_name, [])

if api_name not in self.function_names:
self.function_names[api_name]=[]
self.function_names[api_name].append(str(resolved_function_name))
#backward compatibility
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment is also probably unnecessary.

Copy link
Author

Choose a reason for hiding this comment

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

okayy

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