diff --git a/godot-core/src/builtin/callable.rs b/godot-core/src/builtin/callable.rs index 272c79271..ca43f54e4 100644 --- a/godot-core/src/builtin/callable.rs +++ b/godot-core/src/builtin/callable.rs @@ -654,11 +654,14 @@ mod custom_callable { ) { let arg_refs: &[&Variant] = Variant::borrow_ref_slice(p_args, p_argument_count as usize); - let name = { + #[cfg(debug_assertions)] + let name = &{ let c: &C = CallableUserdata::inner_from_raw(callable_userdata); c.to_string() }; - let ctx = meta::CallContext::custom_callable(name.as_str()); + #[cfg(not(debug_assertions))] + let name = ""; + let ctx = meta::CallContext::custom_callable(name); crate::private::handle_varcall_panic(&ctx, &mut *r_error, move || { // Get the RustCallable again inside closure so it doesn't have to be UnwindSafe. @@ -681,11 +684,14 @@ mod custom_callable { { let arg_refs: &[&Variant] = Variant::borrow_ref_slice(p_args, p_argument_count as usize); - let name = { + #[cfg(debug_assertions)] + let name = &{ let w: &FnWrapper = CallableUserdata::inner_from_raw(callable_userdata); w.name.to_string() }; - let ctx = meta::CallContext::custom_callable(name.as_str()); + #[cfg(not(debug_assertions))] + let name = ""; + let ctx = meta::CallContext::custom_callable(name); crate::private::handle_varcall_panic(&ctx, &mut *r_error, move || { // Get the FnWrapper again inside closure so the FnMut doesn't have to be UnwindSafe. diff --git a/itest/rust/src/benchmarks/mod.rs b/itest/rust/src/benchmarks/mod.rs index 77312090b..6d41bec56 100644 --- a/itest/rust/src/benchmarks/mod.rs +++ b/itest/rust/src/benchmarks/mod.rs @@ -13,6 +13,7 @@ use godot::builtin::inner::InnerRect2i; use godot::builtin::{GString, PackedInt32Array, Rect2i, StringName, Vector2i}; use godot::classes::{Node3D, Os, RefCounted}; use godot::obj::{Gd, InstanceId, NewAlloc, NewGd, Singleton}; +use godot::prelude::{varray, Callable, RustCallable, Variant}; use godot::register::GodotClass; use crate::framework::bench; @@ -113,9 +114,36 @@ fn packed_array_from_iter_unknown_size() -> PackedInt32Array { })) } +#[bench(repeat = 25)] +fn call_callv_rust_fn() -> Variant { + let callable = Callable::from_fn("RustFunction", |_| ()); + callable.callv(&varray![]) +} + +#[bench(repeat = 25)] +fn call_callv_custom() -> Variant { + let callable = Callable::from_custom(MyRustCallable {}); + callable.callv(&varray![]) +} + // ---------------------------------------------------------------------------------------------------------------------------------------------- // Helpers for benchmarks above #[derive(GodotClass)] #[class(init)] struct MyBenchType {} + +#[derive(PartialEq, Hash)] +struct MyRustCallable {} + +impl RustCallable for MyRustCallable { + fn invoke(&mut self, _args: &[&Variant]) -> Variant { + Variant::nil() + } +} + +impl std::fmt::Display for MyRustCallable { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "MyRustCallable") + } +}