From ddd03ee818af9f0d63a02c9164df5b397a265307 Mon Sep 17 00:00:00 2001 From: Jordan Schidlowsky Date: Wed, 9 Oct 2024 15:11:20 -0600 Subject: [PATCH] static inline is bad. Generates way too much code that the linker is unable to optimize and remove on final link. This causes these symbols from every class in godot-cpp to be included in the final link, even if completely unused by the lib. Removing changes a basic shared library from being ~1.5MB on almost all platforms to now ~200kB. --- include/godot_cpp/classes/ref.hpp | 2 +- include/godot_cpp/classes/wrapped.hpp | 4 ++-- src/classes/wrapped.cpp | 4 ++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/include/godot_cpp/classes/ref.hpp b/include/godot_cpp/classes/ref.hpp index 137b677b..569cdfa0 100644 --- a/include/godot_cpp/classes/ref.hpp +++ b/include/godot_cpp/classes/ref.hpp @@ -219,7 +219,7 @@ public: // Used exclusively in the bindings to recreate the Ref Godot encapsulates in return values, // without adding to the refcount. - inline static Ref _gde_internal_constructor(Object *obj) { + static Ref _gde_internal_constructor(Object *obj) { Ref r; r.reference = (T *)obj; return r; diff --git a/include/godot_cpp/classes/wrapped.hpp b/include/godot_cpp/classes/wrapped.hpp index 0ffd783f..6fdc5465 100644 --- a/include/godot_cpp/classes/wrapped.hpp +++ b/include/godot_cpp/classes/wrapped.hpp @@ -77,7 +77,7 @@ protected: GDExtensionObjectPtr owner; RecreateInstance *next; }; - inline static RecreateInstance *recreate_instance = nullptr; + static RecreateInstance *recreate_instance; #endif void _notification(int p_what) {} @@ -408,7 +408,7 @@ private: // Don't use this for your classes, use GDCLASS() instead. #define GDEXTENSION_CLASS_ALIAS(m_class, m_alias_for, m_inherits) /******************************************************************************************************************/ \ private: \ - inline static ::godot::internal::EngineClassRegistration _gde_engine_class_registration_helper; \ + static ::godot::internal::EngineClassRegistration _gde_engine_class_registration_helper; \ void operator=(const m_class &p_rval) {} \ friend class ::godot::ClassDB; \ friend class ::godot::Wrapped; \ diff --git a/src/classes/wrapped.cpp b/src/classes/wrapped.cpp index ffca4f97..a5e87bc5 100644 --- a/src/classes/wrapped.cpp +++ b/src/classes/wrapped.cpp @@ -42,6 +42,10 @@ namespace godot { thread_local const StringName *Wrapped::_constructing_extension_class_name = nullptr; thread_local const GDExtensionInstanceBindingCallbacks *Wrapped::_constructing_class_binding_callbacks = nullptr; +#ifdef HOT_RELOAD_ENABLED +Wrapped::RecreateInstance *Wrapped::recreate_instance = nullptr; +#endif + const StringName *Wrapped::_get_extension_class_name() { return nullptr; }