Skip to content
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 GDScriptLanguage::finish #94505

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions modules/gdscript/gdscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1537,10 +1537,14 @@ void GDScript::clear(ClearData *p_clear_data) {
}
}

RBSet<GDScript *> must_clear_dependencies = get_must_clear_dependencies();
for (GDScript *E : must_clear_dependencies) {
clear_data->scripts.insert(E);
E->clear(clear_data);
// If we're in the process of shutting things down then every single script will be cleared
// anyway, so we can safely skip this very costly operation.
if (!GDScriptLanguage::singleton->finishing) {
RBSet<GDScript *> must_clear_dependencies = get_must_clear_dependencies();
for (GDScript *E : must_clear_dependencies) {
clear_data->scripts.insert(E);
E->clear(clear_data);
}
}

for (const KeyValue<StringName, GDScriptFunction *> &E : member_functions) {
Expand Down Expand Up @@ -2246,6 +2250,11 @@ String GDScriptLanguage::get_extension() const {
}

void GDScriptLanguage::finish() {
if (finishing) {
return;
}
finishing = true;

_call_stack.free();

// Clear the cache before parsing the script_list
Expand Down Expand Up @@ -2281,6 +2290,8 @@ void GDScriptLanguage::finish() {
}
script_list.clear();
function_list.clear();

finishing = false;
}

void GDScriptLanguage::profiling_start() {
Expand Down
2 changes: 2 additions & 0 deletions modules/gdscript/gdscript.h
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,8 @@ class GDScriptLanguage : public ScriptLanguage {

static GDScriptLanguage *singleton;

bool finishing = false;

Variant *_global_array = nullptr;
Vector<Variant> global_array;
HashMap<StringName, int> globals;
Expand Down
Loading