[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: LuaJIT 2 - FFI struct copy performance issue
- From: Chris <coderight@...>
- Date: Tue, 29 Mar 2011 14:46:29 -0400
I'm getting a performance discrepancy issue when trying to copy FFI
structure values around. If I copy each member from a structure
separately the performance is about 4 or 5 times faster than just
assigning the structure all at once. I'm actually having this problem
as part of a larger application but I have stripped it down to the
following test case:
------------------------------------------------------
local ffi = require'ffi'
ffi.cdef[[
typedef struct {
uint64_t a;
uint64_t b;
uint64_t c;
double d;
double e;
double f;
} foo;
]]
local function copyfoo(a, b)
a.a = b.a
a.b = b.b
a.c = b.c
a.d = b.d
a.e = b.e
a.f = b.f
end
buffer = ffi.new("foo[?]", 1000001)
bar = ffi.new("foo")
for x=1, 40, 1 do
for y=1, 1000000, 1 do
buffer[y] = bar
--copyfoo(buffer[y], bar)
end
end
-----------------------------------------------
If I switch out that "buffer[y] = bar" assignment for the "copyfoo"
call then it runs considerably faster. It makes me wonder why the JIT
can't just do what it's doing in the copyfoo function.
Assignment:
$ time luajit ffitest.lua
real 0m2.965s
user 0m2.950s
sys 0m0.010s
Using copyfoo:
$ time luajit ffitest.lua
real 0m0.682s
user 0m0.670s
sys 0m0.010s
Did I mess something up or what's going on here?
Thanks!
CR