lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Petri Häkkinen wrote:
> Ok, here are the result from Alan Wake, averaged over time from multiple
> scenes:
> Vector creation ~100000
> Arith ~30000
> Normalization ~2500

Thank you for the numbers!

Assuming 3d vectors throughout this would give an allocation size
of 8+3*sizeof(double) = 32 bytes for the FFI cdata. Allocating
this with the current built-in allocator takes 1.3ms (@3GHz).
Collection and free would take a similar amount. With some
overhead this might add to around 3ms or 18% of the per-frame
budget. This is indeed quite high.

> Vectors are scattered all over the code base, so it's almost impossible to
> get good statistics on the data-flow. Probably most of the vecs are really
> short lived.

Ok, so let's pretend for a moment we could kill 90% of the
allocations with some code restructuring and some optimization
magic by the compiler (pure speculation of course). Then you're
down to 1.8% overhead per frame. That sounds acceptable. The new
GC in 2.1 would be much faster at alloc/GC/free, so it will be
even lower in the future.

> Value semantics ruled out for now, what is your recommendation for vector
> implementation with current version of LuaJIT? Userdata + C operations or
> Lua only implementation with tables? Obviously FFI in the future is the way
> to go, or is it? I would like to keep the functional syntax if at all
> possible.

For LuaJIT, using Lua tables (use array indexes [0], [1], [2]) is
definitely much faster than anything involving userdata and calls
to C code. The FFI will beat that by a substantial amount, though
(I have no exact numbers yet).