lihop / godot-xterm

Terminal emulator for the Godot game engine.
MIT License
99 stars 15 forks source link

Long loading time on Godot 4.2 due to `Terminal::set_default_theme_items` in `Terminal` constructor #104

Closed rpaciorek closed 4 months ago

rpaciorek commented 4 months ago

Adding godot-xterm addon increases the startup time of Godot 4.2 from approximately 7 to 30 seconds. All this extra time is spent on the first call of set_default_theme_items from Terminal constructor.

Removing this call:

diff --git a/addons/godot_xterm/native/src/terminal.cpp b/addons/godot_xterm/native/src/terminal.cpp
index 3796240..bb4ff83 100644
--- a/addons/godot_xterm/native/src/terminal.cpp
+++ b/addons/godot_xterm/native/src/terminal.cpp
@@ -95,7 +95,6 @@ void Terminal::_bind_methods()

 Terminal::Terminal()
 {
-       set_default_theme_items();
        set_focus_mode(FOCUS_ALL);

        max_scrollback = 1000;

fixes the problem and appears to have no side effects.

Additionally, calling set_default_theme_items from GdScript (after adding the appropriate bind) is quick, so it looks like some problem with the constructor and set_default_theme_items being called at the wrong time (too early) when Godot is started.

lihop commented 4 months ago

Thanks for identifying this. I found it to be related to https://github.com/godotengine/godot-cpp/issues/1332. Applying the workaround suggested in https://github.com/godotengine/godot-cpp/issues/1332 resolves the issue.