-
Notifications
You must be signed in to change notification settings - Fork 178
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
Full IntSets? #999
Comments
Think this could technically be represented with existing constructors containers/containers/src/Data/IntSet/Internal.hs Lines 262 to 263 in c651094
If the lowest bit in the isFullTree = mask .&. 1 == 1
fullTree prefix mask = Bin prefix (mask .|. 1) Tip Tip This saves a constructor entry at the cost of 2 #998 would affect the bit fiddling costs of this I guess. |
Ah sure, it could be done by assigning the case to some currently invalid configuration. But what is the benefit of keeping the number of constructors at 3? We can even reduce it to 2 today if we want, by replacing |
Replacing |
My thinking was it might decrease the amount of branch prediction needed in some cases, (assuming the bit fiddling doesn't eclipse benefits), but it also depends on what constructor matching gets compiled to and I don't know how ghc behaves there. |
I found an implementation of this: https://hackage.haskell.org/package/intset Haven't looked into how it compares performance-wise yet. |
I wonder if it will be useful to add another constructor to
IntSet
:Full Prefix
. This indicates that this is a full tree with a shared prefix.I expect this to show good improvements for use cases where contiguous runs of$O(\log n)$ memory instead of $O(n)$ .
Int
s are likely. It will also reduce space usage in such cases. For instance, to store[0..n]
we will need onlyBut this would add small overheads in various places, so it will likely not be a clear win in all use cases.
Also, to be clear, this would be small added costs and not a change in the worst case bounds.
For sure we would want to test something like this out on some real world use cases (like GHC, maybe others?) to see how it affects things. Just documenting this idea for now.
The text was updated successfully, but these errors were encountered: