|
@@ -73,8 +73,8 @@ The FFI library is tightly integrated into LuaJIT (it's not available
|
|
as a separate module). The code generated by the JIT-compiler for
|
|
as a separate module). The code generated by the JIT-compiler for
|
|
accesses to C data structures from Lua code is on par with the
|
|
accesses to C data structures from Lua code is on par with the
|
|
code a C compiler would generate. Calls to C functions can
|
|
code a C compiler would generate. Calls to C functions can
|
|
-be inlined in the JIT-compiled code, unlike calls to functions bound
|
|
|
|
-via the classic Lua/C API.
|
|
|
|
|
|
+be inlined in JIT-compiled code, unlike calls to functions bound via
|
|
|
|
+the classic Lua/C API.
|
|
</p>
|
|
</p>
|
|
<p>
|
|
<p>
|
|
This page gives a short introduction to the usage of the FFI library.
|
|
This page gives a short introduction to the usage of the FFI library.
|
|
@@ -253,14 +253,17 @@ would consume 40 Megabytes in plain Lua (on x64).
|
|
Next, performance: the pure Lua version runs in 9.57 seconds (52.9
|
|
Next, performance: the pure Lua version runs in 9.57 seconds (52.9
|
|
seconds with the Lua interpreter) and the FFI version runs in 0.48
|
|
seconds with the Lua interpreter) and the FFI version runs in 0.48
|
|
seconds on my machine (YMMV). That's a factor of 20x faster (110x
|
|
seconds on my machine (YMMV). That's a factor of 20x faster (110x
|
|
-faster than with plain Lua).
|
|
|
|
|
|
+faster than the Lua interpreter).
|
|
</p>
|
|
</p>
|
|
<p style="font-size: 8pt;">
|
|
<p style="font-size: 8pt;">
|
|
The avid reader may notice that converting the pure Lua version over
|
|
The avid reader may notice that converting the pure Lua version over
|
|
to use array indexes for the colors (<tt>[1]</tt> instead of
|
|
to use array indexes for the colors (<tt>[1]</tt> instead of
|
|
<tt>.red</tt>, <tt>[2]</tt> instead of <tt>.green</tt> etc.) ought to
|
|
<tt>.red</tt>, <tt>[2]</tt> instead of <tt>.green</tt> etc.) ought to
|
|
be more compact and faster. This is certainly true (by a factor of
|
|
be more compact and faster. This is certainly true (by a factor of
|
|
-~1.7x), but the resulting code would be less idiomatic and rather
|
|
|
|
|
|
+~1.7x). Switching to a struct-of-arrays would help, too.
|
|
|
|
+</p>
|
|
|
|
+<p style="font-size: 8pt;">
|
|
|
|
+However the resulting code would be less idiomatic and rather
|
|
error-prone. And it still doesn't get even close to the performance of
|
|
error-prone. And it still doesn't get even close to the performance of
|
|
the FFI version of the code. Also, high-level data structures cannot
|
|
the FFI version of the code. Also, high-level data structures cannot
|
|
be easily passed to other C functions, especially I/O functions,
|
|
be easily passed to other C functions, especially I/O functions,
|