gdext
gdext copied to clipboard
[Performance Issue] Array methods duplicate Variant param or Callable take ownership when it could not.
From Performance Investigation
- Extra clones
Calling set and many other methods of
Array
withVariant
arguments clones theVariant
. Example:
let arr = Array::new();
arr.set(0, Variant::nil());
The set will call internally:
pub fn set(&mut self, index: usize, value: T) {
let ptr_mut = self.ptr_mut(index);
// SAFETY: `ptr_mut` just checked that the index is not out of bounds.
unsafe {
value.to_variant().move_into_var_ptr(ptr_mut);
}
}
which will do to_variant()
, even though the argument is already variant. There are multiple such cases throughout the Array
class.
- Ownership
Calling callv
:
pub fn callv(&self, arguments: VariantArray) -> Variant {
self.as_inner().callv(arguments)
}
Takes ownership of VariantArray. It might seem small thing, but for my use cases, i make about 10000 or more calls using callv. Allocating the array every time takes about 100-150ms of a 4s timeslice. I would like to be able to reuse the array. Eg. send it to the callv method, and after the method is called be able to reuse my array:
pub fn callv(&self, arguments: &VariantArray) -> Variant {
self.as_inner().callv(arguments)
}