-
Notifications
You must be signed in to change notification settings - Fork 30
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
make MSF a newtype #169
make MSF a newtype #169
Conversation
I wasn't aware that |
I'll try to provide a self-contained benchmark later (I'm currently debugging other space leaks in my program), but so far let me say that in my code I had: anyQuit :: Foldable f => f Action -> Bool
anyQuit = any \case { QuitAction -> True ; _ -> False }
quit :: ( Monad m, Foldable f ) => MSF (ExceptT Quit m) (f Action) ()
quit = throwOnCond anyQuit Quit >>> arr ( const () ) A heap profile revealed that this use of I think the leak happened because the method in the |
If this breaks nothing, I am in principle not against. My suspicion is that the issue with |
@sheaf I'd be glad to accept this if we can somehow obtain some way to check. Were you able to create a minimal example we can use to quickly verify the leak and the fix? |
I have just done some basic tests with haskanoid, both deepseqing the main game state and without deepseqing it, and with and without -O2. I think there is some leak in dunai or bearriver. This seems unrelated to this issue, but it would be nice to use some non-trivial game to understand what's going on both with this PR and generally with dunai. There is a haskanoid branch called https://github.com/ivanperez-keera/haskanoid/compare/develop-haskelltitan that may help. It enables record-and-replay, which enables create reproducible runs. It would require some work to merge this properly into haskanoid, and I'd be happy to guide that separately there. Otherwise, it can serve as an example of how to record and replay and facilitate profiling in a systematic way. I've also added a branch: https://github.com/ivanperez-keera/haskanoid/tree/develop-deepseqbangs that allows deepseqing the game state (to make sure the problem is not a leak in haskanoid itself). I don't think we need to merge it, but it may be useful. In a recent issue, haskanoid started supporting bearriver: ivanperez-keera/haskanoid#95, so compiling with -fbearriver should do. |
I unfortunately haven't managed to come up with a self-contained example that demonstrates the problem. Here are the original heap allocation graphs that showcase the difference: Note that in the "datatype" version there are two space leaks which are resolved in the "newtype" version, pertaining to |
I don't fully understand. Do you mean to say that reintroducing the data still gives you a completely flat profile, or is the MSF/dunai/bearriver leak still there (just not the leaks in your own code)? |
I mean that the leaks due to |
If the leak is not manifesting once you change your side of the code, then I'd rather close this for now and revisit later. Changing a We will incorporate a proper way of benchmarking in the future, and then we'll be able to answer these questions properly. When we have proper tests and benchmarks, we can try again, and if nothing breaks then, then I'll re-open and merge this PR. |
That being said, many, many thanks @sheaf :) |
Making MSF a newtype fixes some space leaks, in particular with
ArrowChoice
. This means thatif
statements andcase
statements no longer leak space, and as a result functions likethrowOnCond
which use theArrowChoice
functionality also no longer leak.