eclipse.jdt.ls
eclipse.jdt.ls copied to clipboard
organize import takes a long time for a gradle project which has large amount of files.
Hi folks Our team has a large gradle project. It has 33732 total files, 20693 total .java files. there are about 125 subprojects in the root folder.
I am using vim + coc-java + eclipse.jdt.ls as my working evnironemnt. I am using eclipse.jdt.ls version 0.58 since that is the latest version compatible with Java8.
Based on log message, it took about less than 2 mins to start the server, it is longer than other smaller project, but still acceptable I think.
47 !ENTRY org.eclipse.jdt.ls.core 1 0 2020-12-05 15:06:27.739
48 !MESSAGE No previous Gradle project at /path/to/the/repo, it must be synchronized
50 !ENTRY org.eclipse.jdt.ls.core 1 0 2020-12-05 15:08:14.821
51 !MESSAGE Workspace initialized in 107466ms
After the server is started, features like goToDefinition works with no problem. However, the organize import feature takes quite a long time to start to work.
I tried to put some log message in org.eclipse.jdt.ls.core.internal.handlers.OrganizeImportsHandler
file,
it looks like it is "paused" at line 77 OrganizeImportsOperation op = new OrganizeImportsOperation(unit, astRoot, true, false, true, (TypeNameMatch[][] openChoices, ISourceRange[] ranges) -> {
Is there any suggestion on how to improve the time needed for organize import to work?
I have two experiences that makes me believe that it feels something needs to be calculated in order to make organize import to work, and this calculation takes long time. This calculation is stored somewhere and is not cleaned until a clean workspace is run.
- I started the server and then start to do sth else and forget about it. Then I come back after a long time, then the organize import immediately worked.
- Once the organize import starts to work, I feel if I exit the vim and then open the vim again, after eclipse.jdt.ls is started, the organize import immediately starts to work. It feels some results are stored in somewhere and it doesn't need to be re-calculated in this case. If I do "java.clean.workspace" (command by coc-java), I will need to wait a long time for organize to work again.
67 public static TextEdit organizeImports(ICompilationUnit unit, Function<ImportSelection[], ImportCandidate[]> chooseImports) {
68 JavaLanguageServerPlugin.logInfo("OrganizeImportsHandler.organizeImports organizeImports");
69 if (unit == null) {
70 return null;
71 }
72 JavaLanguageServerPlugin.logInfo("OrganizeImportsHandler.organizeImports before RefactoringASTParser");
73 RefactoringASTParser astParser = new RefactoringASTParser(IASTSharedValues.SHARED_AST_LEVEL);
74 JavaLanguageServerPlugin.logInfo("OrganizeImportsHandler.organizeImports before astParser.parse");
75 CompilationUnit astRoot = astParser.parse(unit, true);
76 JavaLanguageServerPlugin.logInfo("OrganizeImportsHandler.organizeImports before OrganizeImportsOperation");
77 OrganizeImportsOperation op = new OrganizeImportsOperation(unit, astRoot, true, false, true, (TypeNameMatch[][] openChoices, ISourceRange[] ranges) -> {
78 JavaLanguageServerPlugin.logInfo("OrganizeImportsHandler.organizeImports each OrganizeImportsOperation");
79 List<ImportSelection> selections = new ArrayList<>();
80 for (int i = 0; i < openChoices.length; i++) {
81 ImportCandidate[] candidates = Stream.of(openChoices[i]).map((choice) -> new ImportCandidate(choice)).toArray(ImportCandidate[]::new);
Not sure why log "OrganizeImportsHandler.organizeImports each OrganizeImportsOperation" was never printed out. And based on the following log
237 !ENTRY org.eclipse.jdt.ls.core 1 0 2020-12-05 15:18:29.065
238 !MESSAGE OrganizeImportsHandler.organizeImports before OrganizeImportsOperation
239
240 !ENTRY org.eclipse.jdt.ls.core 1 0 2020-12-05 15:52:26.760
241 !MESSAGE >> document/didChange
It feels like it takes about 34 minutes for the "calculation" to complete
Would you be able to check if this is still an issue with snapshot release of JDT-LS from tomorrow (Dec. 8) : https://download.eclipse.org/jdtls/snapshots/ ? A performance issue was resolved as part of https://github.com/redhat-developer/vscode-java/issues/3383 that also affected "Organize Imports" .