-
-
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
Speed up GDScript::get_must_clear_dependencies()
#85603
Speed up GDScript::get_must_clear_dependencies()
#85603
Conversation
GDScript::get_must_clear_dependencies()
For the record, your commit seems not to be linked to your GitHub account. See: Why are my commits linked to the wrong user? for more info. |
f53ff0e
to
1963d61
Compare
Sorry about that (I'm quite new to this process), now it should be linked to the correct account. |
1963d61
to
9657341
Compare
This is an improvement indeed but I think Note that I'm not really familiar with the GDScript internals so maybe I'm missing something and it's not that simple? Anyway, could potentially be done in another PR, this is already an improvement. |
GDScript::get_must_clear_dependencies()
GDScript::get_must_clear_dependencies()
But this isn't about |
Can confirm that with The Mirror we see a hugely expensive shutdown time because of this function. Benchmarked using superluminal profiler and it showed this function was consuming 100% CPU for over 90 seconds during shutdown. I'll test this fix and report back the app close time :) |
It is and it isn't, depends how you look at it. 🙃 #85435 which this PR aims to fix is specifically about slow quiting (both editor/runtime) when there are many cross referencing/dependant scripts. This is caused by the slow execution of So this PR makes What I've said in #85603 (comment) is that TLDR: this PR is good on its own but BTW Yeah, would be nice if some benchmark times would be provided for before/after. In the end even if it helps with #85435 (it does) it still might need be considered as not fixing it if the timings are still not satisfying. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eldidou Thanks for your PR! For a first PR, that's a nice one!
I'm trying to see if there's things that could break with your implementation, but the logic seems fine. The idea to skip the dependencies if they don't include the current script is a good idea. It does what I thought to do when I implemented inverse dependency checks.
I asked @vnen and @dalexeev to review it, but so far, I like it.
4 seconds to close the editor (previously multiple minutes) This makes it much more deterministic for me. Tested on windows. |
9657341
to
0780278
Compare
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
0780278
to
0d77c3e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems fine to me. It improved my logic and I don't see how the new logic would not cover my old one.
Especially with all the tests passing, I'm OK merging this very soon.
Thanks! And congratulations on your first merged Godot contribution! That's a very cool way to enter the space 🙂 |
Thanks! Glad to help 🙂 |
@eldidou Don't hesitate to join our developer's chat. We have a GDScript public meeting tomorrow. |
Cherry-picked for 4.2.2. |
Seeing as how this slowdown still remains a problem when you go into the hundreds of scripts (with more complex dependencies), I've gone ahead and made the change that was talked about earlier in this thread, by simply skipping the It seemed like a straight-forward enough of a change, and passes all the unit tests and whatnot, but I'd appreciate some more eyes on it. |
get_must_clear_dependencies() has a N^3log(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^2log(N).
Instead of using all the inverted dependencies, we do the same with all (non-inverted) dependencies, which is N times faster.
Fixes #85435