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

Consider using ContiguousArray instead of Array #3

Open
izackp opened this issue Mar 22, 2022 · 1 comment
Open

Consider using ContiguousArray instead of Array #3

izackp opened this issue Mar 22, 2022 · 1 comment

Comments

@izackp
Copy link

izackp commented Mar 22, 2022

I noticed there is no use of contiguous array in the source. Using Array or [T] with classes or protocols results in a type that's compatible with NSArray. Supporting NSArray results in a performance penalty. ContiguousArray is swift-only thus the compiler can optimize it better.

@izackp
Copy link
Author

izackp commented Mar 23, 2022

Adding some additional info:

Accessing any value at a particular index in an array is at worst O(log n), but should usually be O(1).
Searching for an object at an unknown index is at worst O(n (log n)), but will generally be O(n).
Inserting or deleting an object is at worst O(n (log n)) but will often be O(1)

https://www.raywenderlich.com/1172-collection-data-structures-in-swift#toc-anchor-004

I'm curious about attempting the improve the performance myself though I don't have linux setup atm.

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

No branches or pull requests

1 participant