tarantool / tarantool/tarantool
msgpackffi encode is x3 times slower than Lua C
Open
Nobody has claimed this yet.
bug
lua
performance
- Dominant language
- Lua
- Stars
- 3.7k
- Forks
- 419
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 88
Description
Here is the bench I used:
local clock = require('clock').monotonic64
local msgpackffi = require('msgpackffi')
local msgpack = require('msgpack')
local mp_encode_ffi = msgpackffi.encode
local mp_encode = msgpack.encode
local run_count = 100
local iter_count = 10000
local tuple_data = {1, 2, 3}
local jit_is_on = true
if not jit_is_on then
jit.off()
end
local function bench_mp_encode_ffi()
for i = 1, iter_count do
mp_encode_ffi(tuple_data)
end
end
local function bench_mp_encode()
for i = 1, iter_count do
mp_encode(tuple_data)
end
end
local times = {}
for i = 1, run_count do
collectgarbage('collect')
local t1 = clock()
------------------------- PUT THE BENCH CALLS HERE -------------------------
bench_mp_encode_ffi()
----------------------------------------------------------------------------
local t2 = clock()
local duration = t2 - t1
table.insert(times, duration)
end
table.sort(times)
print(string.format('Median value per iteration: %s ns',
tonumber(times[#times / 2]) / iter_count))
The ffi version works for ~950ns, the Lua C version works for ~280ns. It seems msgpackffi does not serve its purpose - be faster than Lua C because of not leaving Lua VM and better jitting. Either JIT does not work, or I have no idea what is the reason.
Both implementations use the global Lua ibuf (IBUF_SHARED in Lua, tarantool_lua_ibuf in C), and free it after each encode, but I tried to keep the memory reused, and it didn't change much. The reason is in something different.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.