-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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
Exponentially slow quitting time with dependencies between (gdscript) scripts #85435
Comments
Here is a stack trace if I try to attach to the process when it's seems stuck trying to quit:
|
After further investigation, it seems that indeed all of the time is spent in Looking at the code it seems doable to reduce it to at least |
get_must_clear_dependencies() has a N^3*log(N) time complexity, and this can very quickly slow down the quitting process as more gdscripts are added in a project. This change improves it to N^2*log(N). Instead of using all the inverted dependencies, we do the same with all (non-inverted) dependencies, which is N times faster. Fixes godotengine#85435 (cherry picked from commit 0d77c3e)
get_must_clear_dependencies() has a N^3*log(N) time complexity, and this can very quickly slow down the quitting process as more gdscripts are added in a project. This change improves it to N^2*log(N). Instead of using all the inverted dependencies, we do the same with all (non-inverted) dependencies, which is N times faster. Fixes godotengine#85435
Godot version
Godot v4.2.rc2
System information
Godot v4.2.rc2 - Ubuntu 22.04.3 LTS 22.04 - X11 - Vulkan (Forward+) - integrated Intel(R) UHD Graphics (CML GT2) () - Intel(R) Core(TM) i7-10850H CPU @ 2.70GHz (12 Threads)
Issue description
When there is a lot of dependencies between types defined with class_name or class, the quitting time for game (and editor) grows exponentially.
With a "real" project (nb of scripts: 97, nb lignes of code: 11638, nb dependencies between script: 336) the quitting time is ~8.0s.
I could manage to reduce it to ~5.0s just by moving an inner class from one file to another.
On a "toy" project, with N scripts doing nothing except depending on each others, the quitting time seems exponential:
Adding the dependencies as a type check (
if my_var is MyType
) triggers the issue.Adding the dependencies as a type creation (
MyType.new()
) triggers the issue.Adding the dependencies as type hinting (
var my_var : MyType
) doesn't triggers the issue.Adding inner (unused) classes inside these script increases a lot the time.
The dependencies being cyclical or not doesn't seems to change the behavior.
Same issue with 4.1.2-stable.
Steps to reproduce
for example for script0.gd:
in the script of the main scene, add a dependency to one of the N inter-depending scripts, for example with
print(null is Script0)
then quit directly the scene, with
get_tree().quit()
launch the main scene
If N is high enough (>50), it will start to quit directly, but the quitting time will be long.
The quitting time will also be quite long.
note: a python script has been provided in the minimal project to create all the N inter-depending gdscript scripts of step 1.
Minimal reproduction project
quitting_time_dependencies.zip
The text was updated successfully, but these errors were encountered: