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 committed Dec 6, 2020
1 parent 04bef80 commit a946f84
Show file tree
Hide file tree
Showing 11 changed files with 732 additions and 658 deletions.
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 @@ -290,7 +290,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 @@ -330,7 +330,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, nullptr);

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

MethodKey() {}

MethodKey(const StringName &p_name, int p_params_count) {
name = p_name;
params_count = 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 = 0;
};

StringName namespace_name;
Expand Down Expand Up @@ -139,10 +138,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 a946f84

Please sign in to comment.