utopia-rise / godot-kotlin-jvm

Godot Kotlin JVM Module
MIT License
576 stars 39 forks source link

Fix ide plugin performance issues #530

Closed chippmann closed 9 months ago

chippmann commented 10 months ago

Fixes #520

TL;DR

The performance problem should now be fixed. I can currently see no more heavy computations on my machine when using the profiler, but I encourage you to test this on your machines as well (@CedNaru, I'd be particularly grateful if you could test it on your machine, as you could reproduce the issue previously).

To test this, check out the project and run gradlew buildPlugin. Then from the IDE, navigate to the plugins window, click the gear icon and select Install plugin from disk. Then choose the zip file located under kt/plugins/godot-intellij-plugin/build/distributions.

Other small fixes

The core type check threw some exceptions as i tried to apply the error to a "most relevant" parent. But in some cases this parent was "out of scope" for the error annotation and thus throwing an exception. I now just add the error where it actually happens. Which in the case of core type checks can mean that the error is reported more than once in one line (which is technically correct anyways). I also corrected the corresponding error message.

Explanation of the Performance Issue

The root cause of the performance issue was the detection process used to determine if we were operating within a Godot project. Ironically, this check was in place to essentially disable our checks for non-Godot projects - it mainly caused problems for non-Godot projects (almost instantly causing issues) and, depending on the machine and project complexity, for Godot projects as well.

In our main plugin service file, we have a GodotRoot cache which stores for each IntelliJ module (not to be confused with a Gradle module!) if it resides in a Godot root. To determine this, we query Gradle for each IntelliJ module to see if it's within a Gradle project. If it is, we acquire the root directory of that Gradle project and search for a project.godot file in it. If we find one, we assume the project is a Godot project. If not, we essentially disable all checks in our plugin by returning instantly in each check we conduct.

Three problems in this check essentially lead to these performance issues