lua-users home
lua-l archive

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


Hi there,

We've recently been tinkering with Lua core to add support for a new primitive vector data type similar to float4 datatype in shading languages like HLSL and GLSL. The result is lua-vec, or Lua 5.1.4 with vectors. The motivation was to create an efficient vector implementation for 3d applications such as games, 3d visualizations and prototypes of various rendering algorithms. After trying out different less intrusive options like vectors implemented in standard Lua, userdata vectors written in C and even hacked non-persistent light userdata vectors, it soon became apparent that none of the existing approaches work well for vector heavy applications. The main source of inefficiency was determined to be garbage collection of temporary vectors created by arithmetic operations. Thus the idea of a more intrusive approach was born: could we hack the very core of Lua to add support for vectors? Well, the answer is yes.

For a longer answer please visit the homepage of our highly experimental project at:

http://code.google.com/p/lua-vec/

So far the results are promising: speed up by a factor of 4.5 in a vector heavy benchmark (a global illumination renderer). Interestingly, lua-vec's speed in this benchmark is quite close to LuaJIT. However, we're still far from the speed of a full C++ implementation. The question is how much faster could LuaJIT be if it was augmented with native vectors? We're currently wondering how much work it would be to similarly hack vectors into LuaJIT.....

Here are the bechmark results (more detail in project wiki, values are rendering times in seconds):

1217s std lua      
 770s userdata vectors
 274s lua-vec (our implementation)
 234s luajit
  ??s luajit & lua-vec
  10s cpp

Comments, bug reports and criticism of our unorthodox way are always welcome!

On behalf of lua-vec team,

Petri Häkkinen

p.s. the other team member is my brother Henri Häkkinen.