-
Notifications
You must be signed in to change notification settings - Fork 11
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
How to fight undesirable sharing? #6
Comments
It should be possible to reproduce any sharing conundrum that you could make with Data.List. Thus all of these exhaust memory except the one that uses streaming copy:
|
I don't follow. You're showing a different example -- one where you use a stream twice, for two different computations. In my example, I use the stream once to produce an IO action. That IO action is later executed twice. I am not sure how your |
Sorry, the bit about
ghc thinks it might need the list Because the representation of |
Yes, I understand why this is happening, and I didn't want to imply that the problem is somehow specific to this library. I was just curious if you knew any better workarounds than the one I came up with. I also have another way to fix this minimal example:
However, in my real code base, the point where |
@nomeata I know you've done a ton of work in this area. Do you have any thoughts? Is there a chance to get your |
For a while, I implemented the three principal offenders, The slowdown (which is just a matter of piling on more constructors) was only visible in trivial benchmarky cases, so maybe it's worth it. |
Unlikely; it was very fiddly and low-level, and probably is not reliable either. Unfortunately, I don’t know of any better solution. Even tricks like an We might need pragmas like |
Working through some of the recalcitrant cases, I did find that
is not finding any unintended sharing. But I'm sure I observed it yesterday. This suggests to me that the compiler has a learning ability, which wouldn't too much surprise me. |
I would be very interested in any cases you find where |
@tomjaguarpaw see my original snippet in the very first post |
@feuerbach The original snippet doesn't have |
I think |
@tomjaguarpaw it doesn't, but simply adding a Your |
Right, which is why I am interested in
i.e. do you know of any space leaks where both
If so, as I said, I would be very interested. It is my current hypothesis that if both conditions are satisfied then the thunk will not be shared. |
They are indeed different, and I'm suggesting that each would work. |
Weird, I can't reproduce it anymore. I'm reasonably sure no-full-laziness and dummy arguments didn't help in my real problem at work. I'll try to make a minimal example when I have time. |
That's what they all* say :) |
@tomjaguarpaw that's an interesting discussion on haskell-cafe. I wondered about something like
That might be somewhat more practical. Then it could just be another hidden feature the user wouldn't bump into much, since one could still have essential functions like The no-sharing pair would also be kind of a drag since, at least the way I was thinking, it is important for comprehension that the folds in e.g.
and the like, so that they can be used for the characteristic rank-2 maps, but they also need to be practical taken by themselves. Construction and deconstruction would be less pleasant. But I don't know. All of this presupposes that generally counseling |
I'm on a bit of a crusade to eliminate I would be interested to see how performance changes under I don't understand why the form of |
The type signature would be the same, it's just that that that's a place where the user might actually pattern match, say
which then becomes
which isn't bad, just more to keep track of. |
Will the |
You mean marking something like Here's the source I'm using - toggling between
|
EDIT: migrated to haskell-streaming/streaming#110 (comment) |
@tomjaguarpaw, michaelt is no longer active on GitHub or the Haskell community, unfortunately. Development of this package has moved to https://github.com/haskell-streaming/streaming. If you'd like to reopen discussion, I suggest you do so in a new issue there, and link to this one. |
Thanks @treeowl. Done! |
This simple code leaks memory because the stream gets shared:
The only workaround I have found is to introduce dummy monadic layers:
Are there any better approaches?
The text was updated successfully, but these errors were encountered: