Skip to content
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

Restart presentation compilers if memory is low #3967

Merged
merged 4 commits into from
Mar 15, 2018

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Feb 5, 2018

I have noted during long editing sessions (lasting several days,
typically) that memory can get full because the Dotty compiler has some
space leaks. The leaks look really hard to fix, and we don't know
yet whether it's at all possible. To mitigate the leaks, this commit
makes the language server watch available memory, and, if it
is low (i.e. free memory after a GC < 10% of maximal available)
restart all interactive drivers. This will free all memory of
the compiler(s) except the shared nametable.

There's a stressTest option in Memory.scala, which, when turned on,
causes a restart every 10 editing actions. I verified that the compiler
stays functional and reasonably responsive in that mode.

Based on #3960

Copy link
Member

@dottybot dottybot left a comment

Choose a reason for hiding this comment

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

Hello, and thank you for opening this PR! 🎉

All contributors have signed the CLA, thank you! ❤️

Commit Messages

We want to keep history, but for that to actually be useful we have
some rules on how to format our commit messages (relevant xkcd).

Please stick to these guidelines for commit messages:

  1. Separate subject from body with a blank line
  2. When fixing an issue, start your commit message with Fix #<ISSUE-NBR>:
  3. Limit the subject line to 72 characters
  4. Capitalize the subject line
  5. Do not end the subject line with a period
  6. Use the imperative mood in the subject line ("Added" instead of "Add")
  7. Wrap the body at 80 characters
  8. Use the body to explain what and why vs. how

adapted from https://chris.beams.io/posts/git-commit

Have an awesome day! ☀️

// ... 11 more
//
// This looks like a problem with Dottys code generation for void-returning closures passed
// to Java methods. (or SAM functions in general?)
Copy link
Member

@smarter smarter Feb 5, 2018

Choose a reason for hiding this comment

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

Hmm we should be returning a BoxedUnit here, could you open an issue so we can keep track of this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See #3984

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this should be changed now that #3984 has been fixed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, you are right.

@smarter
Copy link
Member

smarter commented Feb 12, 2018

Rebased.

@odersky
Copy link
Contributor Author

odersky commented Feb 21, 2018

rebased

// ... 11 more
//
// This looks like a problem with Dottys code generation for void-returning closures passed
// to Java methods. (or SAM functions in general?)
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this should be changed now that #3984 has been fixed?

@@ -173,6 +204,7 @@ class DottyLanguageServer extends LanguageServer
}

override def didChange(params: DidChangeTextDocumentParams): Unit = thisServer.synchronized {
checkMemory()
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't checkMemory() be called also when doing the other operations? I imagine that completion and references in particular can require quite some memory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since they do not involve new runs, I don't think it's a problem. The leak comes from the memory of previous runs not being completely reclaimed.

I have noted during long editing sessions (lasting several days,
typically) that memory can get full because the Dotty compiler has some
space leaks. The leaks looks really hard to fix, and we don't know
yet whether it's at all possible. To mitigate the leaks, this commit
makes the language server watch available memory, and, if it
is low (i.e. free memory after a GC < 10% of maximal available)
restart all interactive drivers. This will free all memory of
the compiler(s) except the shared nametable.

There's a stressTest option in `Memory.scala`, which, when turned on,
causes a restart every 10 editing actions. I verified that the compiler
stays functional and reasonably responsive in that mode.
I observed a NoType when editing some code which caused ThisType#underlying to crash.
@odersky
Copy link
Contributor Author

odersky commented Mar 15, 2018

Merging this now since I am losing too much productivity running into the problem this solves.

@odersky odersky merged commit 14c5af6 into scala:master Mar 15, 2018
@Blaisorblade Blaisorblade deleted the ide-restart branch March 15, 2018 12:28
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.

5 participants