Skip to content
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

refactor: performance tweaks under DatafileReader #68

Merged
merged 1 commit into from
Apr 3, 2024

Conversation

polok
Copy link
Contributor

@polok polok commented Mar 29, 2024

Dictionaries provide constant, i.e. O(1), access, which means searching if a value exists and updating it, is faster than with an Array, which, depending on implementation can be O(n). Under DatafileReader we use search very often yo find attributes, segments and features.

@polok polok requested a review from a team as a code owner March 29, 2024 19:22
@@ -24,18 +30,18 @@ public class DatafileReader {
}

public func getAllAttributes() -> [Attribute] {
return self.attributes
return Array(attributes.values)

Choose a reason for hiding this comment

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

It's a small improvement (if any) but you can also consider returning here sequence, so you don't need to create new Array

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's replace arrays with dictionaries under this PR. I believe that is not the last PR like this.

@polok polok merged commit c55bbbe into main Apr 3, 2024
1 check passed
@polok polok deleted the ref_datafilereader_optimalizations branch April 3, 2024 04:57
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.

4 participants