Skip to content

Conversation

@mohasarc
Copy link

This pull request optimizes string construction in parse_uncertainty by replacing + concatenation with .join().

The Issue: In Python, strings are immutable. Using + to combine multiple string segments forces the interpreter to create a new string object and copy the content for every concatenation step. This results in inefficient memory usage and unnecessary overhead, particularly when constructing strings from multiple parts.

The Solution: I refactored the string construction logic to use ''.join(). This approach ensures linear time complexity O(n) because the total size of the final string is calculated once, and memory is allocated efficiently.

This is in line with standard python performance recommendation: https://peps.python.org/pep-0008/#programming-recommendations

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.

1 participant