Closed modlfo closed 4 years ago
block.inputs[i][j] needs to be accessed with 0-based indices
Can't you just set float* array = &buffer[-1]
so that array[1]
refers to buffer[0]
?
Memory protection is lost
That's probably fine since we now have a warning message that scripts don't run in a safe sandbox.
@AndrewBelt I have implemented what you suggested and it works fine. The data inside the ProcessBlock can be accessed from the Lua side using 1-based indices. The existing examples work fine and my complex plugins run at a good speed.
Anything blocking this? A nice speedup would be helpful. Thanks.
Just reviewed, looks great! I like your use of LuaProcessBlock. One-indexed and as fast as any FFI access can be. Cleaned up the code a bit after rebasing.
I found that most of the overhead in LuaJIT is caused when accessing the
block
information. I have a complex piece of Lua code (generated with Vult) that runs at ~25% (using the CPU meter in Rack) and goes down to ~5% when using the FFI. Other complex modules that I have tested have a similar performance.This has some big disadvantages:
block.inputs[i][j]
needs to be accessed with 0-based indices, while all Lua code uses 1-based indices. This can be very confusing.block.outputs[100][100]
could segfault the application.That said. This is how it works. I'm loading the FFI library in Lua and I'm creating the following piece of code:
Check commit bdd1ff7 "Example on how to use the FFI in LuaJIT to increase the performance".
The first part describes the
ProcessBlock
structure that way LuaJIT knows how to access it. The function is used to covert the C++ProcessBlock
pointer to a LuaJIT cdata.Since my objective is to run Vult code translated to Lua I could work instead on adding support for Vult language. In that case I would use different API. Rather than having access to the arrays I would use functions. For example: