Skip to content

Commit 60966f5

Browse files
committed
Merge pull request godotengine#94505 from mihe/speed-up-gdscript-shutdown
Speed up `GDScriptLanguage::finish`
2 parents caa1b6d + 6852f94 commit 60966f5

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

modules/gdscript/gdscript.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,10 +1537,14 @@ void GDScript::clear(ClearData *p_clear_data) {
15371537
}
15381538
}
15391539

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

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

22482252
void GDScriptLanguage::finish() {
2253+
if (finishing) {
2254+
return;
2255+
}
2256+
finishing = true;
2257+
22492258
_call_stack.free();
22502259

22512260
// Clear the cache before parsing the script_list
@@ -2281,6 +2290,8 @@ void GDScriptLanguage::finish() {
22812290
}
22822291
script_list.clear();
22832292
function_list.clear();
2293+
2294+
finishing = false;
22842295
}
22852296

22862297
void GDScriptLanguage::profiling_start() {

modules/gdscript/gdscript.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,8 @@ class GDScriptLanguage : public ScriptLanguage {
411411

412412
static GDScriptLanguage *singleton;
413413

414+
bool finishing = false;
415+
414416
Variant *_global_array = nullptr;
415417
Vector<Variant> global_array;
416418
HashMap<StringName, int> globals;

0 commit comments

Comments
 (0)