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

Exponential growth strategy for BitmapIndexed?! #387

Open
sjakobi opened this issue Mar 20, 2022 · 1 comment
Open

Exponential growth strategy for BitmapIndexed?! #387

sjakobi opened this issue Mar 20, 2022 · 1 comment

Comments

@sjakobi
Copy link
Member

sjakobi commented Mar 20, 2022

So far, when we grow the array in a BitmapIndexed, we nearly always enhance it by one (the one exception is union*). For each of these enhancements, we allocate a fresh array and copy over the elements from the old one.

It may be more efficient to grow these array by a factor of 2 or 1.5 instead, avoiding the allocations and copying for some of the enhancements. The unused slots at the end of the array could be marked with Empty or a dedicated Placeholder element. Wherever we rely on the length of the array, we could use the popcount of the bitmap instead.

Regarding the ideal growth factor, there is some discussion in https://stackoverflow.com/q/1100311/1013393.

@sjakobi
Copy link
Member Author

sjakobi commented Mar 22, 2022

If we don't want to have the unused array slots using up memory and GC-time, we could limit this array growth strategy to certain functions like fromList and follow up with a pass that removes the excess space with shrinkSmallMutableArray# (#362).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant