New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Returning multiple values #186
Comments
Yes, and it is documented. We can't support universal multireturn since it would hit performance to create lots of temporary tables inside the router. |
Are this expenses comparable with computations required for performing request? Benchmark shows that the difference between wrapping/unwrapping result with table and returning result as is is less then 1ns. This is not significant comparing to net request timing. |
Less than 1 ns? Please, share with me these benches. 1ns is ~3 processor ticks. It is impossible to pack and unpack a Lua table so fast. |
In addition, the second return value is reserved for error messages. So whenever the user needs to do multireturn, they should do it through creating a table and returning it as first value. |
local clock = require('clock')
local function source(x)
return x + 1, x + 2
end
local function with_wrap(x)
local result = {source(x)}
return unpack(result)
end
local function without_wrap(x)
local result = source(x)
return result
end
local function measure(n, fn)
local start = clock.time()
for i = 1, n, 1 do
fn(i)
end
print(clock.time() - start)
end
local n = 1000000
measure(n, with_wrap)
measure(n, without_wrap) I get
Sorry, I had mistake - it's 69ns per call. |
Ok. Firstly, in But try to add one more integer - it works twice slower. Add fourth integer - it works x100 times slower (microseconds). local function source(x)
return x + 1, x + 2, x + 3, x + 4
end 28.444905042648 - wrap |
There is a couple of options how to handle multireturn without table packing.
function remote_methods:call(func_name, args, opts)
check_remote_arg(self, 'call')
check_call_args(args)
args = args or {}
local res = self:_request('call_17', opts, nil, tostring(func_name), args)
if type(res) ~= 'table' or opts and opts.is_async then
return res
end
return unpack(res)
end
|
Another idea - use netbox |
vshard's
call
does not return all values from called procedure:The text was updated successfully, but these errors were encountered: