Drastic performance improvements when indexing IntelliJ files #571
Replies: 3 comments 4 replies
-
@angelozerr We were just discussing this PR yesterday though from the perspective of a pain point we've had with automated testing. The UI robot we're using tries to interact with the editor to look at diagnostics, apply quick fixes, check the text in hover, etc... and indexing makes the timing of all that challenging. Seems like this could also be a great programmatic solution for writing reliable tests. |
Beta Was this translation helpful? Give feedback.
-
@CppCXY @InSyncWithFoo @seachicken @KUGDev @AlexWeinstein92 @aparnamichael @MituuZ @turkeylurkey @mrglavas @koxudaxi @FalsePattern @onriv @kristofvb @themartdev @kdvolder please test my PR #570 which could have some impact. The idea of this PR is to:
Please try this PR by installing the build zip (see instruction at https://github.com/redhat-developer/lsp4ij?tab=readme-ov-file#testing-the-ci-builds) andplease give me feedback, because I would like to really merge this PR which is very imptant to keep good performance when IJ is starting and in our case with IJ Quarkus to avoid having error like redhat-developer/intellij-quarkus#1373 or other like lossing some codelens, diagnostics in Java files. So the change with this PR, no LSP features like codelens, completion, etc will not be available when IJ is indexing. Thanks so much for your feedback! |
Beta Was this translation helpful? Give feedback.
-
@CppCXY @InSyncWithFoo @seachicken @KUGDev @AlexWeinstein92 @aparnamichael @MituuZ @turkeylurkey @mrglavas @koxudaxi @FalsePattern @onriv @kristofvb @themartdev @kdvolder I merged the PR after doind a lot of tests with IJ Quarkus, with other language servers and it seems it is working pretty well:
I have used this refresh editor codelens, inlay hint also:
Hope it will not have some trouble with your language servers, you can test this feature with https://github.com/redhat-developer/lsp4ij?tab=readme-ov-file#testing-nightly-builds I need to fix some other issues but I would like to create ASAP a new release of LSP4IJ 0.8.0, so please give me feedback ASAP to fix some troubles before the release. Thanks! |
Beta Was this translation helpful? Give feedback.
-
After spending hours and hours trying to fix the problem we have with our MicroProfile LS and Qute LS language server redhat-developer/intellij-quarkus#1373 I intend to make a major change in LSP4IJ. This will not impact the API (I hope) but rather:
the behavior of language server startups
(for most language servers)the execution of some LSP features
(codelens, highlight, etc).Start the language servers after the "Scannings files to index..." process
After having carried out numerous tests, I was able to notice that if we open several projects which must start several language servers and that when opening each project which opens editors which had not been closed during the previous closing of IntelliJ, IntelliJ launches its process of "Scannings files to index...", the performances are catastrophic!
To have better performance, we should start language servers after the "Scannings files to index..." process
This new behavior would be done by default, but if I can do it I would like to be able to provide a new method in the LSPCLientFeature that would disable this behavior to go back to the way it was before if you ever want to have your language server available as soon as possible (but this will impact IntelliJ launch performance if it runs "Scannings files to index...".
To set up this mechanism, it is a real challenge because the launch of the language servers is done
I created a POC at https://github.com/redhat-developer/lsp4ij/pull/570/files which when the editor opens, waits via a CompletableFuture for the indexing to be finished, to then start the language server, which then performs a didOpen. But the editor that opens asks to display the CodeVision which also forces the start of the language server which waits for the didOpen to be done (hence the IntelliJ freezes). In my POC I disabled the codelens, highlight when there is an indexing that is being done. This allows IntelliJ to do its idexation, then start the language servers once the indexing is finished. As a result, the codelens are not displayed. If we refresh the editor by modifying its content, the codelens are displayed again. I need to study how we can manage that.
This is where there is a big challenge: refreshing the codelens, highlight, etc. when the indexing is finished.
Technically, to set up this mechanism you need to know when the file indexing and dumb mode have finished. My first tests were to use DumService.isDumb(Project) and runWhenSmart which failed.
Indeed these 2 methods work well when IntelliJ is in dumb mode but not when it is executing the "Scannings files to index...". I managed to know when IntelliJ is in indexing state by by implementing ProjectIndexingActivityHistoryListener (see my PR https://github.com/redhat-developer/lsp4ij/pull/570/files).
Execution of some LSP features only when IntelliJ is not indexing
This point should not concern you if your server language does not delegate the parsing of the document to IntelliJ.
In the case of MicroProfile LS, Qute LS delegates the calculation of Codelens in Java files to IntelliJ to visit these files and know where the codelens should be displayed and their contents calculated according to the Java field names etc.
Since we are visiting Java files, we must do so only if the indexing is complete. The editor asks to display CodeVision, this calls our language servers which should not return anything if there is an indexing. When the indesaction ends (and the content of the editor has not changed since), this must refresh the codelens by visiting the Java files which are indexed correctly and which allows to avoid this error redhat-developer/intellij-quarkus#1373
For us this is very important for our IntelliJ Quarkus plugin and we need to have this feature as soon as possible because many users are complaining about all these errors.
But I don't know when I will be done with it, so maybe it would be more prudent to create a LSP4IJ 0.7.0 release next week for example. @fbricon what do you think about that?
cc @CppCXY @InSyncWithFoo @seachicken @KUGDev @AlexWeinstein92 @aparnamichael @MituuZ @turkeylurkey @mrglavas @koxudaxi @FalsePattern @onriv @kristofvb @themartdev @kdvolder please follow this important discussion.
Beta Was this translation helpful? Give feedback.
All reactions