Hello!
On Tue, Oct 14, 2014 at 12:19 AM, Michal Cichra wrote:
> So you are saying, that callback driven C libraries like expat and yajl are
> not compatible with OpenResty/LuaJIT ?
C callbacks are problematic and suboptimal at least for the LuaJIT VM.
It means calling into Lua VM from external C code. We should stay away
from them whenever possible.
Try always calling into C from within Lua (via FFI) instead of the
other way around. Calling the Lua code (and the LuaJIT VM) from within
external C can never be JIT compiled because of the unavoidable VM
side-effects (as opposed to FFI's side-effect-free approach for JITted
Lua code).
This is not specific to OpenResty but also applies to any LuaJIT apps
in general.
We could. Though it's more related to LuaJIT in general. Patches welcome :)
> And is there some plan to overcome this limitation?
>
This limitation is in LuaJIT 2, not in OpenResty :) And for
performance reasons, it may not really worth it because even if we
implement "C coroutines" in LuaJIT (as in coco [1]), it is really slow
as compared to the FFI approach (both piratically and theoretically).
You can check out LuaJIT's author and Coco's author, Mike Pall's reply
below on this topic:
http://comments.gmane.org/gmane.comp.lang.lua.luajit/1774
> So to implement streaming XML/JSON parser, we have to write one in pure Lua,
> right? Do you know about some projects doing this?
>
No really. The C library just needs to expose an iterator-style API
(or "pull style") as in libc's epoll/poll/select. (And we're talking
about C libraries doing streaming parsing here rather than nonblocking
I/O though).
For example, my sregex library [2] exposes a "pull style" C API for
streaming regex matching (and substitution) which is friendly to
LuaJIT both in functionality and performance (via FFI). This is also
suggested by Mike Pall in the thread mentioned above.
Regards,
-agentzh
[1]
http://coco.luajit.org/
[2]
https://github.com/openresty/sregex