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
Map data type too strict? #446
Comments
I think this is definitely a reasonable thing to think about, but there are two issues that make me very wary of actually implementing it:
The number of functions that will actually benefit from the change you suggest is relatively small: |
Thank you for that quick response! Ok I will try it out - let's see how it turns out. The numbers of functions concerned might be few, but the difference is huge - I am looking forward to measuring! ;-) Another (unrelated) question out of interest, because I believe you are very experienced in this area and I am pretty new to Haskell performance optimizations: There is often the issue too lazy, but also too strict: Do you think a Map variant could be implemented that is super lazy and therefore also quite efficient? Space leaks can often be resolved by more strictness or by less - therefore the question. I thought about it a bit and I believe the answer is no, mainly because of the re-balancing stuff, which easily piles up thunks and it seems to be hard to avoid that. But on the other hand - I know nothing about that stuff ;-) Many thanks! |
That's a good catch, I haven't thought about that. I am curious already. :-) |
GHC now has pattern synonyms that could be used to do this without a massive refactor and cognitive overhead. Something like
It'd mean dropping GHC <7.8 though. |
It would mean losing much hope of getting it working with non-GHC implementations as well, which goes against the tradition of |
I've been writing R- and radix trees for at least a year now and, since tree libraries naturally want to mimic Why was the choice made to share representation instead of having a fully lazy |
Yes, you could definitely see it that way. Optimized for speed, but even more so for compactness. |
Oh no, this brings a lot of questions to the table and I'm greatly sorry for this deluge:
Obviously these are |
After thinking about this for a while, any trees that can rebalance the root node have no reason to be lazy because any operation has to first evaluate the root node, forcing every previous operation. Curiously enough binary radix trees do not have this requirement, so The case where This issue as such can be closed, as the current implementation of My opinion on the module naming still stands: |
Hi there!
I have the following situation, I have a Map with some internal representation of data:
now I am exposing this map to the user, but I like to offer a different representation of data:
an obivious implementation would be:
the trouble is, Map is too strict for this: The left and the right branch have strictness annotations, that means if the user does a lookup on the result of
getStuff
the whole map will be build and the user effectively gets a linear lookup instead of a logarithmic one - which is pretty bad, obviously.I suppose the strictness annotations are there for efficiency and to avoid space leaks with operations like re-balancing trees. The question is, would it be feasible to simply add bang patterns to those functions instead? As far as I understand it, this should result in the same semantics (Maps can't be unpacked anyway), but would offer the possibility of a lazy fmap, which I actually expected - but gladly I checked the implementation first.
Many thanks! If this sound reasonable, I can definitely provide a PR!
The text was updated successfully, but these errors were encountered: