-
-
Notifications
You must be signed in to change notification settings - Fork 274
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
Fix memory leaks on historyHook
and workspaceHistoryHook
#653
Fix memory leaks on historyHook
and workspaceHistoryHook
#653
Conversation
ff1fa01
to
30ab657
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is neat, thanks!
I wonder if we could get away with just stictifying the respective data structures (since neither is exported); i.e.,
data SP a b = SP !a !b
deriving (Read, Show)
newtype WorkspaceHistory = WorkspaceHistory
{ history :: [StrictPair ScreenId WorkspaceId]
-- ^ Workspace Screens in reverse-chronological order.
} deriving (Read, Show)
---
data HistoryDB = HistoryDB !(Maybe Window) -- currently focused window
!(Seq Window) -- previously focused windows
deriving (Read, Show)
This is still not ultra-strict but since we're not really interesting in forcing things more than to WHNF it should be fine I think. We may or may not still need the odd call to seq
to force the list, not entirely sure about that right now
EDIT: Oh, and
* [🗸] I've considered how to best test these changes (property, unit, manually, ...) and concluded: XXX
:)
We are interested on forcing things to more than WHNF. On the On a related note, given that we are concerned with forcing evaluation until certain "depth", using strict data types as
So, instead of doing those two things, we can use the combinators on The same is true in respect to
Thanks. I should have put something on those XXX. I edited that part on the original post. |
updateHistory leaks unfiltered windows from previous states as it is never forced. The consumer of such data structure is not visible to ghc, so the demand analysis has to fallback on pure laziness. We fix this inserting evaluation points on the `historyHook` function. We do this for two reasons, this is the only function calling `updateHistory`. Plus we cannot do it clearly at the `updateHistory` function as we operate inside a continuation on withWindowSet. In respect to the `put`, everything would be a big thunk.
The XS.modify was leaving thunk on the history that the demand analyser could not prove to be neccesary as they depended on the future user interaction. This was bad as the time advance there was less and less neccesity to force such value, so the thunk would be increasing. Since the datatypes that the `WorkspaceHistory` are really simple, we can just evaluate and save a good chunk of memory.
30ab657
to
44fb597
Compare
I was missing the |
Would https://hackage.haskell.org/package/deepseq work here as well? Both seem to be maintained by the Core Libraries Committee but deepseq is distributed with GHC so adding that dependency is easier. |
Yeah, we are basically doing the same as in |
@liskin using
I consider both of these alternatives worse than the current status. Specially considering I vote for keep using |
While
While this is true, I think the idea of what we want to achieve is expressed much more clearly by "this is an instance of NFData". |
@slotThe You are right in that the intent is more clear with an |
I think is merge ready. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM now!
5b150ee
to
b75d0d2
Compare
Thanks! |
Simplify stuff a bit. Prevent memory leaks additionally in: `workspaceHistoryTransaction` and `workspaceHistoryModify`. Related: xmonad#653
Description
Both of these hooks leaked memory on long running sessions.
To fix it I had to force the thunks stored on the hooks as the compiler wouldn't be able to see where they would be demanded as they depended on the user interaction. Now the graph looks like this.
The most polemic change on this PR is the inclusion of the
parallel
library as a dependency. I needed for theControl.Seq
module which gave me combinators to force just enough of theData.Seq
and[]
data types.Checklist
[🗸] I've read CONTRIBUTING.md
[🗸] I've considered how to best test these changes (property, unit,
manually, ...) and concluded: It shows the memory improvements!
[🗸] I updated the
CHANGES.md
file (None)