Skip to content

Commit

Permalink
Don't box params on Native->C# calls with Variant params
Browse files Browse the repository at this point in the history
Godot uses Variant parameters for calls to script methods.
Up until now we were boxing such parameters when marshalling
them for invokation, even if they were value types.

Now Godot allocates the marshalled parameters on the stack,
reducing the GC allocations resulted from boxing.
  • Loading branch information
neikeq authored and raulsntos committed Nov 3, 2021
1 parent a05aefb commit b775573
Show file tree
Hide file tree
Showing 12 changed files with 686 additions and 623 deletions.
2 changes: 1 addition & 1 deletion modules/mono/csharp_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2479,7 +2479,7 @@ bool CSharpScript::_get_signal(GDMonoClass *p_class, GDMonoClass *p_delegate, Ve

if (mono_type_get_type(raw_type) == MONO_TYPE_CLASS) {
// Arguments are accessibles as arguments of .Invoke method
GDMonoMethod *invoke = p_delegate->get_method("Invoke", -1);
GDMonoMethod *invoke = p_delegate->get_method(mono_get_delegate_invoke(p_delegate->get_mono_ptr()));

Vector<StringName> names;
Vector<ManagedType> types;
Expand Down
4 changes: 2 additions & 2 deletions modules/mono/mono_gd/gd_mono_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ bool GDMonoClass::has_public_parameterless_ctor() {
return ctor && ctor->get_visibility() == IMonoClassMember::PUBLIC;
}

GDMonoMethod *GDMonoClass::get_method(const StringName &p_name, int p_params_count) {
GDMonoMethod *GDMonoClass::get_method(const StringName &p_name, uint16_t p_params_count) {
MethodKey key = MethodKey(p_name, p_params_count);

GDMonoMethod **match = methods.getptr(key);
Expand Down Expand Up @@ -316,7 +316,7 @@ GDMonoMethod *GDMonoClass::get_method(MonoMethod *p_raw_method, const StringName
return get_method(p_raw_method, p_name, params_count);
}

GDMonoMethod *GDMonoClass::get_method(MonoMethod *p_raw_method, const StringName &p_name, int p_params_count) {
GDMonoMethod *GDMonoClass::get_method(MonoMethod *p_raw_method, const StringName &p_name, uint16_t p_params_count) {
ERR_FAIL_NULL_V(p_raw_method, NULL);

MethodKey key = MethodKey(p_name, p_params_count);
Expand Down
8 changes: 4 additions & 4 deletions modules/mono/mono_gd/gd_mono_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ class GDMonoClass {

MethodKey() {}

MethodKey(const StringName &p_name, int p_params_count) {
MethodKey(const StringName &p_name, uint16_t p_params_count) {
name = p_name;
params_count = p_params_count;
}

StringName name;
int params_count;
uint16_t params_count;
};

StringName namespace_name;
Expand Down Expand Up @@ -139,10 +139,10 @@ class GDMonoClass {
bool implements_interface(GDMonoClass *p_interface);
bool has_public_parameterless_ctor();

GDMonoMethod *get_method(const StringName &p_name, int p_params_count = 0);
GDMonoMethod *get_method(const StringName &p_name, uint16_t p_params_count = 0);
GDMonoMethod *get_method(MonoMethod *p_raw_method);
GDMonoMethod *get_method(MonoMethod *p_raw_method, const StringName &p_name);
GDMonoMethod *get_method(MonoMethod *p_raw_method, const StringName &p_name, int p_params_count);
GDMonoMethod *get_method(MonoMethod *p_raw_method, const StringName &p_name, uint16_t p_params_count);
GDMonoMethod *get_method_with_desc(const String &p_description, bool p_include_namespace);

GDMonoField *get_field(const StringName &p_name);
Expand Down
Loading

0 comments on commit b775573

Please sign in to comment.