-
Notifications
You must be signed in to change notification settings - Fork 323
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
Pre compute suggestion db during build time #5698
Pre compute suggestion db during build time #5698
Conversation
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.
Thanks Dmitry, I think I know what to do now.
engine/runtime/src/main/scala/org/enso/compiler/SuggestionsSerializationManager.scala
Outdated
Show resolved
Hide resolved
@@ -493,6 +465,13 @@ final class SuggestionsHandler( | |||
updates.foreach(sessionRouter ! _) | |||
context.become(initialized(name, graph, clients, state)) | |||
|
|||
case libraryLoaded: Api.LibraryLoaded => | |||
logger.debug( |
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.
@4e6's idea is to deliver the cached suggestion.json
here. However I haven't hit a breakpoint placed here yet. I am not sure who's supposed to deliver this message? Probably we are missing a call to NotificationHandler.addListener
that would register SuggestionHandler
. Probably the listener shall be attached when case InitializedEvent.TruffleContextInitialized
is delivered - by where can I find the EnsoContext
at that moment?
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.
One has to subscribe to Akka event bus to get the notification - f480e03
But now there is another problem: The SuggestionSerializationManager
is in runtime, while this code is in language-server
- how shall these two talk to each other? I believe this "library added" notification is send from following stacktrace:
at org.enso.interpreter.instrument.Endpoint.sendToClient(Handler.scala:48)
at org.enso.interpreter.instrument.NotificationHandler$InteractiveMode.sendMessage(NotificationHandler.scala:110)
at org.enso.interpreter.instrument.NotificationHandler$InteractiveMode.addedLibrary(NotificationHandler.scala:123)
at org.enso.interpreter.instrument.NotificationHandler$Forwarder.$anonfun$addedLibrary$1(NotificationHandler.scala:80)
at org.enso.interpreter.instrument.NotificationHandler$Forwarder.$anonfun$addedLibrary$1$adapted(NotificationHandler.scala:79)
at scala.collection.immutable.List.foreach(List.scala:333)
at org.enso.interpreter.instrument.NotificationHandler$Forwarder.addedLibrary(NotificationHandler.scala:79)
at org.enso.compiler.PackageRepository$Default.registerPackageInternal(PackageRepository.scala:326)
I believe the next step is to modify code in PackageRepository
to check whether a suggestion cache exists for the library. If it does, read it and send the content of the suggestions via the Api.LibraryLoaded
messages to the "language-server" project that can distribute it further. The following code shall be modified to send also librarySuggestions
:
if (isLibrary) {
val root = Path.of(pkg.root.toString)
notificationHandler.addedLibrary(libraryName, libraryVersion, root)
}
…mpute-suggestion-db-during-build-time
Added a last-modified cache for stdlib files so that we don't generate index every single time.
…' of enso:enso-org/enso into wip/db/5068-pre-compute-suggestion-db-during-build-time
engine/runtime/src/test/java/org/enso/compiler/test/context/JacksonTest.java
Show resolved
Hide resolved
engine/runtime/src/main/scala/org/enso/compiler/context/SuggestionDiff.scala
Outdated
Show resolved
Hide resolved
2215f5a
to
6638c9d
Compare
|
||
@Override | ||
protected byte[] metadata(String sourceDigest, String blobDigest, CachedSuggestions entry) { | ||
var mapper = new ObjectMapper(); |
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.
Shouldn't the mapper
be a field in the cache? Unless I am mistaken the ObjectMapper
instance maintains mapping from Class
to "functionality". If we create new instance for every library, then its internal mapping must be initialized every time.
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.
It seems that since version 2, the ObjectMapper
creation is cheap https://stackoverflow.com/questions/18611565/how-do-i-correctly-reuse-jackson-objectmapper#comment27463038_18615839
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.
That's not what I experienced. This causes major slowdowns, which is why I also changed it in #5791
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.
That's not what I experienced. This causes major slowdowns, which is why I also changed it in #5791
} | ||
} | ||
|
||
// CachedSuggestions class is not a record because of a Frgaal bug leading to invalid compilation error. |
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.
What is the error? Maybe updating to new version of frgaal would fix the problem. If I modify:
enso$ git diff
diff --git engine/runtime/src/main/java/org/enso/compiler/SuggestionsCache.java engine/runtime/src/main/java/org/enso/compiler/SuggestionsCache.java
index f5d65b8e0..220c01e9c 100644
--- engine/runtime/src/main/java/org/enso/compiler/SuggestionsCache.java
+++ engine/runtime/src/main/java/org/enso/compiler/SuggestionsCache.java
@@ -125,16 +125,7 @@ public final class SuggestionsCache
}
// CachedSuggestions class is not a record because of a Frgaal bug leading to invalid compilation error.
- public final static class CachedSuggestions {
-
- private final LibraryName libraryName;
- private final Suggestions suggestions;
-
- public CachedSuggestions(LibraryName libraryName, Suggestions suggestions) {
- this.libraryName = libraryName;
- this.suggestions = suggestions;
- }
-
+ public record CachedSuggestions(LibraryName libraryName, Suggestions suggestions) {
public LibraryName getLibraryName() {
return libraryName;
}
I am seeing:
sbt:enso> buildEngineDistribution
[info] compiling 45 Scala sources and 191 Java sources to /enso/engine/runtime/target/scala-2.13/classes ...
[error] /enso/engine/runtime/src/main/java/org/enso/compiler/SuggestionsCache.java:128:17: not found: type java
[error] public record CachedSuggestions(LibraryName libraryName, Suggestions suggestions) {
[error] ^
[error] one error found
That's a wild error. Reported to the frgaal project.
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.
Yes, this is what I was seeing as well and the reason why in other cases I don't use the record. Thanks for reporting it with frgaal
name = libraryName.name, | ||
version = libraryVersion.toString, | ||
location = location.toFile | ||
) | ||
) |
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.
I thought that the Api.LibraryLoaded
should be enhanced with optional list of suggestions. However it looks like the proposal is to send a message to self and deserialize the suggestions later. Assuming the deserialization is instant - is there any benefit of sending the suggestions in a separate message?
@@ -1,6 +1,7 @@ | |||
package org.enso.languageserver.search | |||
|
|||
import org.enso.docs.generator.DocsGenerator | |||
import org.enso.docs.sections.DocSectionsBuilder |
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.
Probably unnecessary import.
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.
The change in micro-distribution
looks OK.
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.
Minor nits but overall looks ok
libraryLoaded.namespace, | ||
libraryLoaded.name | ||
) | ||
System.err.println("Loaded library: " + libraryLoaded.name) |
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 looks spurious
} yield { | ||
val treeUpdates = treeResults.flatMap { | ||
case QueryResult(ids, Api.SuggestionUpdate(suggestion, action)) => | ||
val verb = action.getClass.getSimpleName |
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.
can be moved to the condition with the log using it?
|
||
@Override | ||
protected byte[] metadata(String sourceDigest, String blobDigest, CachedSuggestions entry) { | ||
var mapper = new ObjectMapper(); |
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.
That's not what I experienced. This causes major slowdowns, which is why I also changed it in #5791
|
||
@Override | ||
protected byte[] metadata(String sourceDigest, String blobDigest, CachedSuggestions entry) { | ||
var mapper = new ObjectMapper(); |
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.
That's not what I experienced. This causes major slowdowns, which is why I also changed it in #5791
} | ||
} | ||
|
||
// CachedSuggestions class is not a record because of a Frgaal bug leading to invalid compilation error. |
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.
Yes, this is what I was seeing as well and the reason why in other cases I don't use the record. Thanks for reporting it with frgaal
} | ||
|
||
try { | ||
val suggestions = new util.ArrayList[Suggestion]() |
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.
shouldn't this rather be refactored to a separate method?
@4e6 I think documentation needs to be updated as well? |
Pull Request Description
Close #5068
Cache suggestions during the
buildEngineDistribution
command, and read them from the disk when the library is loaded. Initial graph coloring takes ~20 seconds vs ~25 seconds on the develop branch.peek-develop-branch.webm
peek-suggestions-branch.webm
Important Notes
Checklist
Please include the following checklist in your PR:
Scala,
Java,
and
Rust
style guides.
If GUI codebase was changed: Enso GUI was tested when built using BOTH
./run ide build
and./run ide watch
.