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

Native Language Server integration with PM #11880

Merged
merged 22 commits into from
Jan 7, 2025

Conversation

hubertp
Copy link
Collaborator

@hubertp hubertp commented Dec 16, 2024

Pull Request Description

The first attempt at

  1. Building enso native-image that includes full Language Server
  2. Integrating the executable as an experimental feature during project startup

The change (for now) assumes that enso executable appears in Enso's default engines directory.
To build and run the new integration one has to

  1. engine-runner/buildNativeImage
  2. Run PM

The Runner will automatically detect the presence of a native image and attempt to run LS in AOT mode.

This change also adds a copy of some of logback's code (a simple socket server) as it was impossible to debug serialization bugs without some additional logging. Potentially to be removed in the final PR.

This is by no means a final change in this area. We need to make it possible to include all other Standard libs, at least. But it's a step forward that allows devs to experiment.

Important Notes

There is a change in JsonConnectionController which only sets the controller as initialized when all resources are set up. Previously, it seems, the asynchronous setup could lead to some race conditions.

Exchange between LS and GUI (before):
Screenshot from 2024-12-30 15-17-30

(after)
Screenshot from 2024-12-30 15-20-08

As one can see, speedup in startup is rather massive.

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • The documentation has been updated, if necessary.
  • Screenshots/screencasts have been attached, if there are any visual changes. For interactive or animated visual changes, a screencast is preferred.
  • All code follows the
    Scala,
    Java,
    TypeScript,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.

The first attempt at
a) building `enso` native-image that includes full Language Server
b) integrating the executable as an experimental feature during project
startup

The change (for now) assumes that `enso` executable appears in Enso's
default `engines` directory.
To build and run the new integration one has to
a) `engine-runner/buildNativeImage`
b) run PM with `--native-language-server`

This change also adds a copy of some of logback's code (`SocketAppender`
or a simple socket server`) as it was impossible to debug serialization
bugs without some additional logging.
@hubertp hubertp added the CI: No changelog needed Do not require a changelog entry for this PR. label Dec 16, 2024
@hubertp hubertp marked this pull request as ready for review January 2, 2025 09:18
Copy link
Member

@JaroslavTulach JaroslavTulach left a comment

Choose a reason for hiding this comment

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

  • I am glad to see language server startup improvement
  • that's what native image technology is good for and I am glad to see it delivers on its promise
  • for a while I was confused by the dependency changes
  • looks like it is mostly to access TruffleOptions.AOT from the non-Truffle part of our codebase
  • please keep Truffle API out of the dependencies of launcher, boot, etc. projects
  • use Boolean.getBoolean("com.oracle.graalvm.isaot") directly
  • I suggest to avoid introduction of --native-... CLI options
    • we may not need them at all at this stage
    • just prefer bin/enso or bin\enso.exe native binary when it exists
    • there already is well functioning --jvm option
    • we may want to expose it from project manager CLI, but
    • it is already accessible via ENSO_OPTS and that may be enough for now
  • I suggest to separate separate *-config.json and put them into language-server source tree
  • I am glad to see the Launching Enso programs instantly #10121 work moving forward

build.sbt Outdated Show resolved Hide resolved
build.sbt Show resolved Hide resolved
build.sbt Outdated Show resolved Hide resolved
build.sbt Outdated Show resolved Hide resolved
@@ -228,6 +232,19 @@ public Context build() {
.allowCreateThread(true);
}

if (engineOptions != null) {
// In AOT mode one must not use a shared engine; the latter causes issues when initializing
// message transport - it is set to `null`.
Copy link
Member

Choose a reason for hiding this comment

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

Interesting. I don't see a reason wny transport shouldn't work. Maybe it is a bug. Do we have a (small) reproducer that we could report to GraalVM guys and find out what they think?

@@ -108,7 +108,7 @@ public void onContextClosed(TruffleContext context) {}
@Override
protected void onCreate(Env env) {
this.env = env;
env.registerService(this);

if (TruffleOptions.AOT) {
Copy link
Member

Choose a reason for hiding this comment

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

The usage of TruffleOptions.AOT is correct here as this is a Truffle instrument and it needs dependency on Truffle API.

Despite being advertised as such, native image doesn't set
`com.oracle.graalvm.isaot` and it has to be provided separately if we
don't want to use `TruffleOptions`.
Context creation for AOT needs to define a separate Engine configuration
rather than using a shared engine to be able to use message transport.
engine: Engine,
jvmSettings: JVMSettings
): Seq[String] =
Seq("-Dcom.oracle.graalvm.isaot=true")
Copy link
Member

Choose a reason for hiding this comment

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

Interesting. Why do we need to provide this argument?

E.g. if we can access org.graalvm.nativeimage.ImageInfo then we can query "properly" and even distinguish between build time and runtime time.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The property is completely missing during runtime, hence not allowing me to provide different Context configuration.

@JaroslavTulach
Copy link
Member

The description should be updated as

engine-runner/buildNativeImage
Run PM with --native-language-server

may no longer reflect the reality after 3ce2577

@hubertp hubertp added the CI: Clean build required CI runners will be cleaned before and after this PR is built. label Jan 7, 2025
@hubertp hubertp merged commit 7f7d0d1 into develop Jan 7, 2025
49 checks passed
@hubertp hubertp deleted the wip/hubert/11721-language-server-native branch January 7, 2025 17:18
@JaroslavTulach
Copy link
Member

JaroslavTulach commented Jan 8, 2025

Congratulation on merging and making another step towards using native binaries as GUI backend. Notes:

  • generating enso now takes 5m 48s on my Ubuntu. Used to be 3m.
  • the enso executable size is now 350MB. Used to be ~200MB.

This is the top ten of included packages:

Top 10 origins of code area:
  21.50MB js-language-24.0.0.jar
  15.69MB java.base
   6.75MB org.graalvm.truffle
   5.48MB jdk.internal.vm.compiler
   4.81MB java.xml
   4.15MB akka-http-core_2.13-10.2.10.jar
   4.14MB poi-5.2.3.jar
   3.87MB icu4j-24.0.0.jar
   3.34MB org.enso.languageserver.protocol.json

hubertp added a commit that referenced this pull request Jan 10, 2025
Previosly we were wrongly relying on the presence of the file. That way,
a bash script meant that NI integration was wrongly used.
This change uses Tika, but it has already been present in other
subprojects so no additional dependency shall be added.

Follow up on #11880.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: Clean build required CI runners will be cleaned before and after this PR is built. CI: No changelog needed Do not require a changelog entry for this PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants