Closed
Description
At present, Value.Call
for any function with any return arguments is slow because it needs to:
- allocate a stack frame for the underlying return values
- allocate a
[]Value
for the return Values themselves
This is unfortunate since calling a function that returns any arguments is likely the common case. The aforementioned allocations cannot be eliminated because the current API Value.Call
pretty much requires that the implementation be responsible for allocating the return arguments.
I propose a new CallWith
(or any other suggested name) method with the modified signature:
func (v Value) CallWith(out, in []reflect.Value)
where:
- the
in
argument is identical to that forCall
- the
out
argument must be a slice wherelen(out) == v.NumOut()
.
With this API, I believe it is theoretically possible to have an allocation-free version of Value.Call
.
The description above only proposes CallWith
as an optimized version of Call
. You can imagine a CallSliceWith
as an optimized version of CallSlice
.