DelSkayn / rquickjs

High level bindings to the quickjs javascript engine
MIT License
434 stars 59 forks source link

Efficient use of `Args` with variable number of arguments #238

Open markschl opened 7 months ago

markschl commented 7 months ago

While trying to repeadedly call a function with arguments of (initially) unknown number, I noticed that I had to re-construct the Args before every Function::call_arg or Args::apply (in v0.4 beta). This seems quite inefficient, since Args::new_unsized() allocates a vector, and the Args is then consumed during the function call.

Is there any other efficient way that I missed? Is there a specific reason that IntoArgs cannot be implemented for &[Value], such that e.g. an instance of Vec<Value> or even Persistent<Vec<Value>> could be kept around and reused?

DelSkayn commented 7 months ago

I will look making this part of the library more efficient. There are definitely some improvements that can be made on this front!

Minor note though, Args::new_usized() doesn't allocate, it does create a vector but rust vectors don't allocate until they are required to.

markschl commented 7 months ago

Many thanks, and you are right, I was not being precise about empty vectors.