Re: FFI methods for userdata objects

  • From: Simon Cooke <sjcfwd@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Thu, 6 Sep 2012 13:48:15 -0400

On Thu, Sep 6, 2012 at 12:12 PM, Peter Colberg <peter@xxxxxxxxxxx> wrote:
> On Thu, Sep 06, 2012 at 11:54:15AM -0400, Simon Cooke wrote:
>>
>> This is strictly a quick fix to get significantly better indexing
>> performance from the Lua side while maintaining interoperability with
>> existing C++ data structures and calls to wrapped C++ extension
>> modules. For new developments I'm using FFI exclusively as you
>> suggest, but this application predates the release of the FFI library
>> and adapting to use it fully will require significantly more effort.
>
> Assuming you are using the std::vector in a loop, couldn't you
> retrieve the raw pointer just once, e.g., by calling a C method that
> returns &*myvec.begin(), and use that pointer to access the vector?

That could be useful to get a little extra performance for a few
specific loops, but as a general solution it would require
modifications to every loop in a fairly large Lua code base. Most of
my time-critical code is on the C++ side (actually it runs on the GPU)
and this fix already gives roughly 10-15x speedup for array access
from Lua code compared to using the Lua API (~60ns/access), without
any additional code changes. Your suggestion might give an extra
factor of 2-3x that could be worthwhile to consider on a case-by-case
basis, so I will keep it in mind.

Thanks,
Simon

Other related posts: