-
-
Notifications
You must be signed in to change notification settings - Fork 23.3k
#34161: Keep a weak reference to orphan subclasses to reuse on class reload #35102
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
#34161: Keep a weak reference to orphan subclasses to reuse on class reload #35102
Conversation
I have tested and this seems to fix #30557 as well |
This is better but I fear it has the same problem as the other PR: references are kept alive forever. The difference here is that only some inner classes will be kept. But once they are in that list, they'll only be freed when the application ends. Maybe we can do a similar thing but only in smaller contexts. For instance, keep this list for the parser while it's running. Or for the compiler it can keep a list of external references in the actual GDScript, so it can take them away when it's freed. Still, I'm not confident in merging such a solution for 3.2 this close to the release. |
Why do you think that they are kept alive forever? |
I see, I should have another coffee before reading the code. I guess this is a good solution, since it avoids recreating the inner classes when the owner script is reloaded, so the memory address don't change. |
Also, #35122 should be merged first, so this PR can be updated to use the fully qualified names. |
Looks good, thanks. Just need to squash the commits into one. See http://docs.godotengine.org/en/latest/community/contributing/pr_workflow.html#mastering-the-pr-workflow-the-rebase |
c3b66e0
to
e3fa516
Compare
e3fa516
to
86aa12e
Compare
Done, its a single commit now |
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.
Looks good. It's a clever solution while we don't have the proper ScriptCache.
Thanks! |
This change is a second attempt to fix #34161
first attempt is here: #35027
Bugsquad edit: also fixes #30557.
In this change, when a GDScript is destroyed, an ObjectID is kept on GDScriptLanguage for each subclass that is still in use.
when the GDScript is loaded again, it checks if an orphan subclass is still available and reuses it.
To be considered:
the ObjectID is kept in a Map where the Key is a string in the format CLASS:SUBCLASS, this means that there is no support for multiple levels of subclasses, only one.
IMO, every class should keep a fully qualified name, or some other UNIQUE_ID that is stable and reproducible without requiring a full load of the subclass.