Skip to content

[Performance Issue] Array methods duplicate Variant param or Callable take ownership when it could not. #790

Closed
@Ughuuu

Description

@Ughuuu

From Performance Investigation

  1. Extra clones
    Calling set and many other methods of Array with Variant arguments clones the Variant.
    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.

  1. 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)
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    performancePerformance problems and optimizations

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions