[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Execution of bytecodes
- From: Marc Balmer <marc@...>
- Date: Fri, 2 Oct 2015 15:33:11 +0200
> Am 02.10.2015 um 14:49 schrieb Roberto Ierusalimschy <email@example.com>:
>> A similar feature that has been asked before is to do that for
>> strings, for example to use read-only memory on low-RAM platforms. I
>> believe eLua has such a feature, and IIRC Roberto mentioned it (in a
>> recent workshop video) as a potential future feature for Lua. If that
>> ever makes it into Lua for strings, it would be nice to have the same
>> option for bytecode. But on the other hand, contrary to strings, the
>> runtime memory layout of the function prototypes may not be exactly
>> that of the serialized bytecode.
> We could reuse only the bytecode array (and lineinfo array, if present).
> This is usually the bulk in large functions. (Currently Lua copies
> everything into the interpreter. It never keeps pointers to outside
I am experimenting with different ways to execute Lua code. The current behavior of copying everything into the interpreter of course make sense, since normally you load the code from an external file using either open(), read(),
lua_loadXXX(), close() or, what we do most of time, mmap(), lua_loadXXX(), munmap(). So after munmap() the byte code is no longer available.
Now I wrote a script that will convert bytecode to a C character array and emit this with some glue code to a C compiler (clang in the case of the example). This means that the bytecode sits there, directly in the binary, as a static character array that will never go away and which never is freed. So in this case I am wasting memory, because I keep two copies of the bytecode in memory. So with this usage pattern (and whether it is a sane one is a different question) it would be desireable to not copy everything into the interpreter, but just use it.
I atteched the script, in case anyone is interested.
Description: Binary data