kotlin-language-server icon indicating copy to clipboard operation
kotlin-language-server copied to clipboard

Perform incremental compilation using official compiler API

Open fwcd opened this issue 7 years ago • 7 comments

Investigate support for incremental compilation using the official Kotlin compiler API instead of the mechanism currently used (as described in the README), because this might improve performance considerably.

fwcd avatar Jun 11 '18 21:06 fwcd

This might be related:

Caused by: java.lang.OutOfMemoryError: GC overhead limit exceeded
	at java.util.Arrays.copyOfRange(Arrays.java:3664)
	at java.lang.String.<init>(String.java:207)
	at java.lang.String.substring(String.java:1969)
	at java.lang.String.subSequence(String.java:2003)
	at kotlin.text.StringsKt__StringsKt.commonPrefixWith(Strings.kt:775)
	at kotlin.text.StringsKt__StringsKt.commonPrefixWith$default(Strings.kt:765)
	at org.javacs.kt.position.PositionKt.changedRegion(position.kt:95)
	at org.javacs.kt.CompiledFile.oldOffset(CompiledFile.kt:114)
	at org.javacs.kt.CompiledFile.parseAtPoint(CompiledFile.kt:72)
	at org.javacs.kt.signatureHelp.SignatureHelpKt.signatureHelpAt(signatureHelp.kt:22)
	at org.javacs.kt.KotlinTextDocumentService.signatureHelp(KotlinTextDocumentService.kt:128)
	at sun.reflect.GeneratedMethodAccessor76.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.lambda$null$0(GenericEndpoint.java:61)
	at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint$$Lambda$35/698288148.apply(Unknown Source)

fwcd avatar Jun 11 '18 21:06 fwcd

Is incremental compilation needed for code completion or for what purpose? How does the kotlin-web-demo handle completion?

https://github.com/JetBrains/kotlin-web-demo/tree/master/versions/1.2.50/src/main/java/org/jetbrains/webdemo/kotlin/impl

apatrida avatar Jun 19 '18 11:06 apatrida

@apatrida Each file needs to be compiled to an abstract syntax tree by the Kotlin compiler frontend. Using the AST, the language server can provide document symbols, code completion, hover and more.

The naive solution to this problem would be to compile the entire file every time the user makes an edit, but that would be extremly slow (and make your editor feel laggy). To address this problem, the language server currently extracts the expression around the cursor, puts it into a small "fake" file and tells the compiler to compile the "fake" file. Still, it would probably be better to use official compiler APIs as mentioned in the issue description.

The Kotlin demo seems to be promising in terms of performance, I will take a closer look at it soon.

fwcd avatar Jun 19 '18 16:06 fwcd

I don't know well enough how the current method works (lots of methods disappearing into 3rd party packages etc), but would this solve the synchronization issue where e.g. a property is referenced in one "expression" but doesnt exist yet, is added at the relevant location, yet the error that its missing still persists?

on a side note, is there a gitter or some other more convenient place where people can discuss this project with you?

Strum355 avatar Oct 21 '18 23:10 Strum355

@Strum355 There is a new Gitter channel for this project:

Gitter

fwcd avatar Oct 22 '18 13:10 fwcd

@fwcd I am also interested in incremental compilation, and what is the newest pointers on this? Thanks.

xiaoyunwu avatar Feb 02 '22 17:02 xiaoyunwu

Sounds very promising to improve performance. Is it complicated to add this?

weilbith avatar Sep 05 '23 19:09 weilbith