[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Overhead of luaJIT_setmode(L, -1, LUAJIT_MODE_WRAPCFUNC|LUAJIT_MODE_ON)
- From: Mike Pall <mikelu-1112@...>
- Date: Fri, 16 Dec 2011 15:57:37 +0100
Konstantin Osipov wrote:
> what is the overhead of luaJIT_setmode(LUAJIT_MODE_WRAPFUNC)?
>
> Can I call it on every invocation of a certain C function?
It's essentially a double-dispatch. But since the first dispatch
becomes predictable, the branch prediction cost just moves to the
second dispatch. So the overhead isn't that bad.
Note that you can only turn the wrapper function on or off
globally, not per C function.
> Since I need something more informative than "C++ exception",
> I decided the best solution is to re-implement 'pcall' built-in.
>
> One way to re-implement is to turn on WRAPFUNC every time
> pcall() is called. Is this a good solution?
That's not how it works and not something you should do. You turn
this option on _once_ and then leave it on.
If you use the wrapper function given in the docs, that's all you
need to do. No need to override pcall() etc.
> An alternative solution would look like:
It doesn't catch regular Lua errors -- I'm not sure you want that.
And this solution is only ok, if you call it rarely and then run
most of the time inside the called code (without errors).
--Mike