Skip to content

Conversation

@roryc89
Copy link
Contributor

@roryc89 roryc89 commented Jul 19, 2024

Description of the change

To address #4545.

This change fixes the memory issues in our project and makes the IDE reasonable performant but I don't know if there are other ramifications.


Checklist:

  • Added a file to CHANGELOG.d for this PR (see CHANGELOG.d/README.md)
  • Added myself to CONTRIBUTORS.md (if this is my first contribution)
  • Linked any existing issues or proposals that this pull request should close
  • Updated or added relevant documentation (not applicable)
  • Added a test for the contribution (not applicable)

& resolveReexports reexportRefs
setVolatileStateSTM ref (IdeVolatileState (AstData asts) (map reResolved results) rebuildCache)
pure (force results)
pure results
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have limited haskell XP so may be misunderstanding but I suspect that by allowing results to be lazy, the IDE doesn't have to calculate all of the results as the state may be recomputed before much or any of an old result is used.

Whereas, when it is forced, it is possible for many computations to be queued up on a large project and the results value can use up so much memory that the IDE starts to grind to a halt.

@f-f
Copy link
Member

f-f commented Jul 19, 2024

I think the PR is sound, CI currently fails presumably because of the Azure debacle

@f-f
Copy link
Member

f-f commented Jul 22, 2024

We'll need #4548 merged before this can pass

@roryc89
Copy link
Contributor Author

roryc89 commented Aug 23, 2024

As #4548 is merged, is this ok to merge now?

Copy link
Member

@f-f f-f left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me - could someone else take a look as well?

@rhendric
Copy link
Member

This patch appears to be reverting 2606727 from #3006, which means at least three things:

  • If this revert is desirable, there may be a bunch of Generic and NFData instances that can also be cleaned up.
  • Per that commit message, a consequence of this is that a logPerf measurement is no longer accurate, and we should figure out what to do about that.
  • Also per that commit message, something about ‘actually populate the cache of f-thread’ may need attention (I don't know what that means).

@f-f
Copy link
Member

f-f commented Aug 23, 2024

@kritzcreek I know that commit was 7y ago, but do you have any recollection about this?

@kritzcreek
Copy link
Member

Oh my, I had to think for a bit...

‘actually populate the cache of f-thread’

Actually meant off-thread, which is about a worker thread that does the populateVolatileState logic in here in the background. I think at the time when measuring I figured out that leaving the value lazy meant the computation ended up being done on the thread that accepts and responds to requests. Which meant the first requests after a state reload would take a very long time. (That's also why most of the resolution logic is wrapped in STM)

I'm not sure if making things lazy here is going to help with peak memory usage, it might just delay it until you start sending some requests against the updated IdeState. Sorry, it's been a long time so I'm very fuzzy on the details...

@purefunctor
Copy link
Member

fwiw, this change brings down what normally is 30 GBs of peak memory usage down to 10 GBs alongside bringing down memory pressure/time-to-diagnostics quite a bit on our codebase. We also use this with a custom IDE command that filters which externs files get loaded.

One side effect is that diagnostics are not immediately available until the first edit, but I'm not entirely sure if that's coming from this PR or the custom IDE command.

This LGTM aside from removing the redundant Generic/NFData instances.

@kritzcreek
Copy link
Member

kritzcreek commented Aug 27, 2024

Please don't take my comment as a blocker to merging. I haven't written Haskell in over 5(?) years, so I'm hardly an authority on the matter :D Just wanted to dump what context I could remember in case it was helpful.

@nwolverson
Copy link
Contributor

One side effect is that diagnostics are not immediately available until the first edit, but I'm not entirely sure if that's coming from this PR or the custom IDE command.

I assume by diagnostics you mean type info etc. It would certainly seem worth checking this with a clean build because that sounds like a blocker to me (and presumably not at all necessary or deep)

@i-am-the-slime
Copy link
Contributor

This looks very easy to revert. If it was merged, it'd get released as a beta, right?
That could be a good way to gather feedback without having to dive extremely deep.

@roryc89
Copy link
Contributor Author

roryc89 commented Sep 9, 2024

  • If this revert is desirable, there may be a bunch of Generic and NFData instances that can also be cleaned up.

Good point. I've removed them.

  • Per that commit message, a consequence of this is that a logPerf measurement is no longer accurate, and we should figure out what to do about that.

Also removed. I guess it would also be possible to only call force when logLevel == DEBUG

@rhendric
Copy link
Member

This looks ready to merge to me; any final objections?

@rhendric rhendric merged commit fc3fa88 into purescript:master Sep 29, 2024
@kozak kozak mentioned this pull request May 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants